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