mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-06-27 08:58:30 +00:00
[ie/niconico:live] Age restriction support
This commit is contained in:
parent
06c1a8cdff
commit
30ca78d666
@ -779,39 +779,64 @@ class NiconicoLiveIE(NiconicoBaseIE):
|
|||||||
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',
|
'url': 'https://live.nicovideo.jp/watch/lv329299587',
|
||||||
'url': 'https://live.nicovideo.jp/watch/lv339533123',
|
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': 'lv339533123',
|
'id': 'lv329299587',
|
||||||
'title': '激辛ペヤング食べます\u202a( ;ᯅ; )\u202c(歌枠オーディション参加中)',
|
'ext': 'mp4',
|
||||||
'view_count': 1526,
|
'title': str,
|
||||||
'comment_count': 1772,
|
'channel': 'ニコニコエンタメチャンネル',
|
||||||
'description': '初めましてもかって言います❕\nのんびり自由に適当に暮らしてます',
|
'channel_id': 'ch2640322',
|
||||||
'uploader': 'もか',
|
'channel_url': 'https://ch.nicovideo.jp/channel/ch2640322',
|
||||||
'channel': 'ゲストさんのコミュニティ',
|
'comment_count': int,
|
||||||
'channel_id': 'co5776900',
|
'description': 'md5:281edd7f00309e99ec46a87fb16d7033',
|
||||||
'channel_url': 'https://com.nicovideo.jp/community/co5776900',
|
'live_status': 'is_live',
|
||||||
'timestamp': 1670677328,
|
'thumbnail': r're:https?://.+',
|
||||||
'is_live': True,
|
'timestamp': 1608803400,
|
||||||
|
'upload_date': '20201224',
|
||||||
|
'uploader': '株式会社ドワンゴ',
|
||||||
|
'view_count': int,
|
||||||
},
|
},
|
||||||
'skip': 'livestream',
|
'params': {'skip_download': True},
|
||||||
}, {
|
}, {
|
||||||
'url': 'https://live2.nicovideo.jp/watch/lv339533123',
|
'url': 'https://live.nicovideo.jp/watch/lv331050399',
|
||||||
'only_matching': True,
|
'info_dict': {
|
||||||
}, {
|
'id': 'lv331050399',
|
||||||
'url': 'https://sp.live.nicovideo.jp/watch/lv339533123',
|
'ext': 'mp4',
|
||||||
'only_matching': True,
|
'title': str,
|
||||||
}, {
|
'age_limit': 18,
|
||||||
'url': 'https://sp.live2.nicovideo.jp/watch/lv339533123',
|
'channel': 'みんなのおもちゃ REBOOT',
|
||||||
'only_matching': True,
|
'channel_id': 'ch2642088',
|
||||||
|
'channel_url': 'https://ch.nicovideo.jp/channel/ch2642088',
|
||||||
|
'comment_count': int,
|
||||||
|
'description': 'md5:8d0bb5beaca73b911725478a1e7c7b91',
|
||||||
|
'live_status': 'is_live',
|
||||||
|
'thumbnail': r're:https?://.+',
|
||||||
|
'timestamp': 1617029400,
|
||||||
|
'upload_date': '20210329',
|
||||||
|
'uploader': '株式会社ドワンゴ',
|
||||||
|
'view_count': int,
|
||||||
|
},
|
||||||
|
'params': {'skip_download': True},
|
||||||
}]
|
}]
|
||||||
|
|
||||||
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, urlh = self._download_webpage_handle(url, video_id, expected_status=404)
|
||||||
if err_msg := traverse_obj(webpage, ({find_element(cls='message')}, {clean_html})):
|
if err_msg := traverse_obj(webpage, ({find_element(cls='message')}, {clean_html})):
|
||||||
raise ExtractorError(err_msg, expected=True)
|
raise ExtractorError(err_msg, expected=True)
|
||||||
|
|
||||||
|
age_limit = 18 if 'age_auth' in urlh.url else None
|
||||||
|
if age_limit:
|
||||||
|
my = self._download_webpage('https://www.nicovideo.jp/my', None, 'Checking age verification')
|
||||||
|
if traverse_obj(my, (
|
||||||
|
{find_element(id='js-initial-userpage-data', html=True)}, {extract_attributes},
|
||||||
|
'data-environment', {json.loads}, 'allowSensitiveContents', {bool},
|
||||||
|
)):
|
||||||
|
self._set_cookie('.nicovideo.jp', 'age_auth', '1')
|
||||||
|
webpage = self._download_webpage(url, video_id)
|
||||||
|
else:
|
||||||
|
raise ExtractorError('Age restricted content', 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}))
|
||||||
@ -914,6 +939,7 @@ def _real_extract(self, url):
|
|||||||
return {
|
return {
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
'title': title,
|
'title': title,
|
||||||
|
'age_limit': age_limit,
|
||||||
'downloader_options': {
|
'downloader_options': {
|
||||||
'max_quality': traverse_obj(embedded_data, ('program', 'stream', 'maxQuality', {str})) or 'normal',
|
'max_quality': traverse_obj(embedded_data, ('program', 'stream', 'maxQuality', {str})) or 'normal',
|
||||||
'ws': ws,
|
'ws': ws,
|
||||||
|
Loading…
Reference in New Issue
Block a user