[ie/soundcloud] Various fixes (#11820)
[yt-dlp.git] / yt_dlp / extractor / sixplay.py
blob6037a35116ae6fa900b965edd219d40a5cefbd2c
1 from .common import InfoExtractor
2 from ..utils import (
3 determine_ext,
4 int_or_none,
5 parse_qs,
6 qualities,
7 try_get,
11 class SixPlayIE(InfoExtractor):
12 IE_NAME = '6play'
13 _VALID_URL = r'(?:6play:|https?://(?:www\.)?(?P<domain>6play\.fr|rtlplay\.be|play\.rtl\.hr|rtlmost\.hu)/.+?-c_)(?P<id>[0-9]+)'
14 _TESTS = [{
15 'url': 'https://www.6play.fr/minute-par-minute-p_9533/le-but-qui-a-marque-lhistoire-du-football-francais-c_12041051',
16 'md5': '31fcd112637baa0c2ab92c4fcd8baf27',
17 'info_dict': {
18 'id': '12041051',
19 'ext': 'mp4',
20 'title': 'Le but qui a marqué l\'histoire du football français !',
21 'description': 'md5:b59e7e841d646ef1eb42a7868eb6a851',
23 }, {
24 'url': 'https://www.rtlplay.be/rtl-info-13h-p_8551/les-titres-du-rtlinfo-13h-c_12045869',
25 'only_matching': True,
26 }, {
27 'url': 'https://play.rtl.hr/pj-masks-p_9455/epizoda-34-sezona-1-catboyevo-cudo-na-dva-kotaca-c_11984989',
28 'only_matching': True,
29 }, {
30 'url': 'https://www.rtlmost.hu/megtorve-p_14167/megtorve-6-resz-c_12397787',
31 'only_matching': True,
34 def _real_extract(self, url):
35 domain, video_id = self._match_valid_url(url).groups()
36 service, consumer_name = {
37 '6play.fr': ('6play', 'm6web'),
38 'rtlplay.be': ('rtlbe_rtl_play', 'rtlbe'),
39 'play.rtl.hr': ('rtlhr_rtl_play', 'rtlhr'),
40 'rtlmost.hu': ('rtlhu_rtl_most', 'rtlhu'),
41 }.get(domain, ('6play', 'm6web'))
43 data = self._download_json(
44 f'https://pc.middleware.6play.fr/6play/v2/platforms/m6group_web/services/{service}/videos/clip_{video_id}',
45 video_id, headers={
46 'x-customer-name': consumer_name,
47 }, query={
48 'csa': 5,
49 'with': 'clips',
52 clip_data = data['clips'][0]
53 title = clip_data['title']
55 urls = []
56 quality_key = qualities(['lq', 'sd', 'hq', 'hd'])
57 formats = []
58 subtitles = {}
59 assets = clip_data.get('assets') or []
60 for asset in assets:
61 asset_url = asset.get('full_physical_path')
62 protocol = asset.get('protocol')
63 if not asset_url or ((protocol == 'primetime' or asset.get('type') == 'usp_hlsfp_h264') and not ('_drmnp.ism/' in asset_url or '_unpnp.ism/' in asset_url)) or asset_url in urls:
64 continue
65 urls.append(asset_url)
66 container = asset.get('video_container')
67 ext = determine_ext(asset_url)
68 if protocol == 'http_subtitle' or ext == 'vtt':
69 subtitles.setdefault('fr', []).append({'url': asset_url})
70 continue
71 if container == 'm3u8' or ext == 'm3u8':
72 if protocol == 'usp':
73 if parse_qs(asset_url).get('token', [None])[0]:
74 urlh = self._request_webpage(
75 asset_url, video_id, fatal=False,
76 headers=self.geo_verification_headers())
77 if not urlh:
78 continue
79 asset_url = urlh.url
80 asset_url = asset_url.replace('_drmnp.ism/', '_unpnp.ism/')
81 for i in range(3, 0, -1):
82 asset_url = asset_url.replace('_sd1/', f'_sd{i}/')
83 m3u8_formats = self._extract_m3u8_formats(
84 asset_url, video_id, 'mp4', 'm3u8_native',
85 m3u8_id='hls', fatal=False)
86 formats.extend(m3u8_formats)
87 formats.extend(self._extract_mpd_formats(
88 asset_url.replace('.m3u8', '.mpd'),
89 video_id, mpd_id='dash', fatal=False))
90 if m3u8_formats:
91 break
92 else:
93 formats.extend(self._extract_m3u8_formats(
94 asset_url, video_id, 'mp4', 'm3u8_native',
95 m3u8_id='hls', fatal=False))
96 elif container == 'mp4' or ext == 'mp4':
97 quality = asset.get('video_quality')
98 formats.append({
99 'url': asset_url,
100 'format_id': quality,
101 'quality': quality_key(quality),
102 'ext': ext,
105 def get(getter):
106 for src in (data, clip_data):
107 v = try_get(src, getter, str)
108 if v:
109 return v
111 return {
112 'id': video_id,
113 'title': title,
114 'description': get(lambda x: x['description']),
115 'duration': int_or_none(clip_data.get('duration')),
116 'series': get(lambda x: x['program']['title']),
117 'formats': formats,
118 'subtitles': subtitles,