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