]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/mitele.py
debian/control: Add recommends on aria2 | wget | curl to use external downloaders.
[youtubedl] / youtube_dl / extractor / mitele.py
1 from __future__ import unicode_literals
2
3 import json
4
5 from .common import InfoExtractor
6 from ..compat import (
7 compat_urllib_parse,
8 compat_urlparse,
9 )
10 from ..utils import (
11 get_element_by_attribute,
12 parse_duration,
13 strip_jsonp,
14 )
15
16
17 class MiTeleIE(InfoExtractor):
18 IE_NAME = 'mitele.es'
19 _VALID_URL = r'http://www\.mitele\.es/[^/]+/[^/]+/[^/]+/(?P<id>[^/]+)/'
20
21 _TEST = {
22 'url': 'http://www.mitele.es/programas-tv/diario-de/la-redaccion/programa-144/',
23 'md5': '6a75fe9d0d3275bead0cb683c616fddb',
24 'info_dict': {
25 'id': '0fce117d',
26 'ext': 'mp4',
27 'title': 'Programa 144 - Tor, la web invisible',
28 'description': 'md5:3b6fce7eaa41b2d97358726378d9369f',
29 'display_id': 'programa-144',
30 'duration': 2913,
31 },
32 }
33
34 def _real_extract(self, url):
35 episode = self._match_id(url)
36 webpage = self._download_webpage(url, episode)
37 embed_data_json = self._search_regex(
38 r'(?s)MSV\.embedData\[.*?\]\s*=\s*({.*?});', webpage, 'embed data',
39 ).replace('\'', '"')
40 embed_data = json.loads(embed_data_json)
41
42 domain = embed_data['mediaUrl']
43 if not domain.startswith('http'):
44 # only happens in telecinco.es videos
45 domain = 'http://' + domain
46 info_url = compat_urlparse.urljoin(
47 domain,
48 compat_urllib_parse.unquote(embed_data['flashvars']['host'])
49 )
50 info_el = self._download_xml(info_url, episode).find('./video/info')
51
52 video_link = info_el.find('videoUrl/link').text
53 token_query = compat_urllib_parse.urlencode({'id': video_link})
54 token_info = self._download_json(
55 embed_data['flashvars']['ov_tk'] + '?' + token_query,
56 episode,
57 transform_source=strip_jsonp
58 )
59
60 return {
61 'id': embed_data['videoId'],
62 'display_id': episode,
63 'title': info_el.find('title').text,
64 'url': token_info['tokenizedUrl'],
65 'description': get_element_by_attribute('class', 'text', webpage),
66 'thumbnail': info_el.find('thumb').text,
67 'duration': parse_duration(info_el.find('duration').text),
68 }