Allow a `set` to be passed as `download_archive`

pull/4875/head
pukkandan 2 years ago
parent 1015ceeeaf
commit ae1035646a
No known key found for this signature in database
GPG Key ID: 7EEE9E1E817D0A39

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

Loading…
Cancel
Save