]> git.bitcoin.ninja Git - youtube-dl/commitdiff
[bambuser] Capture and output error message (#5478)
authorSergey M․ <dstftw@gmail.com>
Mon, 20 Apr 2015 16:35:53 +0000 (22:35 +0600)
committerSergey M․ <dstftw@gmail.com>
Mon, 20 Apr 2015 16:35:53 +0000 (22:35 +0600)
youtube_dl/extractor/bambuser.py

index 12673e766fd8fe8cee09e76c40138b13fa4e5804..d52302ebcc4a8883dbd2420c708f6d0c44a88373 100644 (file)
@@ -1,13 +1,11 @@
 from __future__ import unicode_literals
 
 import re
-import json
 import itertools
 
 from .common import InfoExtractor
-from ..compat import (
-    compat_urllib_request,
-)
+from ..compat import compat_urllib_request
+from ..utils import ExtractorError
 
 
 class BambuserIE(InfoExtractor):
@@ -39,17 +37,24 @@ class BambuserIE(InfoExtractor):
 
         info = self._download_json(
             'http://player-c.api.bambuser.com/getVideo.json?api_key=%s&vid=%s'
-            % (self._API_KEY, video_id), video_id)['result']
+            % (self._API_KEY, video_id), video_id)
+
+        error = info.get('error')
+        if error:
+            raise ExtractorError(
+                '%s returned error: %s' % (self.IE_NAME, error), expected=True)
+
+        result = info['result']
 
         return {
             'id': video_id,
-            'title': info['title'],
-            'url': info['url'],
-            'thumbnail': info.get('preview'),
-            'duration': int(info['length']),
-            'view_count': int(info['views_total']),
-            'uploader': info['username'],
-            'uploader_id': info['owner']['uid'],
+            'title': result['title'],
+            'url': result['url'],
+            'thumbnail': result.get('preview'),
+            'duration': int(result['length']),
+            'view_count': int(result['views_total']),
+            'uploader': result['username'],
+            'uploader_id': result['owner']['uid'],
         }