[viki] Enhance error message handling (#3774)
authorYen Chi Hsuan <yan12125@gmail.com>
Fri, 1 May 2015 16:32:46 +0000 (00:32 +0800)
committerYen Chi Hsuan <yan12125@gmail.com>
Fri, 1 May 2015 17:20:15 +0000 (01:20 +0800)
youtube_dl/extractor/viki.py

index 957e3c01ea548609f05c274eb9552b9491e68e10..0fc1ceb19c8ece086e683da59e720489c80edbba 100644 (file)
@@ -11,6 +11,7 @@ from ..utils import (
     unescapeHTML,
     unified_strdate,
     US_RATINGS,
+    clean_html,
 )
 from .common import InfoExtractor
 
@@ -71,10 +72,15 @@ class VikiIE(InfoExtractor):
         req.add_header('User-Agent', self._USER_AGENT)
         info_webpage = self._download_webpage(
             req, video_id, note='Downloading info page')
-        if re.match(r'\s*<div\s+class="video-error', info_webpage):
-            raise ExtractorError(
-                'Video %s is blocked from your location.' % video_id,
-                expected=True)
+        err_msg = self._html_search_regex(r'<div[^>]+class="video-error[^>]+>(.+)</div>', info_webpage, 'error message', default=None)
+        if err_msg:
+            err_msg = clean_html(err_msg)
+            if 'not available in your region' in err_msg:
+                raise ExtractorError(
+                    'Video %s is blocked from your location.' % video_id,
+                    expected=True)
+            else:
+                raise ExtractorError('Viki said: ' + err_msg)
         video_url = self._html_search_regex(
             r'<source[^>]+src="([^"]+)"', info_webpage, 'video URL')