]>
Commit | Line | Data |
---|---|---|
5f6a1245 | 1 | # coding: utf-8 |
ad5f53ac JMF |
2 | from __future__ import unicode_literals |
3 | ||
12bc2429 | 4 | import json |
ad5f53ac | 5 | |
12bc2429 S |
6 | from .common import InfoExtractor |
7 | from ..compat import ( | |
12bc2429 | 8 | compat_urllib_parse_unquote, |
15707c7e | 9 | compat_urllib_parse_urlencode, |
12bc2429 S |
10 | compat_urlparse, |
11 | ) | |
12 | from ..utils import ( | |
13 | get_element_by_attribute, | |
14 | parse_duration, | |
15 | strip_jsonp, | |
16 | ) | |
ad5f53ac | 17 | |
12bc2429 S |
18 | |
19 | class TelecincoIE(InfoExtractor): | |
4647fd89 | 20 | IE_DESC = 'telecinco.es, cuatro.com and mediaset.es' |
d492dad8 | 21 | _VALID_URL = r'https?://www\.(?:telecinco\.es|cuatro\.com|mediaset\.es)/(?:[^/]+/)+(?P<id>.+?)\.html' |
ad5f53ac | 22 | |
c10ea454 | 23 | _TESTS = [{ |
ad5f53ac | 24 | 'url': 'http://www.telecinco.es/robinfood/temporada-01/t01xp14/Bacalao-cocochas-pil-pil_0_1876350223.html', |
369e6016 | 25 | 'md5': '5cbef3ad5ef17bf0d21570332d140729', |
ad5f53ac JMF |
26 | 'info_dict': { |
27 | 'id': 'MDSVID20141015_0058', | |
28 | 'ext': 'mp4', | |
29 | 'title': 'Con Martín Berasategui, hacer un bacalao al ...', | |
30 | 'duration': 662, | |
31 | }, | |
d5e7657f S |
32 | }, { |
33 | 'url': 'http://www.cuatro.com/deportes/futbol/barcelona/Leo_Messi-Champions-Roma_2_2052780128.html', | |
34 | 'md5': '0a5b9f3cc8b074f50a0578f823a12694', | |
35 | 'info_dict': { | |
36 | 'id': 'MDSVID20150916_0128', | |
37 | 'ext': 'mp4', | |
38 | 'title': '¿Quién es este ex futbolista con el que hablan ...', | |
39 | 'duration': 79, | |
40 | }, | |
d492dad8 S |
41 | }, { |
42 | 'url': 'http://www.mediaset.es/12meses/campanas/doylacara/conlatratanohaytrato/Ayudame-dar-cara-trata-trato_2_1986630220.html', | |
43 | 'md5': 'ad1bfaaba922dd4a295724b05b68f86a', | |
44 | 'info_dict': { | |
45 | 'id': 'MDSVID20150513_0220', | |
46 | 'ext': 'mp4', | |
47 | 'title': '#DOYLACARA. Con la trata no hay trato', | |
48 | 'duration': 50, | |
49 | }, | |
c10ea454 JMF |
50 | }, { |
51 | 'url': 'http://www.telecinco.es/informativos/nacional/Pablo_Iglesias-Informativos_Telecinco-entrevista-Pedro_Piqueras_2_1945155182.html', | |
52 | 'only_matching': True, | |
34a4cd0a S |
53 | }, { |
54 | 'url': 'http://www.telecinco.es/espanasinirmaslejos/Espana-gran-destino-turistico_2_1240605043.html', | |
55 | 'only_matching': True, | |
c10ea454 | 56 | }] |
12bc2429 S |
57 | |
58 | def _real_extract(self, url): | |
59 | episode = self._match_id(url) | |
60 | webpage = self._download_webpage(url, episode) | |
61 | embed_data_json = self._search_regex( | |
62 | r'(?s)MSV\.embedData\[.*?\]\s*=\s*({.*?});', webpage, 'embed data', | |
63 | ).replace('\'', '"') | |
64 | embed_data = json.loads(embed_data_json) | |
65 | ||
66 | domain = embed_data['mediaUrl'] | |
67 | if not domain.startswith('http'): | |
68 | # only happens in telecinco.es videos | |
69 | domain = 'http://' + domain | |
70 | info_url = compat_urlparse.urljoin( | |
71 | domain, | |
72 | compat_urllib_parse_unquote(embed_data['flashvars']['host']) | |
73 | ) | |
74 | info_el = self._download_xml(info_url, episode).find('./video/info') | |
75 | ||
76 | video_link = info_el.find('videoUrl/link').text | |
15707c7e | 77 | token_query = compat_urllib_parse_urlencode({'id': video_link}) |
12bc2429 S |
78 | token_info = self._download_json( |
79 | embed_data['flashvars']['ov_tk'] + '?' + token_query, | |
80 | episode, | |
81 | transform_source=strip_jsonp | |
82 | ) | |
83 | formats = self._extract_m3u8_formats( | |
d5e7657f | 84 | token_info['tokenizedUrl'], episode, ext='mp4', entry_protocol='m3u8_native') |
19dbaeec | 85 | self._sort_formats(formats) |
12bc2429 S |
86 | |
87 | return { | |
88 | 'id': embed_data['videoId'], | |
89 | 'display_id': episode, | |
90 | 'title': info_el.find('title').text, | |
91 | 'formats': formats, | |
92 | 'description': get_element_by_attribute('class', 'text', webpage), | |
93 | 'thumbnail': info_el.find('thumb').text, | |
94 | 'duration': parse_duration(info_el.find('duration').text), | |
95 | } |