1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2024-11-22 16:44:32 +01:00

[niconico] Add tags info

This commit is contained in:
ishowta 2018-11-11 02:58:38 +09:00
parent dbdaaa231a
commit 05bd9ad0db

View File

@ -11,7 +11,6 @@ from ..compat import (
) )
from ..utils import ( from ..utils import (
determine_ext, determine_ext,
dict_get,
ExtractorError, ExtractorError,
int_or_none, int_or_none,
float_or_none, float_or_none,
@ -22,6 +21,7 @@ from ..utils import (
unified_timestamp, unified_timestamp,
urlencode_postdata, urlencode_postdata,
xpath_text, xpath_text,
xpath_element,
) )
@ -45,6 +45,7 @@ class NiconicoIE(InfoExtractor):
'duration': 33, 'duration': 33,
'view_count': int, 'view_count': int,
'comment_count': int, 'comment_count': int,
'tags': list
}, },
'skip': 'Requires an account', 'skip': 'Requires an account',
}, { }, {
@ -62,6 +63,7 @@ class NiconicoIE(InfoExtractor):
'upload_date': '20110429', 'upload_date': '20110429',
'timestamp': 1304065916, 'timestamp': 1304065916,
'duration': 209, 'duration': 209,
'tags': list
}, },
'skip': 'Requires an account', 'skip': 'Requires an account',
}, { }, {
@ -78,6 +80,7 @@ class NiconicoIE(InfoExtractor):
'timestamp': int, # timestamp field has different value if logged in 'timestamp': int, # timestamp field has different value if logged in
'duration': 304, 'duration': 304,
'view_count': int, 'view_count': int,
'tags': list
}, },
'skip': 'Requires an account', 'skip': 'Requires an account',
}, { }, {
@ -92,6 +95,7 @@ class NiconicoIE(InfoExtractor):
'upload_date': '20140104', 'upload_date': '20140104',
'uploader': 'アニメロチャンネル', 'uploader': 'アニメロチャンネル',
'uploader_id': '312', 'uploader_id': '312',
'tags': list
}, },
'skip': 'The viewing period of the video you were searching for has expired.', 'skip': 'The viewing period of the video you were searching for has expired.',
}, { }, {
@ -111,6 +115,7 @@ class NiconicoIE(InfoExtractor):
'uploader_id': '1392194', 'uploader_id': '1392194',
'view_count': int, 'view_count': int,
'comment_count': int, 'comment_count': int,
'tags': list
}, },
'skip': 'Requires an account', 'skip': 'Requires an account',
}, { }, {
@ -130,6 +135,7 @@ class NiconicoIE(InfoExtractor):
'duration': 198, 'duration': 198,
'view_count': int, 'view_count': int,
'comment_count': int, 'comment_count': int,
'tags': list
}, },
'skip': 'Requires an account', 'skip': 'Requires an account',
}, { }, {
@ -149,6 +155,7 @@ class NiconicoIE(InfoExtractor):
'duration': 5271, 'duration': 5271,
'view_count': int, 'view_count': int,
'comment_count': int, 'comment_count': int,
'tags': list
}, },
'skip': 'Requires an account', 'skip': 'Requires an account',
}, { }, {
@ -284,6 +291,18 @@ class NiconicoIE(InfoExtractor):
def _format_id_from_url(video_url): def _format_id_from_url(video_url):
return 'economy' if video_real_url.endswith('low') else 'normal' return 'economy' if video_real_url.endswith('low') else 'normal'
video_info_xml = self._download_xml(
'http://ext.nicovideo.jp/api/getthumbinfo/' + video_id,
video_id, note='Downloading video info page')
def get_video_info(items):
if not isinstance(items, list):
items = [items]
for item in items:
ret = xpath_text(video_info_xml, './/' + item)
if ret:
return ret
try: try:
video_real_url = api_data['video']['smileInfo']['url'] video_real_url = api_data['video']['smileInfo']['url']
except KeyError: # Flash videos except KeyError: # Flash videos
@ -306,18 +325,6 @@ class NiconicoIE(InfoExtractor):
else: else:
raise ExtractorError('Unable to find video URL') raise ExtractorError('Unable to find video URL')
video_info_xml = self._download_xml(
'http://ext.nicovideo.jp/api/getthumbinfo/' + video_id,
video_id, note='Downloading video info page')
def get_video_info(items):
if not isinstance(items, list):
items = [items]
for item in items:
ret = xpath_text(video_info_xml, './/' + item)
if ret:
return ret
video_real_url = flv_info['url'][0] video_real_url = flv_info['url'][0]
extension = get_video_info('movie_type') extension = get_video_info('movie_type')
@ -350,9 +357,6 @@ class NiconicoIE(InfoExtractor):
'format_id': _format_id_from_url(video_real_url), 'format_id': _format_id_from_url(video_real_url),
}] }]
def get_video_info(items):
return dict_get(api_data['video'], items)
# Start extracting information # Start extracting information
title = get_video_info('title') title = get_video_info('title')
if not title: if not title:
@ -420,6 +424,8 @@ class NiconicoIE(InfoExtractor):
uploader_id = get_video_info(['ch_id', 'user_id']) or owner.get('id') uploader_id = get_video_info(['ch_id', 'user_id']) or owner.get('id')
uploader = get_video_info(['ch_name', 'user_nickname']) or owner.get('nickname') uploader = get_video_info(['ch_name', 'user_nickname']) or owner.get('nickname')
tags = [tag.text for tag in xpath_element(video_info_xml, './/' + 'tags')]
return { return {
'id': video_id, 'id': video_id,
'title': title, 'title': title,
@ -433,6 +439,7 @@ class NiconicoIE(InfoExtractor):
'comment_count': comment_count, 'comment_count': comment_count,
'duration': duration, 'duration': duration,
'webpage_url': webpage_url, 'webpage_url': webpage_url,
'tags': tags
} }