[extractor/common] Add _download_xml_handle

This commit is contained in:
Sergey M․ 2018-03-18 02:17:34 +07:00
parent 96b8b9abae
commit e0d198c18d
No known key found for this signature in database
GPG Key ID: 2C393E0F18A9236D

View File

@ -644,19 +644,31 @@ class InfoExtractor(object):
content, _ = res content, _ = res
return content return content
def _download_xml_handle(
self, url_or_request, video_id, note='Downloading XML',
errnote='Unable to download XML', transform_source=None,
fatal=True, encoding=None, data=None, headers={}, query={}):
"""Return a tuple (xml as an xml.etree.ElementTree.Element, 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 res is False:
return res
xml_string, urlh = res
return self._parse_xml(
xml_string, video_id, transform_source=transform_source,
fatal=fatal), urlh
def _download_xml(self, url_or_request, video_id, def _download_xml(self, url_or_request, video_id,
note='Downloading XML', errnote='Unable to download XML', note='Downloading XML', errnote='Unable to download XML',
transform_source=None, fatal=True, encoding=None, transform_source=None, fatal=True, encoding=None,
data=None, headers={}, query={}): data=None, headers={}, query={}):
"""Return the xml as an xml.etree.ElementTree.Element""" """Return the xml as an xml.etree.ElementTree.Element"""
xml_string = self._download_webpage( res = self._download_xml_handle(
url_or_request, video_id, note, errnote, fatal=fatal, url_or_request, video_id, note=note, errnote=errnote,
encoding=encoding, data=data, headers=headers, query=query) transform_source=transform_source, fatal=fatal, encoding=encoding,
if xml_string is False: data=data, headers=headers, query=query)
return xml_string return res if res is False else res[0]
return self._parse_xml(
xml_string, video_id, transform_source=transform_source,
fatal=fatal)
def _parse_xml(self, xml_string, video_id, transform_source=None, fatal=True): def _parse_xml(self, xml_string, video_id, transform_source=None, fatal=True):
if transform_source: if transform_source: