]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/sixplay.py
debian/patches/remove-autoupdate-mechanism.patch: Refresh.
[youtubedl] / youtube_dl / extractor / sixplay.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..compat import (
8 compat_parse_qs,
9 compat_str,
10 compat_urllib_parse_urlparse,
11 )
12 from ..utils import (
13 determine_ext,
14 int_or_none,
15 try_get,
16 qualities,
17 )
18
19
20 class SixPlayIE(InfoExtractor):
21 IE_NAME = '6play'
22 _VALID_URL = r'(?:6play:|https?://(?:www\.)?6play\.fr/.+?-c_)(?P<id>[0-9]+)'
23 _TEST = {
24 'url': 'http://www.6play.fr/le-meilleur-patissier-p_1807/le-meilleur-patissier-special-fetes-mercredi-a-21-00-sur-m6-c_11638450',
25 'md5': '42310bffe4ba3982db112b9cd3467328',
26 'info_dict': {
27 'id': '11638450',
28 'ext': 'mp4',
29 'title': 'Le Meilleur Pâtissier, spécial fêtes mercredi à 21:00 sur M6',
30 'description': 'md5:308853f6a5f9e2d55a30fc0654de415f',
31 'duration': 39,
32 'series': 'Le meilleur pâtissier',
33 },
34 'params': {
35 'skip_download': True,
36 },
37 }
38
39 def _real_extract(self, url):
40 video_id = self._match_id(url)
41
42 data = self._download_json(
43 'https://pc.middleware.6play.fr/6play/v2/platforms/m6group_web/services/6play/videos/clip_%s' % video_id,
44 video_id, query={
45 'csa': 5,
46 'with': 'clips',
47 })
48
49 clip_data = data['clips'][0]
50 title = clip_data['title']
51
52 urls = []
53 quality_key = qualities(['lq', 'sd', 'hq', 'hd'])
54 formats = []
55 subtitles = {}
56 for asset in clip_data['assets']:
57 asset_url = asset.get('full_physical_path')
58 protocol = asset.get('protocol')
59 if not asset_url or protocol == 'primetime' or asset_url in urls:
60 continue
61 urls.append(asset_url)
62 container = asset.get('video_container')
63 ext = determine_ext(asset_url)
64 if protocol == 'http_subtitle' or ext == 'vtt':
65 subtitles.setdefault('fr', []).append({'url': asset_url})
66 continue
67 if container == 'm3u8' or ext == 'm3u8':
68 if protocol == 'usp' and not compat_parse_qs(compat_urllib_parse_urlparse(asset_url).query).get('token', [None])[0]:
69 asset_url = re.sub(r'/([^/]+)\.ism/[^/]*\.m3u8', r'/\1.ism/\1.m3u8', asset_url)
70 formats.extend(self._extract_m3u8_formats(
71 asset_url, video_id, 'mp4', 'm3u8_native',
72 m3u8_id='hls', fatal=False))
73 formats.extend(self._extract_f4m_formats(
74 asset_url.replace('.m3u8', '.f4m'),
75 video_id, f4m_id='hds', fatal=False))
76 formats.extend(self._extract_mpd_formats(
77 asset_url.replace('.m3u8', '.mpd'),
78 video_id, mpd_id='dash', fatal=False))
79 formats.extend(self._extract_ism_formats(
80 re.sub(r'/[^/]+\.m3u8', '/Manifest', asset_url),
81 video_id, ism_id='mss', fatal=False))
82 else:
83 formats.extend(self._extract_m3u8_formats(
84 asset_url, video_id, 'mp4', 'm3u8_native',
85 m3u8_id='hls', fatal=False))
86 elif container == 'mp4' or ext == 'mp4':
87 quality = asset.get('video_quality')
88 formats.append({
89 'url': asset_url,
90 'format_id': quality,
91 'quality': quality_key(quality),
92 'ext': ext,
93 })
94 self._sort_formats(formats)
95
96 def get(getter):
97 for src in (data, clip_data):
98 v = try_get(src, getter, compat_str)
99 if v:
100 return v
101
102 return {
103 'id': video_id,
104 'title': title,
105 'description': get(lambda x: x['description']),
106 'duration': int_or_none(clip_data.get('duration')),
107 'series': get(lambda x: x['program']['title']),
108 'formats': formats,
109 'subtitles': subtitles,
110 }