]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/mitele.py
Add support for https for all extractors as preventive and future-proof measure
[yt-dlp.git] / youtube_dl / extractor / mitele.py
CommitLineData
938dd254
JMF
1from __future__ import unicode_literals
2
938dd254 3from .common import InfoExtractor
eb97f46e
JMF
4from ..compat import (
5 compat_urllib_parse,
6 compat_urlparse,
7)
1cc79574 8from ..utils import (
f84ce1eb 9 encode_dict,
938dd254 10 get_element_by_attribute,
f84ce1eb 11 int_or_none,
938dd254
JMF
12)
13
14
15class MiTeleIE(InfoExtractor):
3368d70d 16 IE_DESC = 'mitele.es'
5886b38d 17 _VALID_URL = r'https?://www\.mitele\.es/[^/]+/[^/]+/[^/]+/(?P<id>[^/]+)/'
938dd254 18
c10ea454 19 _TESTS = [{
938dd254 20 'url': 'http://www.mitele.es/programas-tv/diario-de/la-redaccion/programa-144/',
eb97f46e 21 'md5': '0ff1a13aebb35d9bc14081ff633dd324',
938dd254 22 'info_dict': {
f84ce1eb 23 'id': '0NF1jJnxS1Wu3pHrmvFyw2',
938dd254 24 'display_id': 'programa-144',
f84ce1eb
S
25 'ext': 'flv',
26 'title': 'Tor, la web invisible',
27 'description': 'md5:3b6fce7eaa41b2d97358726378d9369f',
28 'thumbnail': 're:(?i)^https?://.*\.jpg$',
938dd254
JMF
29 'duration': 2913,
30 },
c10ea454 31 }]
938dd254
JMF
32
33 def _real_extract(self, url):
f84ce1eb
S
34 display_id = self._match_id(url)
35
36 webpage = self._download_webpage(url, display_id)
938dd254 37
f84ce1eb
S
38 config_url = self._search_regex(
39 r'data-config\s*=\s*"([^"]+)"', webpage, 'data config url')
eb97f46e 40 config_url = compat_urlparse.urljoin(url, config_url)
938dd254 41
f84ce1eb
S
42 config = self._download_json(
43 config_url, display_id, 'Downloading config JSON')
44
45 mmc = self._download_json(
46 config['services']['mmc'], display_id, 'Downloading mmc JSON')
47
48 formats = []
49 for location in mmc['locations']:
50 gat = self._proto_relative_url(location.get('gat'), 'http:')
51 bas = location.get('bas')
52 loc = location.get('loc')
53 ogn = location.get('ogn')
54 if None in (gat, bas, loc, ogn):
55 continue
56 token_data = {
57 'bas': bas,
58 'icd': loc,
59 'ogn': ogn,
60 'sta': '0',
61 }
62 media = self._download_json(
c9315385 63 '%s/?%s' % (gat, compat_urllib_parse.urlencode(encode_dict(token_data))),
f84ce1eb
S
64 display_id, 'Downloading %s JSON' % location['loc'])
65 file_ = media.get('file')
66 if not file_:
67 continue
68 formats.extend(self._extract_f4m_formats(
69 file_ + '&hdcore=3.2.0&plugin=aasp-3.2.0.77.18',
70 display_id, f4m_id=loc))
71
72 title = self._search_regex(
73 r'class="Destacado-text"[^>]*>\s*<strong>([^<]+)</strong>', webpage, 'title')
74
75 video_id = self._search_regex(
76 r'data-media-id\s*=\s*"([^"]+)"', webpage,
77 'data media id', default=None) or display_id
78 thumbnail = config.get('poster', {}).get('imageUrl')
79 duration = int_or_none(mmc.get('duration'))
938dd254
JMF
80
81 return {
f84ce1eb
S
82 'id': video_id,
83 'display_id': display_id,
84 'title': title,
938dd254 85 'description': get_element_by_attribute('class', 'text', webpage),
f84ce1eb
S
86 'thumbnail': thumbnail,
87 'duration': duration,
88 'formats': formats,
938dd254 89 }