[vlive] fix: extractor tests for VODs
This commit is contained in:
parent
167c108f70
commit
0536e60b48
|
@ -11,7 +11,6 @@ from ..compat import compat_str
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
ExtractorError,
|
ExtractorError,
|
||||||
merge_dicts,
|
merge_dicts,
|
||||||
remove_start,
|
|
||||||
try_get,
|
try_get,
|
||||||
urlencode_postdata,
|
urlencode_postdata,
|
||||||
)
|
)
|
||||||
|
@ -97,49 +96,49 @@ class VLiveIE(NaverBaseIE):
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
webpage = self._download_webpage(
|
PARAMS_RE = r'window\.__PRELOADED_STATE__\s*=\s*({.*});?\s*</script>'
|
||||||
'https://www.vlive.tv/video/%s' % video_id, video_id)
|
PARAMS_FIELD = 'params'
|
||||||
|
|
||||||
VIDEO_PARAMS_RE = r'\bvlive\.video\.init\(([^)]+)'
|
|
||||||
VIDEO_PARAMS_FIELD = 'video params'
|
|
||||||
|
|
||||||
params = self._parse_json(self._search_regex(
|
|
||||||
VIDEO_PARAMS_RE, webpage, VIDEO_PARAMS_FIELD, default=''), video_id,
|
|
||||||
transform_source=lambda s: '[' + s + ']', fatal=False)
|
|
||||||
|
|
||||||
if not params or len(params) < 7:
|
|
||||||
params = self._search_regex(
|
params = self._search_regex(
|
||||||
VIDEO_PARAMS_RE, webpage, VIDEO_PARAMS_FIELD)
|
PARAMS_RE, webpage, PARAMS_FIELD, default='', flags=re.DOTALL)
|
||||||
params = [p.strip(r'"') for p in re.split(r'\s*,\s*', params)]
|
params = self._parse_json(params, video_id, fatal=False)
|
||||||
|
|
||||||
status, long_video_id, key = params[2], params[5], params[6]
|
video_params = params["postDetail"]["post"].get("officialVideo")
|
||||||
status = remove_start(status, 'PRODUCT_')
|
if video_params is None:
|
||||||
|
raise ExtractorError('Invalid key: Failed to extract video parameters.')
|
||||||
|
|
||||||
if status in ('LIVE_ON_AIR', 'BIG_EVENT_ON_AIR'):
|
long_video_id = video_params["vodId"]
|
||||||
return self._live(video_id, webpage)
|
video_type = video_params["type"]
|
||||||
elif status in ('VOD_ON_AIR', 'BIG_EVENT_INTRO'):
|
KEY_ENDPOINT = 'https://www.vlive.tv/globalv-web/vam-web/video/v1.0/vod/%s/inkey' % video_id
|
||||||
return self._replay(video_id, webpage, long_video_id, key)
|
key_json = self._download_json(KEY_ENDPOINT, video_id,
|
||||||
|
headers={"referer": "https://www.vlive.tv"})
|
||||||
|
key = key_json["inkey"]
|
||||||
|
|
||||||
if status == 'LIVE_END':
|
if video_type in ('VOD'):
|
||||||
raise ExtractorError('Uploading for replay. Please wait...',
|
encoding_status = video_params["encodingStatus"]
|
||||||
expected=True)
|
if encoding_status == 'COMPLETE':
|
||||||
elif status == 'COMING_SOON':
|
return self._replay(video_id, webpage, long_video_id, key, params)
|
||||||
raise ExtractorError('Coming soon!', expected=True)
|
|
||||||
elif status == 'CANCELED':
|
|
||||||
raise ExtractorError('We are sorry, '
|
|
||||||
'but the live broadcast has been canceled.',
|
|
||||||
expected=True)
|
|
||||||
elif status == 'ONLY_APP':
|
|
||||||
raise ExtractorError('Unsupported video type', expected=True)
|
|
||||||
else:
|
else:
|
||||||
raise ExtractorError('Unknown status %s' % status)
|
raise ExtractorError('VOD encoding not yet complete. Please try again later.',
|
||||||
|
expected=True)
|
||||||
|
elif video_type in ('LIVE'):
|
||||||
|
video_status = video_params["status"]
|
||||||
|
if video_status == 'RESERVED':
|
||||||
|
raise ExtractorError('Coming soon!', expected=True)
|
||||||
|
else:
|
||||||
|
return self._live(video_id, webpage, params)
|
||||||
|
else:
|
||||||
|
raise ExtractorError('Unknown video type %s' % video_type)
|
||||||
|
|
||||||
def _get_common_fields(self, webpage):
|
def _get_common_fields(self, webpage, params):
|
||||||
title = self._og_search_title(webpage)
|
title = self._og_search_title(webpage)
|
||||||
creator = self._html_search_regex(
|
description = self._html_search_meta(
|
||||||
r'<div[^>]+class="info_area"[^>]*>\s*(?:<em[^>]*>.*?</em\s*>\s*)?<a\s+[^>]*>([^<]+)',
|
['og:description', 'description', 'twitter:description'],
|
||||||
webpage, 'creator', fatal=False)
|
webpage, 'description', default=None)
|
||||||
|
creator = (try_get(params, lambda x: x["channel"]["channel"]["channelName"], compat_str)
|
||||||
|
or self._search_regex(r'on (.*) channel', description or '', 'creator', fatal=False))
|
||||||
thumbnail = self._og_search_thumbnail(webpage)
|
thumbnail = self._og_search_thumbnail(webpage)
|
||||||
return {
|
return {
|
||||||
'title': title,
|
'title': title,
|
||||||
|
@ -147,7 +146,7 @@ class VLiveIE(NaverBaseIE):
|
||||||
'thumbnail': thumbnail,
|
'thumbnail': thumbnail,
|
||||||
}
|
}
|
||||||
|
|
||||||
def _live(self, video_id, webpage):
|
def _live(self, video_id, webpage, params):
|
||||||
init_page = self._download_init_page(video_id)
|
init_page = self._download_init_page(video_id)
|
||||||
|
|
||||||
live_params = self._search_regex(
|
live_params = self._search_regex(
|
||||||
|
@ -164,7 +163,7 @@ class VLiveIE(NaverBaseIE):
|
||||||
fatal=False, live=True))
|
fatal=False, live=True))
|
||||||
self._sort_formats(formats)
|
self._sort_formats(formats)
|
||||||
|
|
||||||
info = self._get_common_fields(webpage)
|
info = self._get_common_fields(webpage, params)
|
||||||
info.update({
|
info.update({
|
||||||
'title': self._live_title(info['title']),
|
'title': self._live_title(info['title']),
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
|
@ -173,7 +172,7 @@ class VLiveIE(NaverBaseIE):
|
||||||
})
|
})
|
||||||
return info
|
return info
|
||||||
|
|
||||||
def _replay(self, video_id, webpage, long_video_id, key):
|
def _replay(self, video_id, webpage, long_video_id, key, params):
|
||||||
if '' in (long_video_id, key):
|
if '' in (long_video_id, key):
|
||||||
init_page = self._download_init_page(video_id)
|
init_page = self._download_init_page(video_id)
|
||||||
video_info = self._parse_json(self._search_regex(
|
video_info = self._parse_json(self._search_regex(
|
||||||
|
@ -186,7 +185,7 @@ class VLiveIE(NaverBaseIE):
|
||||||
long_video_id, key = video_info['vid'], video_info['inkey']
|
long_video_id, key = video_info['vid'], video_info['inkey']
|
||||||
|
|
||||||
return merge_dicts(
|
return merge_dicts(
|
||||||
self._get_common_fields(webpage),
|
self._get_common_fields(webpage, params),
|
||||||
self._extract_video_info(video_id, long_video_id, key))
|
self._extract_video_info(video_id, long_video_id, key))
|
||||||
|
|
||||||
def _download_init_page(self, video_id):
|
def _download_init_page(self, video_id):
|
||||||
|
|
Loading…
Reference in New Issue