[redtube] Make ‘http:’ not optional (closes #2160)
[youtube-dl] / youtube_dl / extractor / viki.py
index 78d03c0793031f4adf1d329b3a6fc6c26fd93e00..2206a06d59f57093f59135f6faa8d68381695a95 100644 (file)
@@ -1,6 +1,8 @@
 import re
 
 from ..utils import (
+    ExtractorError,
+    unescapeHTML,
     unified_strdate,
 )
 from .subtitles import SubtitlesInfoExtractor
@@ -20,7 +22,8 @@ class VikiIE(SubtitlesInfoExtractor):
             u'description': u'md5:c4b17b9626dd4b143dcc4d855ba3474e',
             u'upload_date': u'20131121',
             u'age_limit': 13,
-        }
+        },
+        u'skip': u'Blocked in the US',
     }
 
     def _real_extract(self, url):
@@ -32,11 +35,12 @@ class VikiIE(SubtitlesInfoExtractor):
         description = self._og_search_description(webpage)
         thumbnail = self._og_search_thumbnail(webpage)
 
-        uploader = self._html_search_regex(
-            r'<strong>Broadcast Network: </strong>\s*([^<]*)<', webpage,
-            u'uploader')
-        if uploader is not None:
-            uploader = uploader.strip()
+        uploader_m = re.search(
+            r'<strong>Broadcast Network: </strong>\s*([^<]*)<', webpage)
+        if uploader_m is None:
+            uploader = None
+        else:
+            uploader = uploader_m.group(1).strip()
 
         rating_str = self._html_search_regex(
             r'<strong>Rating: </strong>\s*([^<]*)<', webpage,
@@ -51,7 +55,12 @@ class VikiIE(SubtitlesInfoExtractor):
         age_limit = RATINGS.get(rating_str)
 
         info_url = 'http://www.viki.com/player5_fragment/%s?action=show&controller=videos' % video_id
-        info_webpage = self._download_webpage(info_url, video_id)
+        info_webpage = self._download_webpage(
+            info_url, video_id, note=u'Downloading info page')
+        if re.match(r'\s*<div\s+class="video-error', info_webpage):
+            raise ExtractorError(
+                u'Video %s is blocked from your location.' % video_id,
+                expected=True)
         video_url = self._html_search_regex(
             r'<source[^>]+src="([^"]+)"', info_webpage, u'video URL')
 
@@ -83,7 +92,8 @@ class VikiIE(SubtitlesInfoExtractor):
 
     def _get_available_subtitles(self, video_id, info_webpage):
         res = {}
-        for sturl in re.findall(r'<track src="([^"]+)"/>'):
+        for sturl_html in re.findall(r'<track src="([^"]+)"/>', info_webpage):
+            sturl = unescapeHTML(sturl_html)
             m = re.search(r'/(?P<lang>[a-z]+)\.vtt', sturl)
             if not m:
                 continue