Added method to download using already extracted info

This commit is contained in:
ArabCoders 2024-03-16 18:36:13 +03:00
parent f849d77ab5
commit 395d2793aa
1 changed files with 13 additions and 8 deletions

View File

@ -3560,14 +3560,9 @@ class YoutubeDL:
return self._download_retcode
def download_with_info_file(self, info_filename):
with contextlib.closing(fileinput.FileInput(
[info_filename], mode='r',
openhook=fileinput.hook_encoded('utf-8'))) as f:
# FileInput doesn't have a read method, we can't call json.load
infos = [self.sanitize_info(info, self.params.get('clean_infojson', True))
for info in variadic(json.loads('\n'.join(f)))]
for info in infos:
def download_with_info(self, info_list):
"""Download using already extracted info_dicts."""
for info in info_list:
try:
self.__download_wrapper(self.process_ie_result)(info, download=True)
except (DownloadError, EntryNotInPlaylist, ReExtractInfo) as e:
@ -3582,6 +3577,16 @@ class YoutubeDL:
self.report_error(e)
return self._download_retcode
def download_with_info_file(self, info_filename):
"""Download using an info file."""
with contextlib.closing(fileinput.FileInput(
[info_filename], mode='r',
openhook=fileinput.hook_encoded('utf-8'))) as f:
# FileInput doesn't have a read method, we can't call json.load
infos = [self.sanitize_info(info, self.params.get('clean_infojson', True))
for info in variadic(json.loads('\n'.join(f)))]
return self.download_with_info(infos)
@staticmethod
def sanitize_info(info_dict, remove_private_keys=False):
''' Sanitize the infodict for converting to json '''