aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpukkandan <pukkandan.ytdlp@gmail.com>2022-09-08 15:03:43 +0530
committerpukkandan <pukkandan.ytdlp@gmail.com>2022-09-08 15:09:30 +0530
commitae1035646a6be09c2aed3e22eb8910f341ddacfe (patch)
tree8b24678a7739f3efe717d576ce6c748013ea1c89
parent1015ceeeaf847bce88b60fe20d08a09ab8ce7d47 (diff)
downloadhypervideo-pre-ae1035646a6be09c2aed3e22eb8910f341ddacfe.tar.lz
hypervideo-pre-ae1035646a6be09c2aed3e22eb8910f341ddacfe.tar.xz
hypervideo-pre-ae1035646a6be09c2aed3e22eb8910f341ddacfe.zip
Allow a `set` to be passed as `download_archive`
-rw-r--r--yt_dlp/YoutubeDL.py28
1 files changed, 15 insertions, 13 deletions
diff --git a/yt_dlp/YoutubeDL.py b/yt_dlp/YoutubeDL.py
index a7b881397..95fa5fb19 100644
--- a/yt_dlp/YoutubeDL.py
+++ b/yt_dlp/YoutubeDL.py
@@ -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 @@ class YoutubeDL:
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 @@ class YoutubeDL:
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,9 +3479,11 @@ class YoutubeDL:
return
vid_id = self._make_archive_id(info_dict)
assert vid_id
+
self.write_debug(f'Adding to archive: {vid_id}')
- with locked_file(fn, 'a', encoding='utf-8') as archive_file:
- archive_file.write(vid_id + '\n')
+ 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)
@staticmethod