2 from __future__ import unicode_literals
5 from hashlib import sha1
6 from base64 import b64encode
9 from .common import InfoExtractor
15 from ..compat import compat_urllib_parse
18 class VLiveIE(InfoExtractor):
20 # vlive.tv/video/ links redirect to www.vlive.tv/video/
21 _VALID_URL = r'https?://(?:(www|m)\.)?vlive\.tv/video/(?P<id>[0-9]+)'
23 'url': 'http://www.vlive.tv/video/1326',
24 'md5': 'cc7314812855ce56de70a06a27314983',
28 'title': '[V] Girl\'s Day\'s Broadcast',
29 'creator': 'Girl\'s Day',
33 def _real_extract(self, url):
34 video_id = self._match_id(url)
36 webpage = self._download_webpage(
37 'http://www.vlive.tv/video/%s' % video_id,
38 video_id, note='Download video page')
40 long_video_id = self._search_regex(
41 r'vlive\.tv\.video\.ajax\.request\.handler\.init\("[0-9]+",\s?"[^"]*",\s?"([^"]+)",\s?"[^"]+",\s?"[^"]*",\s?"[^"]*"\)', webpage, 'long_video_id')
43 key = self._search_regex(
44 r'vlive\.tv\.video\.ajax\.request\.handler\.init\("[0-9]+",\s?"[^"]*",\s?"[^"]+",\s?"([^"]+)",\s?"[^"]*",\s?"[^"]*"\)', webpage, 'key')
46 title = self._og_search_title(webpage)
47 thumbnail = self._og_search_thumbnail(webpage)
48 creator = self._html_search_regex(
49 r'<div class="info_area">\s*<strong[^>]+class="name">([^<>]+)</strong>', webpage, 'creator',fatal=False)
51 # doct = document type (xml or json), cpt = caption type (vtt or ttml)
52 url = "http://global.apis.naver.com/rmcnmv/rmcnmv/vod_play_videoInfo.json?videoId=%s&key=%s&ptc=http&doct=json&cpt=vtt" % (long_video_id, key)
54 playinfo = self._download_json(url, video_id, 'Downloading video json')
57 for vid in playinfo.get('videos', {}).get('list', []):
61 'abr': vid.get('bitrate', {}).get('audio'),
62 'vbr': vid.get('bitrate', {}).get('video'),
63 'format_id': vid.get('encodingOption', {}).get('name'),
64 'height': int_or_none(vid.get('encodingOption', {}).get('height')),
65 'width': int_or_none(vid.get('encodingOption', {}).get('width')),
67 self._sort_formats(formats)
70 for caption in playinfo.get('captions', {}).get('list', []):
71 subtitles[caption['language']] = [
72 {'ext': determine_ext(caption['source'], default_ext='vtt'),
73 'url': caption['source']}]
79 'thumbnail': thumbnail,
81 'subtitles': subtitles,