Merge pull request #101 from exwm/vlive-fix

[vlive] fix extractor for revamped website
This commit is contained in:
Tom-Oliver Heidel 2020-11-05 17:20:44 +01:00 committed by GitHub
commit 206de9b233
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,7 +11,6 @@
from ..utils import ( from ..utils import (
ExtractorError, ExtractorError,
merge_dicts, merge_dicts,
remove_start,
try_get, try_get,
urlencode_postdata, urlencode_postdata,
) )
@ -19,10 +18,10 @@
class VLiveIE(NaverBaseIE): class VLiveIE(NaverBaseIE):
IE_NAME = 'vlive' IE_NAME = 'vlive'
_VALID_URL = r'https?://(?:(?:www|m)\.)?vlive\.tv/video/(?P<id>[0-9]+)' _VALID_URL = r'https?://(?:(?:www|m)\.)?vlive\.tv/(?:video|post)/(?P<id>(?:\d-)?[0-9]+)'
_NETRC_MACHINE = 'vlive' _NETRC_MACHINE = 'vlive'
_TESTS = [{ _TESTS = [{
'url': 'http://www.vlive.tv/video/1326', 'url': 'https://www.vlive.tv/video/1326',
'md5': 'cc7314812855ce56de70a06a27314983', 'md5': 'cc7314812855ce56de70a06a27314983',
'info_dict': { 'info_dict': {
'id': '1326', 'id': '1326',
@ -32,8 +31,21 @@ class VLiveIE(NaverBaseIE):
'view_count': int, 'view_count': int,
'uploader_id': 'muploader_a', 'uploader_id': 'muploader_a',
}, },
}, { },
'url': 'http://www.vlive.tv/video/16937', {
'url': 'https://vlive.tv/post/1-18244258',
'md5': 'cc7314812855ce56de70a06a27314983',
'info_dict': {
'id': '1326',
'ext': 'mp4',
'title': "[V LIVE] Girl's Day's Broadcast",
'creator': "Girl's Day",
'view_count': int,
'uploader_id': 'muploader_a',
},
},
{
'url': 'https://www.vlive.tv/video/16937',
'info_dict': { 'info_dict': {
'id': '16937', 'id': '16937',
'ext': 'mp4', 'ext': 'mp4',
@ -96,50 +108,69 @@ def is_logged_in():
raise ExtractorError('Unable to log in', expected=True) raise ExtractorError('Unable to log in', expected=True)
def _real_extract(self, url): def _real_extract(self, url):
video_id = self._match_id(url) # url may match on a post or a video url with a post_id potentially matching a video_id
working_id = self._match_id(url)
webpage = self._download_webpage(url, working_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, working_id, fatal=False)
params = self._parse_json(self._search_regex( video_params = try_get(params, lambda x: x["postDetail"]["post"]["officialVideo"], dict)
VIDEO_PARAMS_RE, webpage, VIDEO_PARAMS_FIELD, default=''), video_id,
transform_source=lambda s: '[' + s + ']', fatal=False)
if not params or len(params) < 7: if video_params is None:
params = self._search_regex( error = try_get(params, lambda x: x["postDetail"]["error"], dict)
VIDEO_PARAMS_RE, webpage, VIDEO_PARAMS_FIELD) error_data = try_get(error, lambda x: x["data"], dict)
params = [p.strip(r'"') for p in re.split(r'\s*,\s*', params)] error_video = try_get(error_data, lambda x: x["officialVideo"], dict)
error_msg = try_get(error, lambda x: x["message"], compat_str)
product_type = try_get(error_data,
[lambda x: x["officialVideo"]["productType"],
lambda x: x["board"]["boardType"]],
compat_str)
status, long_video_id, key = params[2], params[5], params[6] if error_video is not None:
status = remove_start(status, 'PRODUCT_') if product_type in ('VLIVE_PLUS', 'VLIVE+'):
self.raise_login_required('This video is only available with V LIVE+.')
elif error_msg is not None:
raise ExtractorError('V LIVE reported the following error: %s' % error_msg)
else:
raise ExtractorError('Failed to extract video parameters.')
elif 'post' in url:
raise ExtractorError('Url does not appear to be a video post.', expected=True)
else:
raise ExtractorError('Failed to extract video parameters.')
if status in ('LIVE_ON_AIR', 'BIG_EVENT_ON_AIR'): video_id = working_id if 'video' in url else str(video_params["videoSeq"])
return self._live(video_id, webpage)
elif status in ('VOD_ON_AIR', 'BIG_EVENT_INTRO'):
return self._replay(video_id, webpage, long_video_id, key)
if status == 'LIVE_END': video_type = video_params["type"]
raise ExtractorError('Uploading for replay. Please wait...', if video_type in ('VOD'):
expected=True) encoding_status = video_params["encodingStatus"]
elif status == 'COMING_SOON': if encoding_status == 'COMPLETE':
raise ExtractorError('Coming soon!', expected=True) return self._replay(video_id, webpage, params, video_params)
elif status == 'CANCELED': else:
raise ExtractorError('We are sorry, ' raise ExtractorError('VOD encoding not yet complete. Please try again later.',
'but the live broadcast has been canceled.', expected=True)
expected=True) elif video_type in ('LIVE'):
elif status == 'ONLY_APP': video_status = video_params["status"]
raise ExtractorError('Unsupported video type', expected=True) if video_status in ('RESERVED'):
raise ExtractorError('Coming soon!', expected=True)
elif video_status in ('ENDED', 'END'):
raise ExtractorError('Uploading for replay. Please wait...', expected=True)
else:
return self._live(video_id, webpage, params)
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,24 +178,21 @@ def _get_common_fields(self, webpage):
'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) LIVE_INFO_ENDPOINT = 'https://www.vlive.tv/globalv-web/vam-web/old/v3/live/%s/playInfo' % video_id
play_info = self._download_json(LIVE_INFO_ENDPOINT, video_id,
headers={"referer": "https://www.vlive.tv"})
live_params = self._search_regex( streams = try_get(play_info, lambda x: x["result"]["streamList"], list) or []
r'"liveStreamInfo"\s*:\s*(".*"),',
init_page, 'live stream info')
live_params = self._parse_json(live_params, video_id)
live_params = self._parse_json(live_params, video_id)
formats = [] formats = []
for vid in live_params.get('resolutions', []): for stream in streams:
formats.extend(self._extract_m3u8_formats( formats.extend(self._extract_m3u8_formats(
vid['cdnUrl'], video_id, 'mp4', stream['serviceUrl'], video_id, 'mp4',
m3u8_id=vid.get('name'),
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,44 +201,37 @@ def _live(self, video_id, webpage):
}) })
return info return info
def _replay(self, video_id, webpage, long_video_id, key): def _replay(self, video_id, webpage, params, video_params):
if '' in (long_video_id, key): long_video_id = video_params["vodId"]
init_page = self._download_init_page(video_id)
video_info = self._parse_json(self._search_regex( VOD_KEY_ENDPOINT = 'https://www.vlive.tv/globalv-web/vam-web/video/v1.0/vod/%s/inkey' % video_id
(r'(?s)oVideoStatus\s*=\s*({.+?})\s*</script', key_json = self._download_json(VOD_KEY_ENDPOINT, video_id,
r'(?s)oVideoStatus\s*=\s*({.+})'), init_page, 'video info'), headers={"referer": "https://www.vlive.tv"})
video_id) key = key_json["inkey"]
if video_info.get('status') == 'NEED_CHANNEL_PLUS':
self.raise_login_required(
'This video is only available for CH+ subscribers')
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):
return self._download_webpage(
'https://www.vlive.tv/video/init/view',
video_id, note='Downloading live webpage',
data=urlencode_postdata({'videoSeq': video_id}),
headers={
'Referer': 'https://www.vlive.tv/video/%s' % video_id,
'Content-Type': 'application/x-www-form-urlencoded'
})
class VLiveChannelIE(InfoExtractor): class VLiveChannelIE(InfoExtractor):
IE_NAME = 'vlive:channel' IE_NAME = 'vlive:channel'
_VALID_URL = r'https?://channels\.vlive\.tv/(?P<id>[0-9A-Z]+)' _VALID_URL = r'https?://(?:(?:www|m)\.)?(?:channels\.vlive\.tv/|vlive\.tv/channels?/)(?P<id>[0-9A-Z]+)'
_TEST = { _TESTS = [{
'url': 'http://channels.vlive.tv/FCD4B', 'url': 'https://channels.vlive.tv/FCD4B',
'info_dict': { 'info_dict': {
'id': 'FCD4B', 'id': 'FCD4B',
'title': 'MAMAMOO', 'title': 'MAMAMOO',
}, },
'playlist_mincount': 110 'playlist_mincount': 110
} }, {
'url': 'https://www.vlive.tv/channel/FCD4B',
'info_dict': {
'id': 'FCD4B',
'title': 'MAMAMOO',
},
'playlist_mincount': 110
}]
_APP_ID = '8c6cc7b45d2568fb668be6e05b6e5a3b' _APP_ID = '8c6cc7b45d2568fb668be6e05b6e5a3b'
def _real_extract(self, url): def _real_extract(self, url):