From 395d2793aa6097fd463fc35c52ff94e94e4fd71a Mon Sep 17 00:00:00 2001 From: ArabCoders Date: Sat, 16 Mar 2024 18:36:13 +0300 Subject: [PATCH 1/2] Added method to download using already extracted info --- yt_dlp/YoutubeDL.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/yt_dlp/YoutubeDL.py b/yt_dlp/YoutubeDL.py index c34d97bba1..a29b9406f9 100644 --- a/yt_dlp/YoutubeDL.py +++ b/yt_dlp/YoutubeDL.py @@ -3560,14 +3560,9 @@ def download(self, url_list): 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 @@ def download_with_info_file(self, info_filename): 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 ''' From d3aec35e5b02dd2f179cf30b3e3223c33a50af49 Mon Sep 17 00:00:00 2001 From: ArabCoders Date: Sat, 16 Mar 2024 22:16:11 +0300 Subject: [PATCH 2/2] implemented requested changes --- yt_dlp/YoutubeDL.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/yt_dlp/YoutubeDL.py b/yt_dlp/YoutubeDL.py index a29b9406f9..4aca9bf9f0 100644 --- a/yt_dlp/YoutubeDL.py +++ b/yt_dlp/YoutubeDL.py @@ -3560,9 +3560,11 @@ def download(self, url_list): return self._download_retcode - def download_with_info(self, info_list): + def download_with_info(self, *info_list): """Download using already extracted info_dicts.""" - for info in info_list: + infos = [self.sanitize_info(info, self.params.get('clean_infojson', True)) + for info in info_list] + for info in infos: try: self.__download_wrapper(self.process_ie_result)(info, download=True) except (DownloadError, EntryNotInPlaylist, ReExtractInfo) as e: @@ -3583,8 +3585,7 @@ def download_with_info_file(self, info_filename): [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)))] + infos = [info for info in variadic(json.loads('\n'.join(f)))] return self.download_with_info(infos) @staticmethod