]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/mitele.py
debian/control: Prefer mplayer to mplayer2 in Recommends.
[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_urllib_parse_unquote,
9 compat_urlparse,
10 )
11 from ..utils import (
12 get_element_by_attribute,
13 parse_duration,
14 strip_jsonp,
15 )
16
17
18 class MiTeleIE(InfoExtractor):
19 IE_NAME = 'mitele.es'
20 _VALID_URL = r'http://www\.mitele\.es/[^/]+/[^/]+/[^/]+/(?P<id>[^/]+)/'
21
22 _TESTS = [{
23 'url': 'http://www.mitele.es/programas-tv/diario-de/la-redaccion/programa-144/',
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 'params': {
33 # m3u8 download
34 'skip_download': True,
35 },
36 }]
37
38 def _real_extract(self, url):
39 episode = self._match_id(url)
40 webpage = self._download_webpage(url, episode)
41 embed_data_json = self._search_regex(
42 r'(?s)MSV\.embedData\[.*?\]\s*=\s*({.*?});', webpage, 'embed data',
43 ).replace('\'', '"')
44 embed_data = json.loads(embed_data_json)
45
46 domain = embed_data['mediaUrl']
47 if not domain.startswith('http'):
48 # only happens in telecinco.es videos
49 domain = 'http://' + domain
50 info_url = compat_urlparse.urljoin(
51 domain,
52 compat_urllib_parse_unquote(embed_data['flashvars']['host'])
53 )
54 info_el = self._download_xml(info_url, episode).find('./video/info')
55
56 video_link = info_el.find('videoUrl/link').text
57 token_query = compat_urllib_parse.urlencode({'id': video_link})
58 token_info = self._download_json(
59 embed_data['flashvars']['ov_tk'] + '?' + token_query,
60 episode,
61 transform_source=strip_jsonp
62 )
63 formats = self._extract_m3u8_formats(
64 token_info['tokenizedUrl'], episode, ext='mp4')
65
66 return {
67 'id': embed_data['videoId'],
68 'display_id': episode,
69 'title': info_el.find('title').text,
70 'formats': formats,
71 'description': get_element_by_attribute('class', 'text', webpage),
72 'thumbnail': info_el.find('thumb').text,
73 'duration': parse_duration(info_el.find('duration').text),
74 }