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