]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/whowatch.py
1 from .common
import InfoExtractor
9 from ..compat
import compat_str
12 class WhoWatchIE(InfoExtractor
):
14 _VALID_URL
= r
'https?://whowatch\.tv/viewer/(?P<id>\d+)'
17 'url': 'https://whowatch.tv/viewer/21450171',
18 'only_matching': True,
21 def _real_extract(self
, url
):
22 video_id
= self
._match
_id
(url
)
23 self
._download
_webpage
(url
, video_id
)
24 metadata
= self
._download
_json
('https://api.whowatch.tv/lives/%s' % video_id
, video_id
)
25 live_data
= self
._download
_json
('https://api.whowatch.tv/lives/%s/play' % video_id
, video_id
)
28 lambda: live_data
['share_info']['live_title'][1:-1],
29 lambda: metadata
['live']['title'],
32 hls_url
= live_data
.get('hls_url')
34 raise ExtractorError(live_data
.get('error_message') or 'The user is offline.', expected
=True)
36 QUALITIES
= qualities(['low', 'medium', 'high', 'veryhigh'])
39 for i
, fmt
in enumerate(live_data
.get('streams') or []):
40 name
= fmt
.get('quality') or fmt
.get('name') or compat_str(i
)
41 hls_url
= fmt
.get('hls_url')
42 rtmp_url
= fmt
.get('rtmp_url')
43 audio_only
= fmt
.get('audio_only')
44 quality
= QUALITIES(fmt
.get('quality'))
47 hls_fmts
= self
._extract
_m
3u8_formats
(
48 hls_url
, video_id
, ext
='mp4', m3u8_id
='hls-%s' % name
, quality
=quality
)
49 formats
.extend(hls_fmts
)
53 # RTMP url for audio_only is same as high format, so skip it
54 if rtmp_url
and not audio_only
:
57 'format_id': 'rtmp-%s' % name
,
59 'protocol': 'rtmp_ffmpeg', # ffmpeg can, while rtmpdump can't
63 'format_note': fmt
.get('label'),
64 # note: HLS and RTMP have same resolution for now, so it's acceptable
65 'width': try_get(hls_fmts
, lambda x
: x
[0]['width'], int),
66 'height': try_get(hls_fmts
, lambda x
: x
[0]['height'], int),
69 # This contains the same formats as the above manifests and is used only as a fallback
70 formats
.extend(self
._extract
_m
3u8_formats
(
71 hls_url
, video_id
, ext
='mp4', m3u8_id
='hls'))
72 self
._remove
_duplicate
_formats
(formats
)
74 uploader_url
= try_get(metadata
, lambda x
: x
['live']['user']['user_path'], compat_str
)
76 uploader_url
= 'https://whowatch.tv/profile/%s' % uploader_url
77 uploader_id
= compat_str(try_get(metadata
, lambda x
: x
['live']['user']['id'], int))
78 uploader
= try_get(metadata
, lambda x
: x
['live']['user']['name'], compat_str
)
79 thumbnail
= try_get(metadata
, lambda x
: x
['live']['latest_thumbnail_url'], compat_str
)
80 timestamp
= int_or_none(try_get(metadata
, lambda x
: x
['live']['started_at'], int), scale
=1000)
81 view_count
= try_get(metadata
, lambda x
: x
['live']['total_view_count'], int)
82 comment_count
= try_get(metadata
, lambda x
: x
['live']['comment_count'], int)
87 'uploader_id': uploader_id
,
88 'uploader_url': uploader_url
,
91 'thumbnail': thumbnail
,
92 'timestamp': timestamp
,
93 'view_count': view_count
,
94 'comment_count': comment_count
,