mirror of https://github.com/yt-dlp/yt-dlp.git
[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\(([^)]+)'
|
params = self._search_regex(
|
||||||
VIDEO_PARAMS_FIELD = 'video params'
|
PARAMS_RE, webpage, PARAMS_FIELD, default='', flags=re.DOTALL)
|
||||||
|
params = self._parse_json(params, video_id, fatal=False)
|
||||||
|
|
||||||
params = self._parse_json(self._search_regex(
|
video_params = params["postDetail"]["post"].get("officialVideo")
|
||||||
VIDEO_PARAMS_RE, webpage, VIDEO_PARAMS_FIELD, default=''), video_id,
|
if video_params is None:
|
||||||
transform_source=lambda s: '[' + s + ']', fatal=False)
|
raise ExtractorError('Invalid key: Failed to extract video parameters.')
|
||||||
|
|
||||||
if not params or len(params) < 7:
|
long_video_id = video_params["vodId"]
|
||||||
params = self._search_regex(
|
video_type = video_params["type"]
|
||||||
VIDEO_PARAMS_RE, webpage, VIDEO_PARAMS_FIELD)
|
KEY_ENDPOINT = 'https://www.vlive.tv/globalv-web/vam-web/video/v1.0/vod/%s/inkey' % video_id
|
||||||
params = [p.strip(r'"') for p in re.split(r'\s*,\s*', params)]
|
key_json = self._download_json(KEY_ENDPOINT, video_id,
|
||||||
|
headers={"referer": "https://www.vlive.tv"})
|
||||||
|
key = key_json["inkey"]
|
||||||
|
|
||||||
status, long_video_id, key = params[2], params[5], params[6]
|
if video_type in ('VOD'):
|
||||||
status = remove_start(status, 'PRODUCT_')
|
encoding_status = video_params["encodingStatus"]
|
||||||
|
if encoding_status == 'COMPLETE':
|
||||||
if status in ('LIVE_ON_AIR', 'BIG_EVENT_ON_AIR'):
|
return self._replay(video_id, webpage, long_video_id, key, params)
|
||||||
return self._live(video_id, webpage)
|
else:
|
||||||
elif status in ('VOD_ON_AIR', 'BIG_EVENT_INTRO'):
|
raise ExtractorError('VOD encoding not yet complete. Please try again later.',
|
||||||
return self._replay(video_id, webpage, long_video_id, key)
|
expected=True)
|
||||||
|
elif video_type in ('LIVE'):
|
||||||
if status == 'LIVE_END':
|
video_status = video_params["status"]
|
||||||
raise ExtractorError('Uploading for replay. Please wait...',
|
if video_status == 'RESERVED':
|
||||||
expected=True)
|
raise ExtractorError('Coming soon!', expected=True)
|
||||||
elif status == 'COMING_SOON':
|
else:
|
||||||
raise ExtractorError('Coming soon!', expected=True)
|
return self._live(video_id, webpage, params)
|
||||||
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('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