]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/whowatch.py
2 from __future__
import unicode_literals
4 from .common
import InfoExtractor
12 from ..compat
import compat_str
15 class WhoWatchIE(InfoExtractor
):
17 _VALID_URL
= r
'https?://whowatch\.tv/viewer/(?P<id>\d+)'
20 'url': 'https://whowatch.tv/viewer/21450171',
21 'only_matching': True,
24 def _real_extract(self
, url
):
25 video_id
= self
._match
_id
(url
)
26 self
._download
_webpage
(url
, video_id
)
27 metadata
= self
._download
_json
('https://api.whowatch.tv/lives/%s' % video_id
, video_id
)
28 live_data
= self
._download
_json
('https://api.whowatch.tv/lives/%s/play' % video_id
, video_id
)
31 lambda: live_data
['share_info']['live_title'][1:-1],
32 lambda: metadata
['live']['title'],
35 hls_url
= live_data
.get('hls_url')
37 raise ExtractorError(live_data
.get('error_message') or 'The user is offline.', expected
=True)
39 QUALITIES
= qualities(['low', 'medium', 'high', 'veryhigh'])
42 for i
, fmt
in enumerate(live_data
.get('streams') or []):
43 name
= fmt
.get('quality') or fmt
.get('name') or compat_str(i
)
44 hls_url
= fmt
.get('hls_url')
45 rtmp_url
= fmt
.get('rtmp_url')
46 audio_only
= fmt
.get('audio_only')
47 quality
= QUALITIES(fmt
.get('quality'))
50 hls_fmts
= self
._extract
_m
3u8_formats
(
51 hls_url
, video_id
, ext
='mp4', m3u8_id
='hls-%s' % name
, quality
=quality
)
52 formats
.extend(hls_fmts
)
56 # RTMP url for audio_only is same as high format, so skip it
57 if rtmp_url
and not audio_only
:
60 'format_id': 'rtmp-%s' % name
,
62 'protocol': 'rtmp_ffmpeg', # ffmpeg can, while rtmpdump can't
66 'format_note': fmt
.get('label'),
67 # note: HLS and RTMP have same resolution for now, so it's acceptable
68 'width': try_get(hls_fmts
, lambda x
: x
[0]['width'], int),
69 'height': try_get(hls_fmts
, lambda x
: x
[0]['height'], int),
72 # This contains the same formats as the above manifests and is used only as a fallback
73 formats
.extend(self
._extract
_m
3u8_formats
(
74 hls_url
, video_id
, ext
='mp4', m3u8_id
='hls'))
75 self
._remove
_duplicate
_formats
(formats
)
76 self
._sort
_formats
(formats
)
78 uploader_url
= try_get(metadata
, lambda x
: x
['live']['user']['user_path'], compat_str
)
80 uploader_url
= 'https://whowatch.tv/profile/%s' % uploader_url
81 uploader_id
= compat_str(try_get(metadata
, lambda x
: x
['live']['user']['id'], int))
82 uploader
= try_get(metadata
, lambda x
: x
['live']['user']['name'], compat_str
)
83 thumbnail
= try_get(metadata
, lambda x
: x
['live']['latest_thumbnail_url'], compat_str
)
84 timestamp
= int_or_none(try_get(metadata
, lambda x
: x
['live']['started_at'], int), scale
=1000)
85 view_count
= try_get(metadata
, lambda x
: x
['live']['total_view_count'], int)
86 comment_count
= try_get(metadata
, lambda x
: x
['live']['comment_count'], int)
91 'uploader_id': uploader_id
,
92 'uploader_url': uploader_url
,
95 'thumbnail': thumbnail
,
96 'timestamp': timestamp
,
97 'view_count': view_count
,
98 'comment_count': comment_count
,