mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-06-28 09:28:33 +00:00
Apply suggestions from code review
This commit is contained in:
parent
30c4364c19
commit
7ca024bc35
@ -14,8 +14,8 @@ class NiconicoLiveFD(FileDownloader):
|
|||||||
|
|
||||||
def real_download(self, filename, info_dict):
|
def real_download(self, filename, info_dict):
|
||||||
video_id = info_dict['id']
|
video_id = info_dict['id']
|
||||||
quality, ws_extractor, ws_url = map(
|
opts = info_dict['downloader_options']
|
||||||
info_dict['downloader_options'].get, ('max_quality', 'ws', 'ws_url'))
|
quality, ws_extractor, ws_url = opts['max_quality'], opts['ws'], opts['ws_url']
|
||||||
dl = FFmpegFD(self.ydl, self.params or {})
|
dl = FFmpegFD(self.ydl, self.params or {})
|
||||||
|
|
||||||
new_info_dict = info_dict.copy()
|
new_info_dict = info_dict.copy()
|
||||||
@ -76,7 +76,7 @@ def ws_main():
|
|||||||
return
|
return
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
self.to_screen(
|
self.to_screen(
|
||||||
f'[niconico:live] {video_id}: Connection error occured, reconnecting after 10 seconds: {str_or_none(e)}')
|
f'[niconico:live] {video_id}: Connection error occured, reconnecting after 10 seconds: {e}')
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
continue
|
continue
|
||||||
finally:
|
finally:
|
||||||
|
@ -754,7 +754,6 @@ def _real_extract(self, url):
|
|||||||
class NiconicoLiveIE(NiconicoBaseIE):
|
class NiconicoLiveIE(NiconicoBaseIE):
|
||||||
IE_NAME = 'niconico:live'
|
IE_NAME = 'niconico:live'
|
||||||
IE_DESC = 'ニコニコ生放送'
|
IE_DESC = 'ニコニコ生放送'
|
||||||
|
|
||||||
_VALID_URL = r'https?://(?:sp\.)?live2?\.nicovideo\.jp/(?:watch|gate)/(?P<id>lv\d+)'
|
_VALID_URL = r'https?://(?:sp\.)?live2?\.nicovideo\.jp/(?:watch|gate)/(?P<id>lv\d+)'
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
'note': 'this test case includes invisible characters for title, pasting them as-is',
|
'note': 'this test case includes invisible characters for title, pasting them as-is',
|
||||||
@ -787,17 +786,13 @@ class NiconicoLiveIE(NiconicoBaseIE):
|
|||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
video_id = self._match_id(url)
|
video_id = self._match_id(url)
|
||||||
webpage = self._download_webpage(url, video_id, expected_status=404)
|
webpage = self._download_webpage(url, video_id, expected_status=404)
|
||||||
if err_msg := traverse_obj(webpage, (
|
if err_msg := traverse_obj(webpage, ({find_element(cls='message')}, {clean_html})):
|
||||||
{find_element(cls='message')}, {clean_html},
|
|
||||||
)):
|
|
||||||
raise ExtractorError(err_msg, expected=True)
|
raise ExtractorError(err_msg, expected=True)
|
||||||
|
|
||||||
embedded_data = traverse_obj(webpage, (
|
embedded_data = traverse_obj(webpage, (
|
||||||
{find_element(tag='script', id='embedded-data', html=True)},
|
{find_element(tag='script', id='embedded-data', html=True)},
|
||||||
{extract_attributes}, 'data-props', {json.loads},
|
{extract_attributes}, 'data-props', {json.loads}))
|
||||||
))
|
frontend_id = traverse_obj(embedded_data, ('site', 'frontendId', {str_or_none}), default='9')
|
||||||
frontend_id = traverse_obj(embedded_data, (
|
|
||||||
'site', 'frontendId', {str_or_none}), default='9')
|
|
||||||
|
|
||||||
if not (ws_url := traverse_obj(embedded_data, (
|
if not (ws_url := traverse_obj(embedded_data, (
|
||||||
'site', 'relive', 'webSocketUrl', {url_or_none},
|
'site', 'relive', 'webSocketUrl', {url_or_none},
|
||||||
@ -853,7 +848,7 @@ def _real_extract(self, url):
|
|||||||
title = traverse_obj(embedded_data, ('program', 'title')) or self._html_search_meta(
|
title = traverse_obj(embedded_data, ('program', 'title')) or self._html_search_meta(
|
||||||
('og:title', 'twitter:title'), webpage, 'live title', fatal=False)
|
('og:title', 'twitter:title'), webpage, 'live title', fatal=False)
|
||||||
|
|
||||||
raw_thumbs = traverse_obj(embedded_data, ('program', 'thumbnail', {dict}), default={})
|
raw_thumbs = traverse_obj(embedded_data, ('program', 'thumbnail', {dict})) or {}
|
||||||
thumbnails = []
|
thumbnails = []
|
||||||
for name, value in raw_thumbs.items():
|
for name, value in raw_thumbs.items():
|
||||||
if not isinstance(value, dict):
|
if not isinstance(value, dict):
|
||||||
|
Loading…
Reference in New Issue
Block a user