]>
Commit | Line | Data |
---|---|---|
a098c99f RA |
1 | import json |
2 | import re | |
ad5f53ac | 3 | |
a098c99f | 4 | from .common import InfoExtractor |
a098c99f RA |
5 | from ..utils import ( |
6 | clean_html, | |
a098c99f RA |
7 | int_or_none, |
8 | str_or_none, | |
6d475d01 | 9 | try_get, |
a098c99f | 10 | ) |
ad5f53ac | 11 | |
a098c99f RA |
12 | |
13 | class TelecincoIE(InfoExtractor): | |
4647fd89 | 14 | IE_DESC = 'telecinco.es, cuatro.com and mediaset.es' |
92519402 | 15 | _VALID_URL = r'https?://(?:www\.)?(?:telecinco\.es|cuatro\.com|mediaset\.es)/(?:[^/]+/)+(?P<id>.+?)\.html' |
ad5f53ac | 16 | |
c10ea454 | 17 | _TESTS = [{ |
ad5f53ac JMF |
18 | 'url': 'http://www.telecinco.es/robinfood/temporada-01/t01xp14/Bacalao-cocochas-pil-pil_0_1876350223.html', |
19 | 'info_dict': { | |
a098c99f | 20 | 'id': '1876350223', |
47335a0e | 21 | 'title': 'Bacalao con kokotxas al pil-pil', |
6d475d01 | 22 | 'description': 'md5:716caf5601e25c3c5ab6605b1ae71529', |
ad5f53ac | 23 | }, |
a098c99f | 24 | 'playlist': [{ |
29f7c58a | 25 | 'md5': '7ee56d665cfd241c0e6d80fd175068b0', |
a098c99f RA |
26 | 'info_dict': { |
27 | 'id': 'JEA5ijCnF6p5W08A1rNKn7', | |
28 | 'ext': 'mp4', | |
29 | 'title': 'Con Martín Berasategui, hacer un bacalao al pil-pil es fácil y divertido', | |
30 | 'duration': 662, | |
31 | }, | |
32 | }] | |
d5e7657f S |
33 | }, { |
34 | 'url': 'http://www.cuatro.com/deportes/futbol/barcelona/Leo_Messi-Champions-Roma_2_2052780128.html', | |
29f7c58a | 35 | 'md5': 'c86fe0d99e3bdb46b7950d38bf6ef12a', |
d5e7657f | 36 | 'info_dict': { |
47335a0e | 37 | 'id': 'jn24Od1zGLG4XUZcnUnZB6', |
d5e7657f | 38 | 'ext': 'mp4', |
47335a0e RA |
39 | 'title': '¿Quién es este ex futbolista con el que hablan Leo Messi y Luis Suárez?', |
40 | 'description': 'md5:a62ecb5f1934fc787107d7b9a2262805', | |
d5e7657f S |
41 | 'duration': 79, |
42 | }, | |
d492dad8 S |
43 | }, { |
44 | 'url': 'http://www.mediaset.es/12meses/campanas/doylacara/conlatratanohaytrato/Ayudame-dar-cara-trata-trato_2_1986630220.html', | |
29f7c58a | 45 | 'md5': 'eddb50291df704ce23c74821b995bcac', |
d492dad8 | 46 | 'info_dict': { |
47335a0e | 47 | 'id': 'aywerkD2Sv1vGNqq9b85Q2', |
d492dad8 S |
48 | 'ext': 'mp4', |
49 | 'title': '#DOYLACARA. Con la trata no hay trato', | |
47335a0e | 50 | 'description': 'md5:2771356ff7bfad9179c5f5cd954f1477', |
d492dad8 S |
51 | 'duration': 50, |
52 | }, | |
6d475d01 S |
53 | }, { |
54 | # video in opening's content | |
55 | 'url': 'https://www.telecinco.es/vivalavida/fiorella-sobrina-edmundo-arrocet-entrevista_18_2907195140.html', | |
56 | 'info_dict': { | |
57 | 'id': '2907195140', | |
58 | 'title': 'La surrealista entrevista a la sobrina de Edmundo Arrocet: "No puedes venir aquí y tomarnos por tontos"', | |
59 | 'description': 'md5:73f340a7320143d37ab895375b2bf13a', | |
60 | }, | |
61 | 'playlist': [{ | |
62 | 'md5': 'adb28c37238b675dad0f042292f209a7', | |
63 | 'info_dict': { | |
64 | 'id': 'TpI2EttSDAReWpJ1o0NVh2', | |
65 | 'ext': 'mp4', | |
66 | 'title': 'La surrealista entrevista a la sobrina de Edmundo Arrocet: "No puedes venir aquí y tomarnos por tontos"', | |
67 | 'duration': 1015, | |
68 | }, | |
69 | }], | |
70 | 'params': { | |
71 | 'skip_download': True, | |
72 | }, | |
c10ea454 JMF |
73 | }, { |
74 | 'url': 'http://www.telecinco.es/informativos/nacional/Pablo_Iglesias-Informativos_Telecinco-entrevista-Pedro_Piqueras_2_1945155182.html', | |
75 | 'only_matching': True, | |
34a4cd0a S |
76 | }, { |
77 | 'url': 'http://www.telecinco.es/espanasinirmaslejos/Espana-gran-destino-turistico_2_1240605043.html', | |
78 | 'only_matching': True, | |
9d089630 | 79 | }, { |
9d089630 S |
80 | 'url': 'http://www.cuatro.com/chesterinlove/a-carta/chester-chester_in_love-chester_edu_2_2331030022.html', |
81 | 'only_matching': True, | |
c10ea454 | 82 | }] |
12bc2429 | 83 | |
a098c99f RA |
84 | def _parse_content(self, content, url): |
85 | video_id = content['dataMediaId'] | |
a098c99f | 86 | config = self._download_json( |
29f7c58a | 87 | content['dataConfig'], video_id, 'Downloading config JSON') |
a098c99f | 88 | title = config['info']['title'] |
29f7c58a | 89 | services = config['services'] |
90 | caronte = self._download_json(services['caronte'], video_id) | |
91 | stream = caronte['dls'][0]['stream'] | |
92 | headers = self.geo_verification_headers() | |
93 | headers.update({ | |
94 | 'Content-Type': 'application/json;charset=UTF-8', | |
95 | 'Origin': re.match(r'https?://[^/]+', url).group(0), | |
96 | }) | |
97 | cdn = self._download_json( | |
98 | caronte['cerbero'], video_id, data=json.dumps({ | |
99 | 'bbx': caronte['bbx'], | |
100 | 'gbx': self._download_json(services['gbx'], video_id)['gbx'], | |
101 | }).encode(), headers=headers)['tokens']['1']['cdn'] | |
102 | formats = self._extract_m3u8_formats( | |
103 | stream + '?' + cdn, video_id, 'mp4', 'm3u8_native', m3u8_id='hls') | |
a098c99f RA |
104 | |
105 | return { | |
106 | 'id': video_id, | |
107 | 'title': title, | |
108 | 'formats': formats, | |
109 | 'thumbnail': content.get('dataPoster') or config.get('poster', {}).get('imageUrl'), | |
29f7c58a | 110 | 'duration': int_or_none(content.get('dataDuration')), |
a098c99f RA |
111 | } |
112 | ||
12bc2429 | 113 | def _real_extract(self, url): |
47335a0e RA |
114 | display_id = self._match_id(url) |
115 | webpage = self._download_webpage(url, display_id) | |
a098c99f | 116 | article = self._parse_json(self._search_regex( |
f8cbd8c9 | 117 | r'window\.\$REACTBASE_STATE\.article(?:_multisite)?\s*=\s*({.+})', |
a098c99f RA |
118 | webpage, 'article'), display_id)['article'] |
119 | title = article.get('title') | |
6d475d01 | 120 | description = clean_html(article.get('leadParagraph')) or '' |
a098c99f RA |
121 | if article.get('editorialType') != 'VID': |
122 | entries = [] | |
6d475d01 S |
123 | body = [article.get('opening')] |
124 | body.extend(try_get(article, lambda x: x['body'], list) or []) | |
125 | for p in body: | |
126 | if not isinstance(p, dict): | |
127 | continue | |
a098c99f | 128 | content = p.get('content') |
6d475d01 S |
129 | if not content: |
130 | continue | |
131 | type_ = p.get('type') | |
132 | if type_ == 'paragraph': | |
133 | content_str = str_or_none(content) | |
134 | if content_str: | |
135 | description += content_str | |
a098c99f | 136 | continue |
6d475d01 S |
137 | if type_ == 'video' and isinstance(content, dict): |
138 | entries.append(self._parse_content(content, url)) | |
a098c99f RA |
139 | return self.playlist_result( |
140 | entries, str_or_none(article.get('id')), title, description) | |
141 | content = article['opening']['content'] | |
142 | info = self._parse_content(content, url) | |
47335a0e | 143 | info.update({ |
a098c99f | 144 | 'description': description, |
47335a0e RA |
145 | }) |
146 | return info |