1 from .common
import InfoExtractor
11 class WhoWatchIE(InfoExtractor
):
13 _VALID_URL
= r
'https?://whowatch\.tv/viewer/(?P<id>\d+)'
16 'url': 'https://whowatch.tv/viewer/21450171',
17 'only_matching': True,
20 def _real_extract(self
, url
):
21 video_id
= self
._match
_id
(url
)
22 self
._download
_webpage
(url
, video_id
)
23 metadata
= self
._download
_json
(f
'https://api.whowatch.tv/lives/{video_id}', video_id
)
24 live_data
= self
._download
_json
(f
'https://api.whowatch.tv/lives/{video_id}/play', video_id
)
27 lambda: live_data
['share_info']['live_title'][1:-1],
28 lambda: metadata
['live']['title'],
31 hls_url
= live_data
.get('hls_url')
33 raise ExtractorError(live_data
.get('error_message') or 'The user is offline.', expected
=True)
35 QUALITIES
= qualities(['low', 'medium', 'high', 'veryhigh'])
38 for i
, fmt
in enumerate(live_data
.get('streams') or []):
39 name
= fmt
.get('quality') or fmt
.get('name') or str(i
)
40 hls_url
= fmt
.get('hls_url')
41 rtmp_url
= fmt
.get('rtmp_url')
42 audio_only
= fmt
.get('audio_only')
43 quality
= QUALITIES(fmt
.get('quality'))
46 hls_fmts
= self
._extract
_m
3u8_formats
(
47 hls_url
, video_id
, ext
='mp4', m3u8_id
=f
'hls-{name}', quality
=quality
)
48 formats
.extend(hls_fmts
)
52 # RTMP url for audio_only is same as high format, so skip it
53 if rtmp_url
and not audio_only
:
56 'format_id': f
'rtmp-{name}',
58 'protocol': 'rtmp_ffmpeg', # ffmpeg can, while rtmpdump can't
62 'format_note': fmt
.get('label'),
63 # note: HLS and RTMP have same resolution for now, so it's acceptable
64 'width': try_get(hls_fmts
, lambda x
: x
[0]['width'], int),
65 'height': try_get(hls_fmts
, lambda x
: x
[0]['height'], int),
68 # This contains the same formats as the above manifests and is used only as a fallback
69 formats
.extend(self
._extract
_m
3u8_formats
(
70 hls_url
, video_id
, ext
='mp4', m3u8_id
='hls'))
71 self
._remove
_duplicate
_formats
(formats
)
73 uploader_url
= try_get(metadata
, lambda x
: x
['live']['user']['user_path'], str)
75 uploader_url
= f
'https://whowatch.tv/profile/{uploader_url}'
76 uploader_id
= str(try_get(metadata
, lambda x
: x
['live']['user']['id'], int))
77 uploader
= try_get(metadata
, lambda x
: x
['live']['user']['name'], str)
78 thumbnail
= try_get(metadata
, lambda x
: x
['live']['latest_thumbnail_url'], str)
79 timestamp
= int_or_none(try_get(metadata
, lambda x
: x
['live']['started_at'], int), scale
=1000)
80 view_count
= try_get(metadata
, lambda x
: x
['live']['total_view_count'], int)
81 comment_count
= try_get(metadata
, lambda x
: x
['live']['comment_count'], int)
86 'uploader_id': uploader_id
,
87 'uploader_url': uploader_url
,
90 'thumbnail': thumbnail
,
91 'timestamp': timestamp
,
92 'view_count': view_count
,
93 'comment_count': comment_count
,