]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/playwire.py
ab7f71493fd01550f447701e568240d10e893e26
[yt-dlp.git] / yt_dlp / extractor / playwire.py
1 from .common import InfoExtractor
2 from ..utils import (
3 dict_get,
4 float_or_none,
5 )
6
7
8 class PlaywireIE(InfoExtractor):
9 _VALID_URL = r'https?://(?:config|cdn)\.playwire\.com(?:/v2)?/(?P<publisher_id>\d+)/(?:videos/v2|embed|config)/(?P<id>\d+)'
10 _TESTS = [{
11 'url': 'http://config.playwire.com/14907/videos/v2/3353705/player.json',
12 'md5': 'e6398701e3595888125729eaa2329ed9',
13 'info_dict': {
14 'id': '3353705',
15 'ext': 'mp4',
16 'title': 'S04_RM_UCL_Rus',
17 'thumbnail': r're:^https?://.*\.png$',
18 'duration': 145.94,
19 },
20 }, {
21 # m3u8 in f4m
22 'url': 'http://config.playwire.com/21772/videos/v2/4840492/zeus.json',
23 'info_dict': {
24 'id': '4840492',
25 'ext': 'mp4',
26 'title': 'ITV EL SHOW FULL',
27 },
28 'params': {
29 # m3u8 download
30 'skip_download': True,
31 },
32 }, {
33 # Multiple resolutions while bitrates missing
34 'url': 'http://cdn.playwire.com/11625/embed/85228.html',
35 'only_matching': True,
36 }, {
37 'url': 'http://config.playwire.com/12421/videos/v2/3389892/zeus.json',
38 'only_matching': True,
39 }, {
40 'url': 'http://cdn.playwire.com/v2/12342/config/1532636.json',
41 'only_matching': True,
42 }]
43
44 def _real_extract(self, url):
45 mobj = self._match_valid_url(url)
46 publisher_id, video_id = mobj.group('publisher_id'), mobj.group('id')
47
48 player = self._download_json(
49 'http://config.playwire.com/%s/videos/v2/%s/zeus.json' % (publisher_id, video_id),
50 video_id)
51
52 title = player['settings']['title']
53 duration = float_or_none(player.get('duration'), 1000)
54
55 content = player['content']
56 thumbnail = content.get('poster')
57 src = content['media']['f4m']
58
59 formats = self._extract_f4m_formats(src, video_id, m3u8_id='hls')
60 for a_format in formats:
61 if not dict_get(a_format, ['tbr', 'width', 'height']):
62 a_format['quality'] = 1 if '-hd.' in a_format['url'] else 0
63 self._sort_formats(formats)
64
65 return {
66 'id': video_id,
67 'title': title,
68 'thumbnail': thumbnail,
69 'duration': duration,
70 'formats': formats,
71 }