]> jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/sixplay.py
[6play] Fix extraction (closes #12011)
[yt-dlp.git] / youtube_dl / extractor / sixplay.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..compat import compat_str
6 from ..utils import (
7 determine_ext,
8 int_or_none,
9 try_get,
10 qualities,
11 )
12
13
14 class SixPlayIE(InfoExtractor):
15 _VALID_URL = r'(?:6play:|https?://(?:www\.)?6play\.fr/.+?-c_)(?P<id>[0-9]+)'
16 _TEST = {
17 'url': 'http://www.6play.fr/le-meilleur-patissier-p_1807/le-meilleur-patissier-special-fetes-mercredi-a-21-00-sur-m6-c_11638450',
18 'md5': '42310bffe4ba3982db112b9cd3467328',
19 'info_dict': {
20 'id': '11638450',
21 'ext': 'mp4',
22 'title': 'Le Meilleur Pâtissier, spécial fêtes mercredi à 21:00 sur M6',
23 'description': 'md5:308853f6a5f9e2d55a30fc0654de415f',
24 'duration': 39,
25 'series': 'Le meilleur pâtissier',
26 },
27 'params': {
28 'skip_download': True,
29 },
30 }
31
32 def _real_extract(self, url):
33 video_id = self._match_id(url)
34
35 data = self._download_json(
36 'https://pc.middleware.6play.fr/6play/v2/platforms/m6group_web/services/6play/videos/clip_%s' % video_id,
37 video_id, query={
38 'csa': 5,
39 'with': 'clips',
40 })
41
42 clip_data = data['clips'][0]
43 title = clip_data['title']
44
45 quality_key = qualities(['lq', 'sd', 'hq', 'hd'])
46 formats = []
47 for asset in clip_data['assets']:
48 asset_url = asset.get('full_physical_path')
49 if not asset_url:
50 continue
51 container = asset.get('video_container')
52 ext = determine_ext(asset_url)
53 if container == 'm3u8' or ext == 'm3u8':
54 formats.extend(self._extract_m3u8_formats(
55 asset_url, video_id, 'mp4', 'm3u8_native',
56 m3u8_id='hls', fatal=False))
57 formats.extend(self._extract_f4m_formats(
58 asset_url.replace('.m3u8', '.f4m'),
59 video_id, f4m_id='hds', fatal=False))
60 elif container == 'mp4' or ext == 'mp4':
61 quality = asset.get('video_quality')
62 formats.append({
63 'url': asset_url,
64 'format_id': quality,
65 'quality': quality_key(quality),
66 'ext': ext,
67 })
68 self._sort_formats(formats)
69
70 def get(getter):
71 for src in (data, clip_data):
72 v = try_get(src, getter, compat_str)
73 if v:
74 return v
75
76 return {
77 'id': video_id,
78 'title': title,
79 'description': get(lambda x: x['description']),
80 'duration': int_or_none(clip_data.get('duration')),
81 'series': get(lambda x: x['program']['title']),
82 'formats': formats,
83 }