[naver] improve metadata extraction

master
Remita Amine 4 years ago
parent c88debff5d
commit 838171630d

@ -8,8 +8,8 @@ from ..utils import (
clean_html, clean_html,
dict_get, dict_get,
ExtractorError, ExtractorError,
get_element_by_class,
int_or_none, int_or_none,
parse_duration,
try_get, try_get,
update_url_query, update_url_query,
) )
@ -113,6 +113,7 @@ class NaverIE(NaverBaseIE):
'ext': 'mp4', 'ext': 'mp4',
'title': '[9월 모의고사 해설강의][수학_김상희] 수학 A형 16~20번', 'title': '[9월 모의고사 해설강의][수학_김상희] 수학 A형 16~20번',
'description': '메가스터디 수학 김상희 선생님이 9월 모의고사 수학A형 16번에서 20번까지 해설강의를 공개합니다.', 'description': '메가스터디 수학 김상희 선생님이 9월 모의고사 수학A형 16번에서 20번까지 해설강의를 공개합니다.',
'timestamp': 1378200754,
'upload_date': '20130903', 'upload_date': '20130903',
'uploader': '메가스터디, 합격불변의 법칙', 'uploader': '메가스터디, 합격불변의 법칙',
'uploader_id': 'megastudy', 'uploader_id': 'megastudy',
@ -125,6 +126,7 @@ class NaverIE(NaverBaseIE):
'ext': 'mp4', 'ext': 'mp4',
'title': '9년이 지나도 아픈 기억, 전효성의 아버지', 'title': '9년이 지나도 아픈 기억, 전효성의 아버지',
'description': 'md5:eb6aca9d457b922e43860a2a2b1984d3', 'description': 'md5:eb6aca9d457b922e43860a2a2b1984d3',
'timestamp': 1432030253,
'upload_date': '20150519', 'upload_date': '20150519',
'uploader': '4가지쇼 시즌2', 'uploader': '4가지쇼 시즌2',
'uploader_id': 'wrappinguser29', 'uploader_id': 'wrappinguser29',
@ -138,29 +140,27 @@ class NaverIE(NaverBaseIE):
def _real_extract(self, url): def _real_extract(self, url):
video_id = self._match_id(url) video_id = self._match_id(url)
content = self._download_json( content = self._download_json(
'https://tv.naver.com/api/contents/json/v/' + video_id, 'https://tv.naver.com/api/json/v/' + video_id,
video_id, headers=self.geo_verification_headers()) video_id, headers=self.geo_verification_headers())
player_json = content.get('playerJson') or {} player_info_json = content.get('playerInfoJson') or {}
current_clip = player_info_json.get('currentClip') or {}
vid = player_json.get('videoId') vid = current_clip.get('videoId')
in_key = player_json.get('inKey') in_key = current_clip.get('inKey')
if not vid or not in_key: if not vid or not in_key:
player_auth = player_json.get('playerAuth') player_auth = try_get(player_info_json, lambda x: x['playerOption']['auth'])
if player_auth == 'notCountry': if player_auth == 'notCountry':
self.raise_geo_restricted(countries=['KR']) self.raise_geo_restricted(countries=['KR'])
elif player_auth == 'notLogin': elif player_auth == 'notLogin':
self.raise_login_required() self.raise_login_required()
raise ExtractorError('couldn\'t extract vid and key') raise ExtractorError('couldn\'t extract vid and key')
info = self._extract_video_info(video_id, vid, in_key) info = self._extract_video_info(video_id, vid, in_key)
info.update({
clip_info_html = content.get('clipInfoHtml') 'description': clean_html(current_clip.get('description')),
if clip_info_html: 'timestamp': int_or_none(current_clip.get('firstExposureTime'), 1000),
info['description'] = clean_html(get_element_by_class('desc', clip_info_html)) 'duration': parse_duration(current_clip.get('displayPlayTime')),
upload_date = self._search_regex( 'like_count': int_or_none(current_clip.get('recommendPoint')),
r'<span[^>]+class="date".*?(\d{4}\.\d{2}\.\d{2})', 'age_limit': 19 if current_clip.get('adult') else None,
clip_info_html, 'upload date', fatal=False) })
if upload_date:
info['upload_date'] = upload_date.replace('.', '')
return info return info

Loading…
Cancel
Save