[ie/niconico] Fix extractor (#10677)

Closes #10662
Authored by: bashonly
This commit is contained in:
bashonly 2024-08-05 21:50:06 -05:00 committed by GitHub
parent fc5eecfa31
commit 4d92312083
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -40,7 +40,6 @@ class NiconicoIE(InfoExtractor):
_TESTS = [{ _TESTS = [{
'url': 'http://www.nicovideo.jp/watch/sm22312215', 'url': 'http://www.nicovideo.jp/watch/sm22312215',
'md5': 'd1a75c0823e2f629128c43e1212760f9',
'info_dict': { 'info_dict': {
'id': 'sm22312215', 'id': 'sm22312215',
'ext': 'mp4', 'ext': 'mp4',
@ -56,8 +55,8 @@ class NiconicoIE(InfoExtractor):
'comment_count': int, 'comment_count': int,
'genres': ['未設定'], 'genres': ['未設定'],
'tags': [], 'tags': [],
'expected_protocol': str,
}, },
'params': {'skip_download': 'm3u8'},
}, { }, {
# File downloaded with and without credentials are different, so omit # File downloaded with and without credentials are different, so omit
# the md5 field # the md5 field
@ -77,8 +76,8 @@ class NiconicoIE(InfoExtractor):
'view_count': int, 'view_count': int,
'genres': ['音楽・サウンド'], 'genres': ['音楽・サウンド'],
'tags': ['Translation_Request', 'Kagamine_Rin', 'Rin_Original'], 'tags': ['Translation_Request', 'Kagamine_Rin', 'Rin_Original'],
'expected_protocol': str,
}, },
'params': {'skip_download': 'm3u8'},
}, { }, {
# 'video exists but is marked as "deleted" # 'video exists but is marked as "deleted"
# md5 is unstable # md5 is unstable
@ -112,7 +111,6 @@ class NiconicoIE(InfoExtractor):
}, { }, {
# video not available via `getflv`; "old" HTML5 video # video not available via `getflv`; "old" HTML5 video
'url': 'http://www.nicovideo.jp/watch/sm1151009', 'url': 'http://www.nicovideo.jp/watch/sm1151009',
'md5': 'f95a3d259172667b293530cc2e41ebda',
'info_dict': { 'info_dict': {
'id': 'sm1151009', 'id': 'sm1151009',
'ext': 'mp4', 'ext': 'mp4',
@ -128,11 +126,10 @@ class NiconicoIE(InfoExtractor):
'comment_count': int, 'comment_count': int,
'genres': ['ゲーム'], 'genres': ['ゲーム'],
'tags': [], 'tags': [],
'expected_protocol': str,
}, },
'params': {'skip_download': 'm3u8'},
}, { }, {
# "New" HTML5 video # "New" HTML5 video
# md5 is unstable
'url': 'http://www.nicovideo.jp/watch/sm31464864', 'url': 'http://www.nicovideo.jp/watch/sm31464864',
'info_dict': { 'info_dict': {
'id': 'sm31464864', 'id': 'sm31464864',
@ -149,12 +146,11 @@ class NiconicoIE(InfoExtractor):
'comment_count': int, 'comment_count': int,
'genres': ['アニメ'], 'genres': ['アニメ'],
'tags': [], 'tags': [],
'expected_protocol': str,
}, },
'params': {'skip_download': 'm3u8'},
}, { }, {
# Video without owner # Video without owner
'url': 'http://www.nicovideo.jp/watch/sm18238488', 'url': 'http://www.nicovideo.jp/watch/sm18238488',
'md5': 'd265680a1f92bdcbbd2a507fc9e78a9e',
'info_dict': { 'info_dict': {
'id': 'sm18238488', 'id': 'sm18238488',
'ext': 'mp4', 'ext': 'mp4',
@ -168,8 +164,8 @@ class NiconicoIE(InfoExtractor):
'comment_count': int, 'comment_count': int,
'genres': ['エンターテイメント'], 'genres': ['エンターテイメント'],
'tags': [], 'tags': [],
'expected_protocol': str,
}, },
'params': {'skip_download': 'm3u8'},
}, { }, {
'url': 'http://sp.nicovideo.jp/watch/sm28964488?ss_pos=1&cp_in=wt_tg', 'url': 'http://sp.nicovideo.jp/watch/sm28964488?ss_pos=1&cp_in=wt_tg',
'only_matching': True, 'only_matching': True,
@ -458,9 +454,11 @@ class NiconicoIE(InfoExtractor):
if video_id.startswith('so'): if video_id.startswith('so'):
video_id = self._match_id(handle.url) video_id = self._match_id(handle.url)
api_data = self._parse_json(self._html_search_regex( api_data = traverse_obj(
'data-api-data="([^"]+)"', webpage, self._parse_json(self._html_search_meta('server-response', webpage) or '', video_id),
'API data', default='{}'), video_id) ('data', 'response', {dict}))
if not api_data:
raise ExtractorError('Server response data not found')
except ExtractorError as e: except ExtractorError as e:
try: try:
api_data = self._download_json( api_data = self._download_json(