]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/tv5mondeplus.py
[tv5mondeplus] Fix extractor (#739)
[yt-dlp.git] / yt_dlp / extractor / tv5mondeplus.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6 determine_ext,
7 extract_attributes,
8 int_or_none,
9 parse_duration,
10 try_get,
11 )
12
13
14 class TV5MondePlusIE(InfoExtractor):
15 IE_DESC = 'TV5MONDE+'
16 _VALID_URL = r'https?://(?:www\.)?(?:tv5mondeplus|revoir\.tv5monde)\.com/toutes-les-videos/[^/]+/(?P<id>[^/?#]+)'
17 _TESTS = [{
18 # movie
19 'url': 'https://revoir.tv5monde.com/toutes-les-videos/cinema/ceux-qui-travaillent',
20 'md5': '32fa0cde16a4480d1251502a66856d5f',
21 'info_dict': {
22 'id': 'dc57a011-ec4b-4648-2a9a-4f03f8352ed3',
23 'display_id': 'ceux-qui-travaillent',
24 'ext': 'mp4',
25 'title': 'Ceux qui travaillent',
26 'description': 'md5:570e8bb688036ace873b2d50d24c026d',
27 'upload_date': '20210819',
28 },
29 }, {
30 # series episode
31 'url': 'https://revoir.tv5monde.com/toutes-les-videos/series-fictions/vestiaires-caro-actrice',
32 'info_dict': {
33 'id': '9e9d599e-23af-6915-843e-ecbf62e97925',
34 'display_id': 'vestiaires-caro-actrice',
35 'ext': 'mp4',
36 'title': "Vestiaires - Caro actrice",
37 'description': 'md5:db15d2e1976641e08377f942778058ea',
38 'upload_date': '20210819',
39 'series': "Vestiaires",
40 'episode': 'Caro actrice',
41 },
42 'params': {
43 'skip_download': True,
44 },
45 }, {
46 'url': 'https://revoir.tv5monde.com/toutes-les-videos/series-fictions/neuf-jours-en-hiver-neuf-jours-en-hiver',
47 'only_matching': True,
48 }, {
49 'url': 'https://revoir.tv5monde.com/toutes-les-videos/info-societe/le-journal-de-la-rts-edition-du-30-01-20-19h30',
50 'only_matching': True,
51 }]
52 _GEO_BYPASS = False
53
54 def _real_extract(self, url):
55 display_id = self._match_id(url)
56 webpage = self._download_webpage(url, display_id)
57
58 if ">Ce programme n'est malheureusement pas disponible pour votre zone géographique.<" in webpage:
59 self.raise_geo_restricted(countries=['FR'])
60
61 title = episode = self._html_search_regex(r'<h1>([^<]+)', webpage, 'title')
62 vpl_data = extract_attributes(self._search_regex(
63 r'(<[^>]+class="video_player_loader"[^>]+>)',
64 webpage, 'video player loader'))
65
66 video_files = self._parse_json(
67 vpl_data['data-broadcast'], display_id)
68 formats = []
69 for video_file in video_files:
70 v_url = video_file.get('url')
71 if not v_url:
72 continue
73 video_format = video_file.get('format') or determine_ext(v_url)
74 if video_format == 'm3u8':
75 formats.extend(self._extract_m3u8_formats(
76 v_url, display_id, 'mp4', 'm3u8_native',
77 m3u8_id='hls', fatal=False))
78 else:
79 formats.append({
80 'url': v_url,
81 'format_id': video_format,
82 })
83 self._sort_formats(formats)
84
85 metadata = self._parse_json(
86 vpl_data['data-metadata'], display_id)
87 duration = (int_or_none(try_get(metadata, lambda x: x['content']['duration']))
88 or parse_duration(self._html_search_meta('duration', webpage)))
89
90 description = self._html_search_regex(
91 r'(?s)<div[^>]+class=["\']episode-texte[^>]+>(.+?)</div>', webpage,
92 'description', fatal=False)
93
94 series = self._html_search_regex(
95 r'<p[^>]+class=["\']episode-emission[^>]+>([^<]+)', webpage,
96 'series', default=None)
97
98 if series and series != title:
99 title = '%s - %s' % (series, title)
100
101 upload_date = self._search_regex(
102 r'(?:date_publication|publish_date)["\']\s*:\s*["\'](\d{4}_\d{2}_\d{2})',
103 webpage, 'upload date', default=None)
104 if upload_date:
105 upload_date = upload_date.replace('_', '')
106
107 video_id = self._search_regex(
108 (r'data-guid=["\']([\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})',
109 r'id_contenu["\']\s:\s*(\d+)'), webpage, 'video id',
110 default=display_id)
111
112 return {
113 'id': video_id,
114 'display_id': display_id,
115 'title': title,
116 'description': description,
117 'thumbnail': vpl_data.get('data-image'),
118 'duration': duration,
119 'upload_date': upload_date,
120 'formats': formats,
121 'series': series,
122 'episode': episode,
123 }