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