Closes #9351
Authored by: pzhlkj6612
This commit is contained in:
Mozi 2024-03-03 23:14:54 +00:00 committed by GitHub
parent eedb38ce40
commit 40966e8da2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 23 additions and 9 deletions

View File

@ -36,6 +36,8 @@ from ..utils import (
class NiconicoIE(InfoExtractor): class NiconicoIE(InfoExtractor):
IE_NAME = 'niconico' IE_NAME = 'niconico'
IE_DESC = 'ニコニコ動画' IE_DESC = 'ニコニコ動画'
_GEO_COUNTRIES = ['JP']
_GEO_BYPASS = False
_TESTS = [{ _TESTS = [{
'url': 'http://www.nicovideo.jp/watch/sm22312215', 'url': 'http://www.nicovideo.jp/watch/sm22312215',
@ -478,15 +480,27 @@ class NiconicoIE(InfoExtractor):
raise raise
raise ExtractorError(clean_html(error_msg), expected=True) raise ExtractorError(clean_html(error_msg), expected=True)
club_joined = traverse_obj(api_data, ('channel', 'viewer', 'follow', 'isFollowed', {bool})) availability = self._availability(**(traverse_obj(api_data, ('payment', 'video', {
if club_joined is None: 'needs_premium': ('isPremium', {bool}),
fail_msg = self._html_search_regex( 'needs_subscription': ('isAdmission', {bool}),
})) or {'needs_auth': True}))
formats = [*self._yield_dmc_formats(api_data, video_id),
*self._yield_dms_formats(api_data, video_id)]
if not formats:
fail_msg = clean_html(self._html_search_regex(
r'<p[^>]+\bclass="fail-message"[^>]*>(?P<msg>.+?)</p>', r'<p[^>]+\bclass="fail-message"[^>]*>(?P<msg>.+?)</p>',
webpage, 'fail message', default=None, group='msg') webpage, 'fail message', default=None, group='msg'))
if fail_msg: if fail_msg:
self.raise_login_required(clean_html(fail_msg), metadata_available=True) self.to_screen(f'Niconico said: {fail_msg}')
elif not club_joined: if fail_msg and 'された地域と同じ地域からのみ視聴できます。' in fail_msg:
availability = None
self.raise_geo_restricted(countries=self._GEO_COUNTRIES, metadata_available=True)
elif availability == 'premium_only':
self.raise_login_required('This video requires premium', metadata_available=True)
elif availability == 'subscriber_only':
self.raise_login_required('This video is for members only', metadata_available=True) self.raise_login_required('This video is for members only', metadata_available=True)
elif availability == 'needs_auth':
self.raise_login_required(metadata_available=False)
# Start extracting information # Start extracting information
tags = None tags = None
@ -512,8 +526,8 @@ class NiconicoIE(InfoExtractor):
'id': video_id, 'id': video_id,
'_api_data': api_data, '_api_data': api_data,
'title': get_video_info(('originalTitle', 'title')) or self._og_search_title(webpage, default=None), 'title': get_video_info(('originalTitle', 'title')) or self._og_search_title(webpage, default=None),
'formats': [*self._yield_dmc_formats(api_data, video_id), 'formats': formats,
*self._yield_dms_formats(api_data, video_id)], 'availability': availability,
'thumbnails': [{ 'thumbnails': [{
'id': key, 'id': key,
'url': url, 'url': url,