]>
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 S |
79 | }, { |
80 | # ooyala video | |
81 | 'url': 'http://www.cuatro.com/chesterinlove/a-carta/chester-chester_in_love-chester_edu_2_2331030022.html', | |
82 | 'only_matching': True, | |
c10ea454 | 83 | }] |
12bc2429 | 84 | |
a098c99f RA |
85 | def _parse_content(self, content, url): |
86 | video_id = content['dataMediaId'] | |
a098c99f | 87 | config = self._download_json( |
29f7c58a | 88 | content['dataConfig'], video_id, 'Downloading config JSON') |
a098c99f | 89 | title = config['info']['title'] |
29f7c58a | 90 | services = config['services'] |
91 | caronte = self._download_json(services['caronte'], video_id) | |
92 | stream = caronte['dls'][0]['stream'] | |
93 | headers = self.geo_verification_headers() | |
94 | headers.update({ | |
95 | 'Content-Type': 'application/json;charset=UTF-8', | |
96 | 'Origin': re.match(r'https?://[^/]+', url).group(0), | |
97 | }) | |
98 | cdn = self._download_json( | |
99 | caronte['cerbero'], video_id, data=json.dumps({ | |
100 | 'bbx': caronte['bbx'], | |
101 | 'gbx': self._download_json(services['gbx'], video_id)['gbx'], | |
102 | }).encode(), headers=headers)['tokens']['1']['cdn'] | |
103 | formats = self._extract_m3u8_formats( | |
104 | stream + '?' + cdn, video_id, 'mp4', 'm3u8_native', m3u8_id='hls') | |
a098c99f RA |
105 | |
106 | return { | |
107 | 'id': video_id, | |
108 | 'title': title, | |
109 | 'formats': formats, | |
110 | 'thumbnail': content.get('dataPoster') or config.get('poster', {}).get('imageUrl'), | |
29f7c58a | 111 | 'duration': int_or_none(content.get('dataDuration')), |
a098c99f RA |
112 | } |
113 | ||
12bc2429 | 114 | def _real_extract(self, url): |
47335a0e RA |
115 | display_id = self._match_id(url) |
116 | webpage = self._download_webpage(url, display_id) | |
a098c99f | 117 | article = self._parse_json(self._search_regex( |
f8cbd8c9 | 118 | r'window\.\$REACTBASE_STATE\.article(?:_multisite)?\s*=\s*({.+})', |
a098c99f RA |
119 | webpage, 'article'), display_id)['article'] |
120 | title = article.get('title') | |
6d475d01 | 121 | description = clean_html(article.get('leadParagraph')) or '' |
a098c99f RA |
122 | if article.get('editorialType') != 'VID': |
123 | entries = [] | |
6d475d01 S |
124 | body = [article.get('opening')] |
125 | body.extend(try_get(article, lambda x: x['body'], list) or []) | |
126 | for p in body: | |
127 | if not isinstance(p, dict): | |
128 | continue | |
a098c99f | 129 | content = p.get('content') |
6d475d01 S |
130 | if not content: |
131 | continue | |
132 | type_ = p.get('type') | |
133 | if type_ == 'paragraph': | |
134 | content_str = str_or_none(content) | |
135 | if content_str: | |
136 | description += content_str | |
a098c99f | 137 | continue |
6d475d01 S |
138 | if type_ == 'video' and isinstance(content, dict): |
139 | entries.append(self._parse_content(content, url)) | |
a098c99f RA |
140 | return self.playlist_result( |
141 | entries, str_or_none(article.get('id')), title, description) | |
142 | content = article['opening']['content'] | |
143 | info = self._parse_content(content, url) | |
47335a0e | 144 | info.update({ |
a098c99f | 145 | 'description': description, |
47335a0e RA |
146 | }) |
147 | return info |