]>
Commit | Line | Data |
---|---|---|
cb9722cb PH |
1 | from __future__ import unicode_literals |
2 | ||
382ed50e PH |
3 | import re |
4 | ||
4f7cea6c | 5 | from ..compat import compat_urlparse |
382ed50e | 6 | from ..utils import ( |
6d88bc37 | 7 | ExtractorError, |
de79c46c | 8 | unescapeHTML, |
382ed50e | 9 | unified_strdate, |
a1a530b0 | 10 | US_RATINGS, |
382ed50e | 11 | ) |
4f7cea6c | 12 | from .common import InfoExtractor |
382ed50e PH |
13 | |
14 | ||
4f7cea6c | 15 | class VikiIE(InfoExtractor): |
cb9722cb | 16 | IE_NAME = 'viki' |
382ed50e PH |
17 | |
18 | _VALID_URL = r'^https?://(?:www\.)?viki\.com/videos/(?P<id>[0-9]+v)' | |
19 | _TEST = { | |
cb9722cb | 20 | 'url': 'http://www.viki.com/videos/1023585v-heirs-episode-14', |
cb9722cb PH |
21 | 'info_dict': { |
22 | 'id': '1023585v', | |
23 | 'ext': 'mp4', | |
24 | 'title': 'Heirs Episode 14', | |
25 | 'uploader': 'SBS', | |
26 | 'description': 'md5:c4b17b9626dd4b143dcc4d855ba3474e', | |
27 | 'upload_date': '20131121', | |
28 | 'age_limit': 13, | |
6d88bc37 | 29 | }, |
cb9722cb | 30 | 'skip': 'Blocked in the US', |
382ed50e PH |
31 | } |
32 | ||
33 | def _real_extract(self, url): | |
8ee34150 | 34 | video_id = self._match_id(url) |
382ed50e PH |
35 | |
36 | webpage = self._download_webpage(url, video_id) | |
37 | title = self._og_search_title(webpage) | |
38 | description = self._og_search_description(webpage) | |
39 | thumbnail = self._og_search_thumbnail(webpage) | |
40 | ||
1fb2bcbb PH |
41 | uploader_m = re.search( |
42 | r'<strong>Broadcast Network: </strong>\s*([^<]*)<', webpage) | |
43 | if uploader_m is None: | |
44 | uploader = None | |
45 | else: | |
07e40358 | 46 | uploader = uploader_m.group(1).strip() |
382ed50e PH |
47 | |
48 | rating_str = self._html_search_regex( | |
49 | r'<strong>Rating: </strong>\s*([^<]*)<', webpage, | |
cb9722cb | 50 | 'rating information', default='').strip() |
a1a530b0 | 51 | age_limit = US_RATINGS.get(rating_str) |
382ed50e PH |
52 | |
53 | info_url = 'http://www.viki.com/player5_fragment/%s?action=show&controller=videos' % video_id | |
b7553b25 | 54 | info_webpage = self._download_webpage( |
cb9722cb | 55 | info_url, video_id, note='Downloading info page') |
6d88bc37 PH |
56 | if re.match(r'\s*<div\s+class="video-error', info_webpage): |
57 | raise ExtractorError( | |
cb9722cb | 58 | 'Video %s is blocked from your location.' % video_id, |
6d88bc37 | 59 | expected=True) |
382ed50e | 60 | video_url = self._html_search_regex( |
cb9722cb | 61 | r'<source[^>]+src="([^"]+)"', info_webpage, 'video URL') |
382ed50e PH |
62 | |
63 | upload_date_str = self._html_search_regex( | |
cb9722cb | 64 | r'"created_at":"([^"]+)"', info_webpage, 'upload date') |
382ed50e PH |
65 | upload_date = ( |
66 | unified_strdate(upload_date_str) | |
67 | if upload_date_str is not None | |
68 | else None | |
69 | ) | |
70 | ||
71 | # subtitles | |
72 | video_subtitles = self.extract_subtitles(video_id, info_webpage) | |
382ed50e PH |
73 | |
74 | return { | |
75 | 'id': video_id, | |
76 | 'title': title, | |
77 | 'url': video_url, | |
78 | 'description': description, | |
79 | 'thumbnail': thumbnail, | |
80 | 'age_limit': age_limit, | |
81 | 'uploader': uploader, | |
82 | 'subtitles': video_subtitles, | |
83 | 'upload_date': upload_date, | |
84 | } | |
85 | ||
4f7cea6c | 86 | def _get_subtitles(self, video_id, info_webpage): |
382ed50e | 87 | res = {} |
4f7cea6c | 88 | for sturl_html in re.findall(r'<track src="([^"]+)"', info_webpage): |
de79c46c | 89 | sturl = unescapeHTML(sturl_html) |
382ed50e PH |
90 | m = re.search(r'/(?P<lang>[a-z]+)\.vtt', sturl) |
91 | if not m: | |
92 | continue | |
4f7cea6c JMF |
93 | res[m.group('lang')] = [{ |
94 | 'url': compat_urlparse.urljoin('http://www.viki.com', sturl), | |
95 | 'ext': 'vtt', | |
96 | }] | |
382ed50e | 97 | return res |