1 from __future__ import unicode_literals
16 from .common import InfoExtractor
19 class VikiIE(InfoExtractor):
23 _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'
25 _VALID_URL = r'^https?://(?:www\.)?viki\.com/videos/(?P<id>[0-9]+v)'
27 'url': 'http://www.viki.com/videos/1023585v-heirs-episode-14',
31 'title': 'Heirs Episode 14',
33 'description': 'md5:c4b17b9626dd4b143dcc4d855ba3474e',
34 'upload_date': '20131121',
37 'skip': 'Blocked in the US',
39 'url': 'http://www.viki.com/videos/1067139v-the-avengers-age-of-ultron-press-conference',
40 'md5': 'ca6493e6f0a6ec07da9aa8d6304b4b2c',
44 'description': 'md5:d70b2f9428f5488321bfe1db10d612ea',
45 'upload_date': '20150430',
46 'title': '\'The Avengers: Age of Ultron\' Press Conference',
50 def _real_extract(self, url):
51 video_id = self._match_id(url)
53 webpage = self._download_webpage(url, video_id)
54 title = self._og_search_title(webpage)
55 description = self._og_search_description(webpage)
56 thumbnail = self._og_search_thumbnail(webpage)
58 uploader_m = re.search(
59 r'<strong>Broadcast Network: </strong>\s*([^<]*)<', webpage)
60 if uploader_m is None:
63 uploader = uploader_m.group(1).strip()
65 rating_str = self._html_search_regex(
66 r'<strong>Rating: </strong>\s*([^<]*)<', webpage,
67 'rating information', default='').strip()
68 age_limit = US_RATINGS.get(rating_str)
70 req = compat_urllib_request.Request(
71 'http://www.viki.com/player5_fragment/%s?action=show&controller=videos' % video_id)
72 req.add_header('User-Agent', self._USER_AGENT)
73 info_webpage = self._download_webpage(
74 req, video_id, note='Downloading info page')
75 err_msg = self._html_search_regex(r'<div[^>]+class="video-error[^>]+>(.+)</div>', info_webpage, 'error message', default=None)
77 err_msg = clean_html(err_msg)
78 if 'not available in your region' in err_msg:
80 'Video %s is blocked from your location.' % video_id,
83 raise ExtractorError('Viki said: ' + err_msg)
84 video_url = self._html_search_regex(
85 r'<source[^>]+src="([^"]+)"', info_webpage, 'video URL')
87 upload_date_str = self._html_search_regex(
88 r'"created_at":"([^"]+)"', info_webpage, 'upload date')
90 unified_strdate(upload_date_str)
91 if upload_date_str is not None
96 video_subtitles = self.extract_subtitles(video_id, info_webpage)
102 'description': description,
103 'thumbnail': thumbnail,
104 'age_limit': age_limit,
105 'uploader': uploader,
106 'subtitles': video_subtitles,
107 'upload_date': upload_date,
110 def _get_subtitles(self, video_id, info_webpage):
112 for sturl_html in re.findall(r'<track src="([^"]+)"', info_webpage):
113 sturl = unescapeHTML(sturl_html)
114 m = re.search(r'/(?P<lang>[a-z]+)\.vtt', sturl)
117 res[m.group('lang')] = [{
118 'url': compat_urlparse.urljoin('http://www.viki.com', sturl),