]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/mitele.py
[dailymotion] Error spelling
[youtube-dl] / youtube_dl / extractor / mitele.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..compat import compat_urllib_parse
5 from ..utils import (
6     encode_dict,
7     get_element_by_attribute,
8     int_or_none,
9 )
10
11
12 class MiTeleIE(InfoExtractor):
13     IE_DESC = 'mitele.es'
14     _VALID_URL = r'http://www\.mitele\.es/[^/]+/[^/]+/[^/]+/(?P<id>[^/]+)/'
15
16     _TESTS = [{
17         'url': 'http://www.mitele.es/programas-tv/diario-de/la-redaccion/programa-144/',
18         'md5': 'ace7635b2a0b286aaa37d3ff192d2a8a',
19         'info_dict': {
20             'id': '0NF1jJnxS1Wu3pHrmvFyw2',
21             'display_id': 'programa-144',
22             'ext': 'flv',
23             'title': 'Tor, la web invisible',
24             'description': 'md5:3b6fce7eaa41b2d97358726378d9369f',
25             'thumbnail': 're:(?i)^https?://.*\.jpg$',
26             'duration': 2913,
27         },
28     }]
29
30     def _real_extract(self, url):
31         display_id = self._match_id(url)
32
33         webpage = self._download_webpage(url, display_id)
34
35         config_url = self._search_regex(
36             r'data-config\s*=\s*"([^"]+)"', webpage, 'data config url')
37
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'))
76
77         return {
78             'id': video_id,
79             'display_id': display_id,
80             'title': title,
81             'description': get_element_by_attribute('class', 'text', webpage),
82             'thumbnail': thumbnail,
83             'duration': duration,
84             'formats': formats,
85         }