]>
Commit | Line | Data |
---|---|---|
7d3d658f JD |
1 | import urllib.parse |
2 | ||
61e2331a RA |
3 | from .common import InfoExtractor |
4 | from ..utils import ( | |
5 | determine_ext, | |
6 | extract_attributes, | |
61e2331a RA |
7 | int_or_none, |
8 | parse_duration, | |
7d3d658f | 9 | traverse_obj, |
f79ec47d | 10 | try_get, |
7d3d658f | 11 | url_or_none, |
61e2331a RA |
12 | ) |
13 | ||
14 | ||
15 | class TV5MondePlusIE(InfoExtractor): | |
16 | IE_DESC = 'TV5MONDE+' | |
d95a1cc9 S |
17 | _VALID_URL = r'https?://(?:www\.)?(?:tv5mondeplus|revoir\.tv5monde)\.com/toutes-les-videos/[^/]+/(?P<id>[^/?#]+)' |
18 | _TESTS = [{ | |
7d3d658f JD |
19 | # movie |
20 | 'url': 'https://revoir.tv5monde.com/toutes-les-videos/cinema/les-novices', | |
21 | 'md5': 'c86f60bf8b75436455b1b205f9745955', | |
22 | 'info_dict': { | |
23 | 'id': 'ZX0ipMyFQq_6D4BA7b', | |
24 | 'display_id': 'les-novices', | |
25 | 'ext': 'mp4', | |
26 | 'title': 'Les novices', | |
27 | 'description': 'md5:2e7c33ba3ad48dabfcc2a956b88bde2b', | |
28 | 'upload_date': '20230821', | |
29 | 'thumbnail': 'https://revoir.tv5monde.com/uploads/media/video_thumbnail/0738/60/01e952b7ccf36b7c6007ec9131588954ab651de9.jpeg', | |
30 | 'duration': 5177, | |
31 | 'episode': 'Les novices', | |
32 | }, | |
33 | }, { | |
34 | # series episode | |
35 | 'url': 'https://revoir.tv5monde.com/toutes-les-videos/series-fictions/opj-les-dents-de-la-terre-2', | |
36 | 'info_dict': { | |
37 | 'id': 'wJ0eeEPozr_6D4BA7b', | |
38 | 'display_id': 'opj-les-dents-de-la-terre-2', | |
39 | 'ext': 'mp4', | |
40 | 'title': "OPJ - Les dents de la Terre (2)", | |
41 | 'description': 'md5:288f87fd68d993f814e66e60e5302d9d', | |
42 | 'upload_date': '20230823', | |
43 | 'series': 'OPJ', | |
44 | 'episode': 'Les dents de la Terre (2)', | |
45 | 'duration': 2877, | |
46 | 'thumbnail': 'https://dl-revoir.tv5monde.com/images/1a/5753448.jpg' | |
47 | }, | |
48 | }, { | |
d95a1cc9 | 49 | # movie |
f79ec47d JD |
50 | 'url': 'https://revoir.tv5monde.com/toutes-les-videos/cinema/ceux-qui-travaillent', |
51 | 'md5': '32fa0cde16a4480d1251502a66856d5f', | |
61e2331a | 52 | 'info_dict': { |
f79ec47d JD |
53 | 'id': 'dc57a011-ec4b-4648-2a9a-4f03f8352ed3', |
54 | 'display_id': 'ceux-qui-travaillent', | |
61e2331a | 55 | 'ext': 'mp4', |
f79ec47d JD |
56 | 'title': 'Ceux qui travaillent', |
57 | 'description': 'md5:570e8bb688036ace873b2d50d24c026d', | |
58 | 'upload_date': '20210819', | |
d95a1cc9 | 59 | }, |
7d3d658f | 60 | 'skip': 'no longer available', |
d95a1cc9 S |
61 | }, { |
62 | # series episode | |
f79ec47d | 63 | 'url': 'https://revoir.tv5monde.com/toutes-les-videos/series-fictions/vestiaires-caro-actrice', |
d95a1cc9 | 64 | 'info_dict': { |
f79ec47d JD |
65 | 'id': '9e9d599e-23af-6915-843e-ecbf62e97925', |
66 | 'display_id': 'vestiaires-caro-actrice', | |
d95a1cc9 | 67 | 'ext': 'mp4', |
f79ec47d JD |
68 | 'title': "Vestiaires - Caro actrice", |
69 | 'description': 'md5:db15d2e1976641e08377f942778058ea', | |
70 | 'upload_date': '20210819', | |
71 | 'series': "Vestiaires", | |
72 | 'episode': 'Caro actrice', | |
d95a1cc9 S |
73 | }, |
74 | 'params': { | |
75 | 'skip_download': True, | |
76 | }, | |
7d3d658f | 77 | 'skip': 'no longer available', |
d95a1cc9 S |
78 | }, { |
79 | 'url': 'https://revoir.tv5monde.com/toutes-les-videos/series-fictions/neuf-jours-en-hiver-neuf-jours-en-hiver', | |
80 | 'only_matching': True, | |
81 | }, { | |
82 | 'url': 'https://revoir.tv5monde.com/toutes-les-videos/info-societe/le-journal-de-la-rts-edition-du-30-01-20-19h30', | |
83 | 'only_matching': True, | |
84 | }] | |
61e2331a RA |
85 | _GEO_BYPASS = False |
86 | ||
0f634dba F |
87 | @staticmethod |
88 | def _extract_subtitles(data_captions): | |
89 | subtitles = {} | |
90 | for f in traverse_obj(data_captions, ('files', lambda _, v: url_or_none(v['file']))): | |
91 | subtitles.setdefault(f.get('label') or 'fra', []).append({'url': f['file']}) | |
92 | return subtitles | |
93 | ||
61e2331a RA |
94 | def _real_extract(self, url): |
95 | display_id = self._match_id(url) | |
96 | webpage = self._download_webpage(url, display_id) | |
97 | ||
98 | if ">Ce programme n'est malheureusement pas disponible pour votre zone géographique.<" in webpage: | |
99 | self.raise_geo_restricted(countries=['FR']) | |
100 | ||
d95a1cc9 | 101 | title = episode = self._html_search_regex(r'<h1>([^<]+)', webpage, 'title') |
61e2331a RA |
102 | vpl_data = extract_attributes(self._search_regex( |
103 | r'(<[^>]+class="video_player_loader"[^>]+>)', | |
104 | webpage, 'video player loader')) | |
105 | ||
106 | video_files = self._parse_json( | |
f79ec47d | 107 | vpl_data['data-broadcast'], display_id) |
61e2331a | 108 | formats = [] |
7d3d658f JD |
109 | video_id = None |
110 | ||
111 | def process_video_files(v): | |
112 | nonlocal video_id | |
113 | for video_file in v: | |
114 | v_url = video_file.get('url') | |
115 | if not v_url: | |
116 | continue | |
117 | if video_file.get('type') == 'application/deferred': | |
118 | d_param = urllib.parse.quote(v_url) | |
119 | token = video_file.get('token') | |
120 | if not token: | |
121 | continue | |
122 | deferred_json = self._download_json( | |
123 | f'https://api.tv5monde.com/player/asset/{d_param}/resolve?condenseKS=true', display_id, | |
124 | note='Downloading deferred info', headers={'Authorization': f'Bearer {token}'}, fatal=False) | |
125 | v_url = traverse_obj(deferred_json, (0, 'url', {url_or_none})) | |
126 | if not v_url: | |
127 | continue | |
128 | # data-guid from the webpage isn't stable, use the material id from the json urls | |
129 | video_id = self._search_regex( | |
130 | r'materials/([\da-zA-Z]{10}_[\da-fA-F]{7})/', v_url, 'video id', default=None) | |
131 | process_video_files(deferred_json) | |
132 | ||
133 | video_format = video_file.get('format') or determine_ext(v_url) | |
134 | if video_format == 'm3u8': | |
135 | formats.extend(self._extract_m3u8_formats( | |
136 | v_url, display_id, 'mp4', 'm3u8_native', | |
137 | m3u8_id='hls', fatal=False)) | |
138 | elif video_format == 'mpd': | |
139 | formats.extend(self._extract_mpd_formats( | |
140 | v_url, display_id, fatal=False)) | |
141 | else: | |
142 | formats.append({ | |
143 | 'url': v_url, | |
144 | 'format_id': video_format, | |
145 | }) | |
146 | ||
147 | process_video_files(video_files) | |
61e2331a | 148 | |
f79ec47d JD |
149 | metadata = self._parse_json( |
150 | vpl_data['data-metadata'], display_id) | |
151 | duration = (int_or_none(try_get(metadata, lambda x: x['content']['duration'])) | |
152 | or parse_duration(self._html_search_meta('duration', webpage))) | |
153 | ||
d95a1cc9 S |
154 | description = self._html_search_regex( |
155 | r'(?s)<div[^>]+class=["\']episode-texte[^>]+>(.+?)</div>', webpage, | |
156 | 'description', fatal=False) | |
157 | ||
158 | series = self._html_search_regex( | |
159 | r'<p[^>]+class=["\']episode-emission[^>]+>([^<]+)', webpage, | |
160 | 'series', default=None) | |
161 | ||
162 | if series and series != title: | |
163 | title = '%s - %s' % (series, title) | |
164 | ||
165 | upload_date = self._search_regex( | |
166 | r'(?:date_publication|publish_date)["\']\s*:\s*["\'](\d{4}_\d{2}_\d{2})', | |
167 | webpage, 'upload date', default=None) | |
168 | if upload_date: | |
169 | upload_date = upload_date.replace('_', '') | |
170 | ||
7d3d658f JD |
171 | if not video_id: |
172 | video_id = self._search_regex( | |
173 | (r'data-guid=["\']([\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})', | |
174 | r'id_contenu["\']\s:\s*(\d+)'), webpage, 'video id', | |
175 | default=display_id) | |
d95a1cc9 | 176 | |
61e2331a | 177 | return { |
d95a1cc9 | 178 | 'id': video_id, |
61e2331a RA |
179 | 'display_id': display_id, |
180 | 'title': title, | |
d95a1cc9 | 181 | 'description': description, |
61e2331a | 182 | 'thumbnail': vpl_data.get('data-image'), |
f79ec47d | 183 | 'duration': duration, |
d95a1cc9 | 184 | 'upload_date': upload_date, |
61e2331a | 185 | 'formats': formats, |
0f634dba F |
186 | 'subtitles': self._extract_subtitles(self._parse_json( |
187 | traverse_obj(vpl_data, ('data-captions', {str}), default='{}'), display_id, fatal=False)), | |
61e2331a | 188 | 'series': series, |
d95a1cc9 | 189 | 'episode': episode, |
61e2331a | 190 | } |