]>
Commit | Line | Data |
---|---|---|
5f6a1245 | 1 | # coding: utf-8 |
ad5f53ac JMF |
2 | from __future__ import unicode_literals |
3 | ||
a098c99f RA |
4 | import json |
5 | import re | |
ad5f53ac | 6 | |
a098c99f RA |
7 | from .common import InfoExtractor |
8 | from .ooyala import OoyalaIE | |
9 | from ..utils import ( | |
10 | clean_html, | |
11 | determine_ext, | |
12 | int_or_none, | |
13 | str_or_none, | |
6d475d01 | 14 | try_get, |
a098c99f RA |
15 | urljoin, |
16 | ) | |
ad5f53ac | 17 | |
a098c99f RA |
18 | |
19 | class TelecincoIE(InfoExtractor): | |
4647fd89 | 20 | IE_DESC = 'telecinco.es, cuatro.com and mediaset.es' |
92519402 | 21 | _VALID_URL = r'https?://(?:www\.)?(?:telecinco\.es|cuatro\.com|mediaset\.es)/(?:[^/]+/)+(?P<id>.+?)\.html' |
ad5f53ac | 22 | |
c10ea454 | 23 | _TESTS = [{ |
ad5f53ac JMF |
24 | 'url': 'http://www.telecinco.es/robinfood/temporada-01/t01xp14/Bacalao-cocochas-pil-pil_0_1876350223.html', |
25 | 'info_dict': { | |
a098c99f | 26 | 'id': '1876350223', |
47335a0e | 27 | 'title': 'Bacalao con kokotxas al pil-pil', |
6d475d01 | 28 | 'description': 'md5:716caf5601e25c3c5ab6605b1ae71529', |
ad5f53ac | 29 | }, |
a098c99f RA |
30 | 'playlist': [{ |
31 | 'md5': 'adb28c37238b675dad0f042292f209a7', | |
32 | 'info_dict': { | |
33 | 'id': 'JEA5ijCnF6p5W08A1rNKn7', | |
34 | 'ext': 'mp4', | |
35 | 'title': 'Con Martín Berasategui, hacer un bacalao al pil-pil es fácil y divertido', | |
36 | 'duration': 662, | |
37 | }, | |
38 | }] | |
d5e7657f S |
39 | }, { |
40 | 'url': 'http://www.cuatro.com/deportes/futbol/barcelona/Leo_Messi-Champions-Roma_2_2052780128.html', | |
a098c99f | 41 | 'md5': '9468140ebc300fbb8b9d65dc6e5c4b43', |
d5e7657f | 42 | 'info_dict': { |
47335a0e | 43 | 'id': 'jn24Od1zGLG4XUZcnUnZB6', |
d5e7657f | 44 | 'ext': 'mp4', |
47335a0e RA |
45 | 'title': '¿Quién es este ex futbolista con el que hablan Leo Messi y Luis Suárez?', |
46 | 'description': 'md5:a62ecb5f1934fc787107d7b9a2262805', | |
d5e7657f S |
47 | 'duration': 79, |
48 | }, | |
d492dad8 S |
49 | }, { |
50 | 'url': 'http://www.mediaset.es/12meses/campanas/doylacara/conlatratanohaytrato/Ayudame-dar-cara-trata-trato_2_1986630220.html', | |
a098c99f | 51 | 'md5': 'ae2dc6b7b50b2392076a51c0f70e01f6', |
d492dad8 | 52 | 'info_dict': { |
47335a0e | 53 | 'id': 'aywerkD2Sv1vGNqq9b85Q2', |
d492dad8 S |
54 | 'ext': 'mp4', |
55 | 'title': '#DOYLACARA. Con la trata no hay trato', | |
47335a0e | 56 | 'description': 'md5:2771356ff7bfad9179c5f5cd954f1477', |
d492dad8 S |
57 | 'duration': 50, |
58 | }, | |
6d475d01 S |
59 | }, { |
60 | # video in opening's content | |
61 | 'url': 'https://www.telecinco.es/vivalavida/fiorella-sobrina-edmundo-arrocet-entrevista_18_2907195140.html', | |
62 | 'info_dict': { | |
63 | 'id': '2907195140', | |
64 | 'title': 'La surrealista entrevista a la sobrina de Edmundo Arrocet: "No puedes venir aquí y tomarnos por tontos"', | |
65 | 'description': 'md5:73f340a7320143d37ab895375b2bf13a', | |
66 | }, | |
67 | 'playlist': [{ | |
68 | 'md5': 'adb28c37238b675dad0f042292f209a7', | |
69 | 'info_dict': { | |
70 | 'id': 'TpI2EttSDAReWpJ1o0NVh2', | |
71 | 'ext': 'mp4', | |
72 | 'title': 'La surrealista entrevista a la sobrina de Edmundo Arrocet: "No puedes venir aquí y tomarnos por tontos"', | |
73 | 'duration': 1015, | |
74 | }, | |
75 | }], | |
76 | 'params': { | |
77 | 'skip_download': True, | |
78 | }, | |
c10ea454 JMF |
79 | }, { |
80 | 'url': 'http://www.telecinco.es/informativos/nacional/Pablo_Iglesias-Informativos_Telecinco-entrevista-Pedro_Piqueras_2_1945155182.html', | |
81 | 'only_matching': True, | |
34a4cd0a S |
82 | }, { |
83 | 'url': 'http://www.telecinco.es/espanasinirmaslejos/Espana-gran-destino-turistico_2_1240605043.html', | |
84 | 'only_matching': True, | |
9d089630 S |
85 | }, { |
86 | # ooyala video | |
87 | 'url': 'http://www.cuatro.com/chesterinlove/a-carta/chester-chester_in_love-chester_edu_2_2331030022.html', | |
88 | 'only_matching': True, | |
c10ea454 | 89 | }] |
12bc2429 | 90 | |
a098c99f RA |
91 | def _parse_content(self, content, url): |
92 | video_id = content['dataMediaId'] | |
93 | if content.get('dataCmsId') == 'ooyala': | |
94 | return self.url_result( | |
95 | 'ooyala:%s' % video_id, OoyalaIE.ie_key(), video_id) | |
96 | config_url = urljoin(url, content['dataConfig']) | |
97 | config = self._download_json( | |
98 | config_url, video_id, 'Downloading config JSON') | |
99 | title = config['info']['title'] | |
100 | ||
101 | def mmc_url(mmc_type): | |
102 | return re.sub( | |
103 | r'/(?:flash|html5)\.json', '/%s.json' % mmc_type, | |
104 | config['services']['mmc']) | |
105 | ||
106 | duration = None | |
107 | formats = [] | |
108 | for mmc_type in ('flash', 'html5'): | |
109 | mmc = self._download_json( | |
110 | mmc_url(mmc_type), video_id, | |
111 | 'Downloading %s mmc JSON' % mmc_type, fatal=False) | |
112 | if not mmc: | |
113 | continue | |
114 | if not duration: | |
115 | duration = int_or_none(mmc.get('duration')) | |
116 | for location in mmc['locations']: | |
117 | gat = self._proto_relative_url(location.get('gat'), 'http:') | |
118 | gcp = location.get('gcp') | |
119 | ogn = location.get('ogn') | |
120 | if None in (gat, gcp, ogn): | |
121 | continue | |
122 | token_data = { | |
123 | 'gcp': gcp, | |
124 | 'ogn': ogn, | |
125 | 'sta': 0, | |
126 | } | |
127 | media = self._download_json( | |
128 | gat, video_id, data=json.dumps(token_data).encode('utf-8'), | |
129 | headers={ | |
130 | 'Content-Type': 'application/json;charset=utf-8', | |
131 | 'Referer': url, | |
132 | }, fatal=False) or {} | |
133 | stream = media.get('stream') or media.get('file') | |
134 | if not stream: | |
135 | continue | |
136 | ext = determine_ext(stream) | |
137 | if ext == 'f4m': | |
138 | formats.extend(self._extract_f4m_formats( | |
139 | stream + '&hdcore=3.2.0&plugin=aasp-3.2.0.77.18', | |
140 | video_id, f4m_id='hds', fatal=False)) | |
141 | elif ext == 'm3u8': | |
142 | formats.extend(self._extract_m3u8_formats( | |
143 | stream, video_id, 'mp4', 'm3u8_native', | |
144 | m3u8_id='hls', fatal=False)) | |
145 | self._sort_formats(formats) | |
146 | ||
147 | return { | |
148 | 'id': video_id, | |
149 | 'title': title, | |
150 | 'formats': formats, | |
151 | 'thumbnail': content.get('dataPoster') or config.get('poster', {}).get('imageUrl'), | |
152 | 'duration': duration, | |
153 | } | |
154 | ||
12bc2429 | 155 | def _real_extract(self, url): |
47335a0e RA |
156 | display_id = self._match_id(url) |
157 | webpage = self._download_webpage(url, display_id) | |
a098c99f | 158 | article = self._parse_json(self._search_regex( |
f8cbd8c9 | 159 | r'window\.\$REACTBASE_STATE\.article(?:_multisite)?\s*=\s*({.+})', |
a098c99f RA |
160 | webpage, 'article'), display_id)['article'] |
161 | title = article.get('title') | |
6d475d01 | 162 | description = clean_html(article.get('leadParagraph')) or '' |
a098c99f RA |
163 | if article.get('editorialType') != 'VID': |
164 | entries = [] | |
6d475d01 S |
165 | body = [article.get('opening')] |
166 | body.extend(try_get(article, lambda x: x['body'], list) or []) | |
167 | for p in body: | |
168 | if not isinstance(p, dict): | |
169 | continue | |
a098c99f | 170 | content = p.get('content') |
6d475d01 S |
171 | if not content: |
172 | continue | |
173 | type_ = p.get('type') | |
174 | if type_ == 'paragraph': | |
175 | content_str = str_or_none(content) | |
176 | if content_str: | |
177 | description += content_str | |
a098c99f | 178 | continue |
6d475d01 S |
179 | if type_ == 'video' and isinstance(content, dict): |
180 | entries.append(self._parse_content(content, url)) | |
a098c99f RA |
181 | return self.playlist_result( |
182 | entries, str_or_none(article.get('id')), title, description) | |
183 | content = article['opening']['content'] | |
184 | info = self._parse_content(content, url) | |
47335a0e | 185 | info.update({ |
a098c99f | 186 | 'description': description, |
47335a0e RA |
187 | }) |
188 | return info |