]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/tv5mondeplus.py
debian/patches: Remove patch cherry-picked from upstream.
[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 clean_html,
7 determine_ext,
8 extract_attributes,
9 get_element_by_class,
10 int_or_none,
11 parse_duration,
12 parse_iso8601,
13 )
14
15
16 class TV5MondePlusIE(InfoExtractor):
17 IE_DESC = 'TV5MONDE+'
18 _VALID_URL = r'https?://(?:www\.)?tv5mondeplus\.com/toutes-les-videos/[^/]+/(?P<id>[^/?#]+)'
19 _TEST = {
20 'url': 'http://www.tv5mondeplus.com/toutes-les-videos/documentaire/tdah-mon-amour-tele-quebec-tdah-mon-amour-ep001-enfants',
21 'md5': '12130fc199f020673138a83466542ec6',
22 'info_dict': {
23 'id': 'tdah-mon-amour-tele-quebec-tdah-mon-amour-ep001-enfants',
24 'ext': 'mp4',
25 'title': 'Tdah, mon amour - Enfants',
26 'description': 'md5:230e3aca23115afcf8006d1bece6df74',
27 'upload_date': '20170401',
28 'timestamp': 1491022860,
29 }
30 }
31 _GEO_BYPASS = False
32
33 def _real_extract(self, url):
34 display_id = self._match_id(url)
35 webpage = self._download_webpage(url, display_id)
36
37 if ">Ce programme n'est malheureusement pas disponible pour votre zone géographique.<" in webpage:
38 self.raise_geo_restricted(countries=['FR'])
39
40 series = get_element_by_class('video-detail__title', webpage)
41 title = episode = get_element_by_class(
42 'video-detail__subtitle', webpage) or series
43 if series and series != title:
44 title = '%s - %s' % (series, title)
45 vpl_data = extract_attributes(self._search_regex(
46 r'(<[^>]+class="video_player_loader"[^>]+>)',
47 webpage, 'video player loader'))
48
49 video_files = self._parse_json(
50 vpl_data['data-broadcast'], display_id).get('files', [])
51 formats = []
52 for video_file in video_files:
53 v_url = video_file.get('url')
54 if not v_url:
55 continue
56 video_format = video_file.get('format') or determine_ext(v_url)
57 if video_format == 'm3u8':
58 formats.extend(self._extract_m3u8_formats(
59 v_url, display_id, 'mp4', 'm3u8_native',
60 m3u8_id='hls', fatal=False))
61 else:
62 formats.append({
63 'url': v_url,
64 'format_id': video_format,
65 })
66 self._sort_formats(formats)
67
68 return {
69 'id': display_id,
70 'display_id': display_id,
71 'title': title,
72 'description': clean_html(get_element_by_class('video-detail__description', webpage)),
73 'thumbnail': vpl_data.get('data-image'),
74 'duration': int_or_none(vpl_data.get('data-duration')) or parse_duration(self._html_search_meta('duration', webpage)),
75 'timestamp': parse_iso8601(self._html_search_meta('uploadDate', webpage)),
76 'formats': formats,
77 'episode': episode,
78 'series': series,
79 }