1 from __future__ import unicode_literals
15 from .common import InfoExtractor
18 class VikiIE(InfoExtractor):
22 _USER_AGENT = 'Mozilla/5.0(iPad; U; CPU OS 4_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8F191 Safari/6533.18.5'
24 _VALID_URL = r'^https?://(?:www\.)?viki\.com/videos/(?P<id>[0-9]+v)'
26 'url': 'http://www.viki.com/videos/1023585v-heirs-episode-14',
30 'title': 'Heirs Episode 14',
32 'description': 'md5:c4b17b9626dd4b143dcc4d855ba3474e',
33 'upload_date': '20131121',
36 'skip': 'Blocked in the US',
38 'url': 'http://www.viki.com/videos/1067139v-the-avengers-age-of-ultron-press-conference',
39 'md5': 'ca6493e6f0a6ec07da9aa8d6304b4b2c',
43 'description': 'md5:d70b2f9428f5488321bfe1db10d612ea',
44 'upload_date': '20150430',
45 'title': '\'The Avengers: Age of Ultron\' Press Conference',
49 def _real_extract(self, url):
50 video_id = self._match_id(url)
52 webpage = self._download_webpage(url, video_id)
53 title = self._og_search_title(webpage)
54 description = self._og_search_description(webpage)
55 thumbnail = self._og_search_thumbnail(webpage)
57 uploader_m = re.search(
58 r'<strong>Broadcast Network: </strong>\s*([^<]*)<', webpage)
59 if uploader_m is None:
62 uploader = uploader_m.group(1).strip()
64 rating_str = self._html_search_regex(
65 r'<strong>Rating: </strong>\s*([^<]*)<', webpage,
66 'rating information', default='').strip()
67 age_limit = US_RATINGS.get(rating_str)
69 req = compat_urllib_request.Request(
70 'http://www.viki.com/player5_fragment/%s?action=show&controller=videos' % video_id)
71 req.add_header('User-Agent', self._USER_AGENT)
72 info_webpage = self._download_webpage(
73 req, video_id, note='Downloading info page')
74 if re.match(r'\s*<div\s+class="video-error', info_webpage):
76 'Video %s is blocked from your location.' % video_id,
78 video_url = self._html_search_regex(
79 r'<source[^>]+src="([^"]+)"', info_webpage, 'video URL')
81 upload_date_str = self._html_search_regex(
82 r'"created_at":"([^"]+)"', info_webpage, 'upload date')
84 unified_strdate(upload_date_str)
85 if upload_date_str is not None
90 video_subtitles = self.extract_subtitles(video_id, info_webpage)
96 'description': description,
97 'thumbnail': thumbnail,
98 'age_limit': age_limit,
100 'subtitles': video_subtitles,
101 'upload_date': upload_date,
104 def _get_subtitles(self, video_id, info_webpage):
106 for sturl_html in re.findall(r'<track src="([^"]+)"', info_webpage):
107 sturl = unescapeHTML(sturl_html)
108 m = re.search(r'/(?P<lang>[a-z]+)\.vtt', sturl)
111 res[m.group('lang')] = [{
112 'url': compat_urlparse.urljoin('http://www.viki.com', sturl),