]> git.bitcoin.ninja Git - youtube-dl/commitdiff
[youku] better error handling
authortewe <tewe@github>
Sun, 15 Sep 2013 19:58:49 +0000 (21:58 +0200)
committerJaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@gmail.com>
Sat, 21 Sep 2013 18:50:31 +0000 (20:50 +0200)
blocked videos used to cause death by TypeError, now we report what the
server says

youtube_dl/extractor/youku.py

index 996d384784cb827ed4baa3304b61782542ea0767..00fa2ccb5469329685a00ada37194219c31cb79f 100644 (file)
@@ -66,6 +66,12 @@ class YoukuIE(InfoExtractor):
         self.report_extraction(video_id)
         try:
             config = json.loads(jsondata)
+            error_code = config['data'][0].get('error_code')
+            if error_code:
+                # -8 means blocked outside China.
+                error = config['data'][0].get('error')  # Chinese and English, separated by newline.
+                raise ExtractorError(error or u'Server reported error %i' % error_code,
+                    expected=True)
 
             video_title =  config['data'][0]['title']
             seed = config['data'][0]['seed']
@@ -89,6 +95,7 @@ class YoukuIE(InfoExtractor):
 
             fileid = config['data'][0]['streamfileids'][format]
             keys = [s['k'] for s in config['data'][0]['segs'][format]]
+            # segs is usually a dictionary, but an empty *list* if an error occured.
         except (UnicodeDecodeError, ValueError, KeyError):
             raise ExtractorError(u'Unable to extract info section')