]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/tv5mondeplus.py
Annotate some highlights of the release.
[youtubedl] / youtube_dl / 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 )
11
12
13 class TV5MondePlusIE(InfoExtractor):
14 IE_DESC = 'TV5MONDE+'
15 _VALID_URL = r'https?://(?:www\.)?(?:tv5mondeplus|revoir\.tv5monde)\.com/toutes-les-videos/[^/]+/(?P<id>[^/?#]+)'
16 _TESTS = [{
17 # movie
18 'url': 'https://revoir.tv5monde.com/toutes-les-videos/cinema/rendez-vous-a-atlit',
19 'md5': '8cbde5ea7b296cf635073e27895e227f',
20 'info_dict': {
21 'id': '822a4756-0712-7329-1859-a13ac7fd1407',
22 'display_id': 'rendez-vous-a-atlit',
23 'ext': 'mp4',
24 'title': 'Rendez-vous à Atlit',
25 'description': 'md5:2893a4c5e1dbac3eedff2d87956e4efb',
26 'upload_date': '20200130',
27 },
28 }, {
29 # series episode
30 'url': 'https://revoir.tv5monde.com/toutes-les-videos/series-fictions/c-est-la-vie-ennemie-juree',
31 'info_dict': {
32 'id': '0df7007c-4900-3936-c601-87a13a93a068',
33 'display_id': 'c-est-la-vie-ennemie-juree',
34 'ext': 'mp4',
35 'title': "C'est la vie - Ennemie jurée",
36 'description': 'md5:dfb5c63087b6f35fe0cc0af4fe44287e',
37 'upload_date': '20200130',
38 'series': "C'est la vie",
39 'episode': 'Ennemie jurée',
40 },
41 'params': {
42 'skip_download': True,
43 },
44 }, {
45 'url': 'https://revoir.tv5monde.com/toutes-les-videos/series-fictions/neuf-jours-en-hiver-neuf-jours-en-hiver',
46 'only_matching': True,
47 }, {
48 'url': 'https://revoir.tv5monde.com/toutes-les-videos/info-societe/le-journal-de-la-rts-edition-du-30-01-20-19h30',
49 'only_matching': True,
50 }]
51 _GEO_BYPASS = False
52
53 def _real_extract(self, url):
54 display_id = self._match_id(url)
55 webpage = self._download_webpage(url, display_id)
56
57 if ">Ce programme n'est malheureusement pas disponible pour votre zone géographique.<" in webpage:
58 self.raise_geo_restricted(countries=['FR'])
59
60 title = episode = self._html_search_regex(r'<h1>([^<]+)', webpage, 'title')
61 vpl_data = extract_attributes(self._search_regex(
62 r'(<[^>]+class="video_player_loader"[^>]+>)',
63 webpage, 'video player loader'))
64
65 video_files = self._parse_json(
66 vpl_data['data-broadcast'], display_id).get('files', [])
67 formats = []
68 for video_file in video_files:
69 v_url = video_file.get('url')
70 if not v_url:
71 continue
72 video_format = video_file.get('format') or determine_ext(v_url)
73 if video_format == 'm3u8':
74 formats.extend(self._extract_m3u8_formats(
75 v_url, display_id, 'mp4', 'm3u8_native',
76 m3u8_id='hls', fatal=False))
77 else:
78 formats.append({
79 'url': v_url,
80 'format_id': video_format,
81 })
82 self._sort_formats(formats)
83
84 description = self._html_search_regex(
85 r'(?s)<div[^>]+class=["\']episode-texte[^>]+>(.+?)</div>', webpage,
86 'description', fatal=False)
87
88 series = self._html_search_regex(
89 r'<p[^>]+class=["\']episode-emission[^>]+>([^<]+)', webpage,
90 'series', default=None)
91
92 if series and series != title:
93 title = '%s - %s' % (series, title)
94
95 upload_date = self._search_regex(
96 r'(?:date_publication|publish_date)["\']\s*:\s*["\'](\d{4}_\d{2}_\d{2})',
97 webpage, 'upload date', default=None)
98 if upload_date:
99 upload_date = upload_date.replace('_', '')
100
101 video_id = self._search_regex(
102 (r'data-guid=["\']([\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})',
103 r'id_contenu["\']\s:\s*(\d+)'), webpage, 'video id',
104 default=display_id)
105
106 return {
107 'id': video_id,
108 'display_id': display_id,
109 'title': title,
110 'description': description,
111 'thumbnail': vpl_data.get('data-image'),
112 'duration': int_or_none(vpl_data.get('data-duration')) or parse_duration(self._html_search_meta('duration', webpage)),
113 'upload_date': upload_date,
114 'formats': formats,
115 'series': series,
116 'episode': episode,
117 }