summary refs log tree commit diff
diff options
context:
space:
mode:
authorSergey M․ <dstftw@gmail.com>2018-04-28 01:59:15 +0700
committerSergey M․ <dstftw@gmail.com>2018-04-28 01:59:15 +0700
commit0fe7783eced5c62dbd95780c2150fd1080bd3927 (patch)
tree3342613f63757292bec6412e6f091755e5a7d0fe
parentc84eae4f66be8a22c14b852bdb01773bb3807239 (diff)
downloadyoutube-dl-0fe7783eced5c62dbd95780c2150fd1080bd3927.tar.gz
youtube-dl-0fe7783eced5c62dbd95780c2150fd1080bd3927.tar.xz
youtube-dl-0fe7783eced5c62dbd95780c2150fd1080bd3927.zip
[extractor/common] Add _download_json_handle
-rw-r--r--youtube_dl/extractor/common.py30
1 files changed, 21 insertions, 9 deletions
diff --git a/youtube_dl/extractor/common.py b/youtube_dl/extractor/common.py
index 59b9d3739..e0c3c8eb0 100644
--- a/youtube_dl/extractor/common.py
+++ b/youtube_dl/extractor/common.py
@@ -682,18 +682,30 @@ class InfoExtractor(object):
             else:
                 self.report_warning(errmsg + str(ve))
 
-    def _download_json(self, url_or_request, video_id,
-                       note='Downloading JSON metadata',
-                       errnote='Unable to download JSON metadata',
-                       transform_source=None,
-                       fatal=True, encoding=None, data=None, headers={}, query={}):
-        json_string = self._download_webpage(
+    def _download_json_handle(
+            self, url_or_request, video_id, note='Downloading JSON metadata',
+            errnote='Unable to download JSON metadata', transform_source=None,
+            fatal=True, encoding=None, data=None, headers={}, query={}):
+        """Return a tuple (JSON object, URL handle)"""
+        res = self._download_webpage_handle(
             url_or_request, video_id, note, errnote, fatal=fatal,
             encoding=encoding, data=data, headers=headers, query=query)
-        if (not fatal) and json_string is False:
-            return None
+        if res is False:
+            return res
+        json_string, urlh = res
         return self._parse_json(
-            json_string, video_id, transform_source=transform_source, fatal=fatal)
+            json_string, video_id, transform_source=transform_source,
+            fatal=fatal), urlh
+
+    def _download_json(
+            self, url_or_request, video_id, note='Downloading JSON metadata',
+            errnote='Unable to download JSON metadata', transform_source=None,
+            fatal=True, encoding=None, data=None, headers={}, query={}):
+        res = self._download_json_handle(
+            url_or_request, video_id, note=note, errnote=errnote,
+            transform_source=transform_source, fatal=fatal, encoding=encoding,
+            data=data, headers=headers, query=query)
+        return res if res is False else res[0]
 
     def _parse_json(self, json_string, video_id, transform_source=None, fatal=True):
         if transform_source: