]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/mitele.py
Prepare to upload.
[youtubedl] / youtube_dl / extractor / mitele.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..compat import (
5 compat_urllib_parse,
6 compat_urlparse,
7 )
8 from ..utils import (
9 encode_dict,
10 get_element_by_attribute,
11 int_or_none,
12 )
13
14
15 class MiTeleIE(InfoExtractor):
16 IE_DESC = 'mitele.es'
17 _VALID_URL = r'http://www\.mitele\.es/[^/]+/[^/]+/[^/]+/(?P<id>[^/]+)/'
18
19 _TESTS = [{
20 'url': 'http://www.mitele.es/programas-tv/diario-de/la-redaccion/programa-144/',
21 'md5': '0ff1a13aebb35d9bc14081ff633dd324',
22 'info_dict': {
23 'id': '0NF1jJnxS1Wu3pHrmvFyw2',
24 'display_id': 'programa-144',
25 'ext': 'flv',
26 'title': 'Tor, la web invisible',
27 'description': 'md5:3b6fce7eaa41b2d97358726378d9369f',
28 'thumbnail': 're:(?i)^https?://.*\.jpg$',
29 'duration': 2913,
30 },
31 }]
32
33 def _real_extract(self, url):
34 display_id = self._match_id(url)
35
36 webpage = self._download_webpage(url, display_id)
37
38 config_url = self._search_regex(
39 r'data-config\s*=\s*"([^"]+)"', webpage, 'data config url')
40 config_url = compat_urlparse.urljoin(url, config_url)
41
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(
63 '%s/?%s' % (gat, compat_urllib_parse.urlencode(encode_dict(token_data))),
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'))
80
81 return {
82 'id': video_id,
83 'display_id': display_id,
84 'title': title,
85 'description': get_element_by_attribute('class', 'text', webpage),
86 'thumbnail': thumbnail,
87 'duration': duration,
88 'formats': formats,
89 }