Allow a set to be passed as download_archive

This commit is contained in:
pukkandan 2022-09-08 15:03:43 +05:30
parent 1015ceeeaf
commit ae1035646a
No known key found for this signature in database
GPG Key ID: 7EEE9E1E817D0A39

View File

@ -293,9 +293,8 @@ class YoutubeDL:
downloaded.
Videos without view count information are always
downloaded. None for no limit.
download_archive: File name of a file where all downloads are recorded.
Videos already present in the file are not downloaded
again.
download_archive: A set, or the name of a file where all downloads are recorded.
Videos already present in the file are not downloaded again.
break_on_existing: Stop the download process after attempting to download a
file that is in the archive.
break_on_reject: Stop the download process when encountering a video that
@ -723,21 +722,23 @@ def check_deprecated(param, option, suggestion):
def preload_download_archive(fn):
"""Preload the archive, if any is specified"""
archive = set()
if fn is None:
return False
return archive
elif not isinstance(fn, os.PathLike):
return fn
self.write_debug(f'Loading archive file {fn!r}')
try:
with locked_file(fn, 'r', encoding='utf-8') as archive_file:
for line in archive_file:
self.archive.add(line.strip())
archive.add(line.strip())
except OSError as ioe:
if ioe.errno != errno.ENOENT:
raise
return False
return True
return archive
self.archive = set()
preload_download_archive(self.params.get('download_archive'))
self.archive = preload_download_archive(self.params.get('download_archive'))
def warn_if_short_id(self, argv):
# short YouTube ID starting with dash?
@ -3465,8 +3466,7 @@ def _make_archive_id(self, info_dict):
return make_archive_id(extractor, video_id)
def in_download_archive(self, info_dict):
fn = self.params.get('download_archive')
if fn is None:
if not self.archive:
return False
vid_ids = [self._make_archive_id(info_dict)]
@ -3479,7 +3479,9 @@ def record_download_archive(self, info_dict):
return
vid_id = self._make_archive_id(info_dict)
assert vid_id
self.write_debug(f'Adding to archive: {vid_id}')
if isinstance(fn, os.PathLike):
with locked_file(fn, 'a', encoding='utf-8') as archive_file:
archive_file.write(vid_id + '\n')
self.archive.add(vid_id)