]>
Commit | Line | Data |
---|---|---|
7d3d658f JD |
1 | import urllib.parse |
2 | ||
61e2331a RA |
3 | from .common import InfoExtractor |
4 | from ..utils import ( | |
6db96268 | 5 | clean_html, |
61e2331a RA |
6 | determine_ext, |
7 | extract_attributes, | |
6db96268 | 8 | get_element_by_class, |
9 | get_element_html_by_class, | |
61e2331a | 10 | int_or_none, |
7d3d658f | 11 | url_or_none, |
61e2331a | 12 | ) |
6db96268 | 13 | from ..utils.traversal import traverse_obj |
61e2331a RA |
14 | |
15 | ||
16 | class TV5MondePlusIE(InfoExtractor): | |
6db96268 | 17 | IE_NAME = 'TV5MONDE' |
18 | _VALID_URL = r'https?://(?:www\.)?tv5monde\.com/tv/video/(?P<id>[^/?#]+)' | |
d95a1cc9 | 19 | _TESTS = [{ |
6db96268 | 20 | # documentary |
21 | 'url': 'https://www.tv5monde.com/tv/video/65931-baudouin-l-heritage-d-un-roi-baudouin-l-heritage-d-un-roi', | |
22 | 'md5': 'd2a708902d3df230a357c99701aece05', | |
7d3d658f | 23 | 'info_dict': { |
6db96268 | 24 | 'id': '3FPa7JMu21_6D4BA7b', |
25 | 'display_id': '65931-baudouin-l-heritage-d-un-roi-baudouin-l-heritage-d-un-roi', | |
7d3d658f | 26 | 'ext': 'mp4', |
6db96268 | 27 | 'title': "Baudouin, l'héritage d'un roi", |
28 | 'thumbnail': 'https://psi.tv5monde.com/upsilon-images/960x540/6f/baudouin-f49c6b0e.jpg', | |
29 | 'duration': 4842, | |
30 | 'upload_date': '20240130', | |
31 | 'timestamp': 1706641242, | |
32 | 'episode': "BAUDOUIN, L'HERITAGE D'UN ROI", | |
33 | 'description': 'md5:78125c74a5cac06d7743a2d09126edad', | |
34 | 'series': "Baudouin, l'héritage d'un roi", | |
7d3d658f JD |
35 | }, |
36 | }, { | |
37 | # series episode | |
6db96268 | 38 | 'url': 'https://www.tv5monde.com/tv/video/52952-toute-la-vie-mardi-23-mars-2021', |
39 | 'md5': 'f5e09637cadd55639c05874e22eb56bf', | |
7d3d658f | 40 | 'info_dict': { |
6db96268 | 41 | 'id': 'obRRZ8m6g9_6D4BA7b', |
42 | 'display_id': '52952-toute-la-vie-mardi-23-mars-2021', | |
7d3d658f | 43 | 'ext': 'mp4', |
6db96268 | 44 | 'title': 'Toute la vie', |
45 | 'description': 'md5:a824a2e1dfd94cf45fa379a1fb43ce65', | |
46 | 'thumbnail': 'https://psi.tv5monde.com/media/image/960px/5880553.jpg', | |
47 | 'duration': 2526, | |
48 | 'upload_date': '20230721', | |
49 | 'timestamp': 1689971646, | |
50 | 'series': 'Toute la vie', | |
51 | 'episode': 'Mardi 23 mars 2021', | |
7d3d658f JD |
52 | }, |
53 | }, { | |
d95a1cc9 | 54 | # movie |
6db96268 | 55 | 'url': 'https://www.tv5monde.com/tv/video/8771-ce-fleuve-qui-nous-charrie-ce-fleuve-qui-nous-charrie-p001-ce-fleuve-qui-nous-charrie', |
56 | 'md5': '87cefc34e10a6bf4f7823cccd7b36eb2', | |
61e2331a | 57 | 'info_dict': { |
6db96268 | 58 | 'id': 'DOcfvdLKXL_6D4BA7b', |
59 | 'display_id': '8771-ce-fleuve-qui-nous-charrie-ce-fleuve-qui-nous-charrie-p001-ce-fleuve-qui-nous-charrie', | |
61e2331a | 60 | 'ext': 'mp4', |
6db96268 | 61 | 'title': 'Ce fleuve qui nous charrie', |
62 | 'description': 'md5:62ba3f875343c7fc4082bdfbbc1be992', | |
63 | 'thumbnail': 'https://psi.tv5monde.com/media/image/960px/5476617.jpg', | |
64 | 'duration': 5300, | |
65 | 'upload_date': '20210822', | |
66 | 'timestamp': 1629594105, | |
67 | 'episode': 'CE FLEUVE QUI NOUS CHARRIE-P001-CE FLEUVE QUI NOUS CHARRIE', | |
68 | 'series': 'Ce fleuve qui nous charrie', | |
d95a1cc9 S |
69 | }, |
70 | }, { | |
6db96268 | 71 | # news |
72 | 'url': 'https://www.tv5monde.com/tv/video/70402-tv5monde-le-journal-edition-du-08-05-24-11h', | |
73 | 'md5': 'c62977d6d10754a2ecebba70ad370479', | |
d95a1cc9 | 74 | 'info_dict': { |
6db96268 | 75 | 'id': 'LgQFrOCNsc_6D4BA7b', |
76 | 'display_id': '70402-tv5monde-le-journal-edition-du-08-05-24-11h', | |
d95a1cc9 | 77 | 'ext': 'mp4', |
6db96268 | 78 | 'title': 'TV5MONDE, le journal', |
79 | 'description': 'md5:777dc209eaa4423b678477c36b0b04a8', | |
80 | 'thumbnail': 'https://psi.tv5monde.com/media/image/960px/6184105.jpg', | |
81 | 'duration': 854, | |
82 | 'upload_date': '20240508', | |
83 | 'timestamp': 1715159640, | |
84 | 'series': 'TV5MONDE, le journal', | |
85 | 'episode': 'EDITION DU 08/05/24 - 11H', | |
d95a1cc9 | 86 | }, |
d95a1cc9 | 87 | }] |
61e2331a RA |
88 | _GEO_BYPASS = False |
89 | ||
0f634dba F |
90 | @staticmethod |
91 | def _extract_subtitles(data_captions): | |
92 | subtitles = {} | |
93 | for f in traverse_obj(data_captions, ('files', lambda _, v: url_or_none(v['file']))): | |
94 | subtitles.setdefault(f.get('label') or 'fra', []).append({'url': f['file']}) | |
95 | return subtitles | |
96 | ||
61e2331a RA |
97 | def _real_extract(self, url): |
98 | display_id = self._match_id(url) | |
99 | webpage = self._download_webpage(url, display_id) | |
100 | ||
101 | if ">Ce programme n'est malheureusement pas disponible pour votre zone géographique.<" in webpage: | |
102 | self.raise_geo_restricted(countries=['FR']) | |
103 | ||
61e2331a RA |
104 | vpl_data = extract_attributes(self._search_regex( |
105 | r'(<[^>]+class="video_player_loader"[^>]+>)', | |
106 | webpage, 'video player loader')) | |
107 | ||
108 | video_files = self._parse_json( | |
f79ec47d | 109 | vpl_data['data-broadcast'], display_id) |
61e2331a | 110 | formats = [] |
7d3d658f JD |
111 | video_id = None |
112 | ||
113 | def process_video_files(v): | |
114 | nonlocal video_id | |
115 | for video_file in v: | |
116 | v_url = video_file.get('url') | |
117 | if not v_url: | |
118 | continue | |
119 | if video_file.get('type') == 'application/deferred': | |
120 | d_param = urllib.parse.quote(v_url) | |
121 | token = video_file.get('token') | |
122 | if not token: | |
123 | continue | |
124 | deferred_json = self._download_json( | |
125 | f'https://api.tv5monde.com/player/asset/{d_param}/resolve?condenseKS=true', display_id, | |
126 | note='Downloading deferred info', headers={'Authorization': f'Bearer {token}'}, fatal=False) | |
127 | v_url = traverse_obj(deferred_json, (0, 'url', {url_or_none})) | |
128 | if not v_url: | |
129 | continue | |
130 | # data-guid from the webpage isn't stable, use the material id from the json urls | |
131 | video_id = self._search_regex( | |
132 | r'materials/([\da-zA-Z]{10}_[\da-fA-F]{7})/', v_url, 'video id', default=None) | |
133 | process_video_files(deferred_json) | |
134 | ||
135 | video_format = video_file.get('format') or determine_ext(v_url) | |
136 | if video_format == 'm3u8': | |
137 | formats.extend(self._extract_m3u8_formats( | |
138 | v_url, display_id, 'mp4', 'm3u8_native', | |
139 | m3u8_id='hls', fatal=False)) | |
140 | elif video_format == 'mpd': | |
141 | formats.extend(self._extract_mpd_formats( | |
142 | v_url, display_id, fatal=False)) | |
143 | else: | |
144 | formats.append({ | |
145 | 'url': v_url, | |
146 | 'format_id': video_format, | |
147 | }) | |
148 | ||
149 | process_video_files(video_files) | |
61e2331a | 150 | |
f79ec47d | 151 | metadata = self._parse_json( |
6db96268 | 152 | vpl_data.get('data-metadata') or '{}', display_id, fatal=False) |
d95a1cc9 | 153 | |
7d3d658f JD |
154 | if not video_id: |
155 | video_id = self._search_regex( | |
156 | (r'data-guid=["\']([\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})', | |
157 | r'id_contenu["\']\s:\s*(\d+)'), webpage, 'video id', | |
158 | default=display_id) | |
d95a1cc9 | 159 | |
61e2331a | 160 | return { |
6db96268 | 161 | **traverse_obj(metadata, ('content', { |
162 | 'id': ('id', {str}), | |
163 | 'title': ('title', {str}), | |
164 | 'episode': ('title', {str}), | |
165 | 'series': ('series', {str}), | |
166 | 'timestamp': ('publishDate_ts', {int_or_none}), | |
167 | 'duration': ('duration', {int_or_none}), | |
168 | })), | |
d95a1cc9 | 169 | 'id': video_id, |
61e2331a | 170 | 'display_id': display_id, |
6db96268 | 171 | 'title': clean_html(get_element_by_class('main-title', webpage)), |
172 | 'description': clean_html(get_element_by_class('text', get_element_html_by_class('ep-summary', webpage) or '')), | |
173 | 'thumbnail': url_or_none(vpl_data.get('data-image')), | |
61e2331a | 174 | 'formats': formats, |
0f634dba F |
175 | 'subtitles': self._extract_subtitles(self._parse_json( |
176 | traverse_obj(vpl_data, ('data-captions', {str}), default='{}'), display_id, fatal=False)), | |
61e2331a | 177 | } |