1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-11-02 09:12:40 +01:00

[extractor/common] Add _download_json_handle

This commit is contained in:
Sergey M․ 2018-04-28 01:59:15 +07:00
parent c84eae4f66
commit 0fe7783ece
No known key found for this signature in database
GPG Key ID: 2C393E0F18A9236D

View File

@ -682,18 +682,30 @@ def _parse_xml(self, xml_string, video_id, transform_source=None, fatal=True):
else: else:
self.report_warning(errmsg + str(ve)) self.report_warning(errmsg + str(ve))
def _download_json(self, url_or_request, video_id, def _download_json_handle(
note='Downloading JSON metadata', self, url_or_request, video_id, note='Downloading JSON metadata',
errnote='Unable to download JSON metadata', errnote='Unable to download JSON metadata', transform_source=None,
transform_source=None, fatal=True, encoding=None, data=None, headers={}, query={}):
fatal=True, encoding=None, data=None, headers={}, query={}): """Return a tuple (JSON object, URL handle)"""
json_string = self._download_webpage( res = self._download_webpage_handle(
url_or_request, video_id, note, errnote, fatal=fatal, url_or_request, video_id, note, errnote, fatal=fatal,
encoding=encoding, data=data, headers=headers, query=query) encoding=encoding, data=data, headers=headers, query=query)
if (not fatal) and json_string is False: if res is False:
return None return res
json_string, urlh = res
return self._parse_json( 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): def _parse_json(self, json_string, video_id, transform_source=None, fatal=True):
if transform_source: if transform_source: