mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-05-21 17:55:44 -05:00
parent
d880e06080
commit
7a7b85c901
1 changed files with 25 additions and 19 deletions
|
@ -16,6 +16,7 @@
|
||||||
determine_ext,
|
determine_ext,
|
||||||
float_or_none,
|
float_or_none,
|
||||||
int_or_none,
|
int_or_none,
|
||||||
|
parse_bitrate,
|
||||||
parse_duration,
|
parse_duration,
|
||||||
parse_iso8601,
|
parse_iso8601,
|
||||||
parse_qs,
|
parse_qs,
|
||||||
|
@ -23,7 +24,6 @@
|
||||||
qualities,
|
qualities,
|
||||||
remove_start,
|
remove_start,
|
||||||
str_or_none,
|
str_or_none,
|
||||||
try_get,
|
|
||||||
unescapeHTML,
|
unescapeHTML,
|
||||||
unified_timestamp,
|
unified_timestamp,
|
||||||
update_url_query,
|
update_url_query,
|
||||||
|
@ -785,8 +785,6 @@ class NiconicoLiveIE(NiconicoBaseIE):
|
||||||
'only_matching': True,
|
'only_matching': True,
|
||||||
}]
|
}]
|
||||||
|
|
||||||
_KNOWN_LATENCY = ('high', 'low')
|
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
video_id = self._match_id(url)
|
video_id = self._match_id(url)
|
||||||
webpage, urlh = self._download_webpage_handle(f'https://live.nicovideo.jp/watch/{video_id}', video_id)
|
webpage, urlh = self._download_webpage_handle(f'https://live.nicovideo.jp/watch/{video_id}', video_id)
|
||||||
|
@ -802,22 +800,19 @@ def _real_extract(self, url):
|
||||||
})
|
})
|
||||||
|
|
||||||
hostname = remove_start(urllib.parse.urlparse(urlh.url).hostname, 'sp.')
|
hostname = remove_start(urllib.parse.urlparse(urlh.url).hostname, 'sp.')
|
||||||
latency = try_get(self._configuration_arg('latency'), lambda x: x[0])
|
|
||||||
if latency not in self._KNOWN_LATENCY:
|
|
||||||
latency = 'high'
|
|
||||||
|
|
||||||
ws = self._request_webpage(
|
ws = self._request_webpage(
|
||||||
Request(ws_url, headers={'Origin': f'https://{hostname}'}),
|
Request(ws_url, headers={'Origin': f'https://{hostname}'}),
|
||||||
video_id=video_id, note='Connecting to WebSocket server')
|
video_id=video_id, note='Connecting to WebSocket server')
|
||||||
|
|
||||||
self.write_debug('[debug] Sending HLS server request')
|
self.write_debug('Sending HLS server request')
|
||||||
ws.send(json.dumps({
|
ws.send(json.dumps({
|
||||||
'type': 'startWatching',
|
'type': 'startWatching',
|
||||||
'data': {
|
'data': {
|
||||||
'stream': {
|
'stream': {
|
||||||
'quality': 'abr',
|
'quality': 'abr',
|
||||||
'protocol': 'hls+fmp4',
|
'protocol': 'hls',
|
||||||
'latency': latency,
|
'latency': 'high',
|
||||||
'accessRightMethod': 'single_cookie',
|
'accessRightMethod': 'single_cookie',
|
||||||
'chasePlay': False,
|
'chasePlay': False,
|
||||||
},
|
},
|
||||||
|
@ -881,18 +876,29 @@ def _real_extract(self, url):
|
||||||
for cookie in cookies:
|
for cookie in cookies:
|
||||||
self._set_cookie(
|
self._set_cookie(
|
||||||
cookie['domain'], cookie['name'], cookie['value'],
|
cookie['domain'], cookie['name'], cookie['value'],
|
||||||
expire_time=unified_timestamp(cookie['expires']), path=cookie['path'], secure=cookie['secure'])
|
expire_time=unified_timestamp(cookie.get('expires')), path=cookie['path'], secure=cookie['secure'])
|
||||||
|
|
||||||
|
fmt_common = {
|
||||||
|
'live_latency': 'high',
|
||||||
|
'origin': hostname,
|
||||||
|
'protocol': 'niconico_live',
|
||||||
|
'video_id': video_id,
|
||||||
|
'ws': ws,
|
||||||
|
}
|
||||||
|
q_iter = (q for q in qualities[1:] if not q.startswith('audio_')) # ignore initial 'abr'
|
||||||
|
a_map = {96: 'audio_low', 192: 'audio_high'}
|
||||||
|
|
||||||
formats = self._extract_m3u8_formats(m3u8_url, video_id, ext='mp4', live=True)
|
formats = self._extract_m3u8_formats(m3u8_url, video_id, ext='mp4', live=True)
|
||||||
for fmt, q in zip(formats, reversed(qualities[1:])):
|
for fmt in formats:
|
||||||
|
if fmt.get('acodec') == 'none':
|
||||||
|
fmt['format_id'] = next(q_iter, fmt['format_id'])
|
||||||
|
elif fmt.get('vcodec') == 'none':
|
||||||
|
abr = parse_bitrate(fmt['url'].lower())
|
||||||
fmt.update({
|
fmt.update({
|
||||||
'format_id': q,
|
'abr': abr,
|
||||||
'protocol': 'niconico_live',
|
'format_id': a_map.get(abr, fmt['format_id']),
|
||||||
'ws': ws,
|
|
||||||
'video_id': video_id,
|
|
||||||
'live_latency': latency,
|
|
||||||
'origin': hostname,
|
|
||||||
})
|
})
|
||||||
|
fmt.update(fmt_common)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
|
|
Loading…
Reference in a new issue