]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/tv5mondeplus.py
[ie/beatbump] Update `_VALID_URL` (#8576)
[yt-dlp.git] / yt_dlp / extractor / tv5mondeplus.py
CommitLineData
7d3d658f
JD
1import urllib.parse
2
61e2331a
RA
3from .common import InfoExtractor
4from ..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
15class 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
87 def _real_extract(self, url):
88 display_id = self._match_id(url)
89 webpage = self._download_webpage(url, display_id)
90
91 if ">Ce programme n'est malheureusement pas disponible pour votre zone géographique.<" in webpage:
92 self.raise_geo_restricted(countries=['FR'])
93
d95a1cc9 94 title = episode = self._html_search_regex(r'<h1>([^<]+)', webpage, 'title')
61e2331a
RA
95 vpl_data = extract_attributes(self._search_regex(
96 r'(<[^>]+class="video_player_loader"[^>]+>)',
97 webpage, 'video player loader'))
98
99 video_files = self._parse_json(
f79ec47d 100 vpl_data['data-broadcast'], display_id)
61e2331a 101 formats = []
7d3d658f
JD
102 video_id = None
103
104 def process_video_files(v):
105 nonlocal video_id
106 for video_file in v:
107 v_url = video_file.get('url')
108 if not v_url:
109 continue
110 if video_file.get('type') == 'application/deferred':
111 d_param = urllib.parse.quote(v_url)
112 token = video_file.get('token')
113 if not token:
114 continue
115 deferred_json = self._download_json(
116 f'https://api.tv5monde.com/player/asset/{d_param}/resolve?condenseKS=true', display_id,
117 note='Downloading deferred info', headers={'Authorization': f'Bearer {token}'}, fatal=False)
118 v_url = traverse_obj(deferred_json, (0, 'url', {url_or_none}))
119 if not v_url:
120 continue
121 # data-guid from the webpage isn't stable, use the material id from the json urls
122 video_id = self._search_regex(
123 r'materials/([\da-zA-Z]{10}_[\da-fA-F]{7})/', v_url, 'video id', default=None)
124 process_video_files(deferred_json)
125
126 video_format = video_file.get('format') or determine_ext(v_url)
127 if video_format == 'm3u8':
128 formats.extend(self._extract_m3u8_formats(
129 v_url, display_id, 'mp4', 'm3u8_native',
130 m3u8_id='hls', fatal=False))
131 elif video_format == 'mpd':
132 formats.extend(self._extract_mpd_formats(
133 v_url, display_id, fatal=False))
134 else:
135 formats.append({
136 'url': v_url,
137 'format_id': video_format,
138 })
139
140 process_video_files(video_files)
61e2331a 141
f79ec47d
JD
142 metadata = self._parse_json(
143 vpl_data['data-metadata'], display_id)
144 duration = (int_or_none(try_get(metadata, lambda x: x['content']['duration']))
145 or parse_duration(self._html_search_meta('duration', webpage)))
146
d95a1cc9
S
147 description = self._html_search_regex(
148 r'(?s)<div[^>]+class=["\']episode-texte[^>]+>(.+?)</div>', webpage,
149 'description', fatal=False)
150
151 series = self._html_search_regex(
152 r'<p[^>]+class=["\']episode-emission[^>]+>([^<]+)', webpage,
153 'series', default=None)
154
155 if series and series != title:
156 title = '%s - %s' % (series, title)
157
158 upload_date = self._search_regex(
159 r'(?:date_publication|publish_date)["\']\s*:\s*["\'](\d{4}_\d{2}_\d{2})',
160 webpage, 'upload date', default=None)
161 if upload_date:
162 upload_date = upload_date.replace('_', '')
163
7d3d658f
JD
164 if not video_id:
165 video_id = self._search_regex(
166 (r'data-guid=["\']([\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})',
167 r'id_contenu["\']\s:\s*(\d+)'), webpage, 'video id',
168 default=display_id)
d95a1cc9 169
61e2331a 170 return {
d95a1cc9 171 'id': video_id,
61e2331a
RA
172 'display_id': display_id,
173 'title': title,
d95a1cc9 174 'description': description,
61e2331a 175 'thumbnail': vpl_data.get('data-image'),
f79ec47d 176 'duration': duration,
d95a1cc9 177 'upload_date': upload_date,
61e2331a 178 'formats': formats,
61e2331a 179 'series': series,
d95a1cc9 180 'episode': episode,
61e2331a 181 }