Skip to content

Commit

Permalink
[archive] implement 'archive-event' option (#5784)
Browse files Browse the repository at this point in the history
With this, IDs of skipped files will no longer be written to an archive
by default. Use "archive-event": "file,skip" to restore the previous
behavior.
  • Loading branch information
mikf committed Jun 27, 2024
1 parent 51fdfbe commit ea81fa9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
19 changes: 19 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,25 @@ Description
may pose a security risk.


extractor.*.archive-event
-------------------------
Type
+ ``string``
+ ``list`` of ``strings``
Default
``"file"``
Example
* ``"file,skip"``
* ``["file", "skip"]``
Description
`Event(s) <metadata.event_>`__
for which IDs get written to an
`archive <extractor.*.archive_>`__.

Available events are:
``file``, ``skip``


extractor.*.archive-format
--------------------------
Type
Expand Down
18 changes: 14 additions & 4 deletions gallery_dl/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def handle_url(self, url, kwdict):
pathfmt.build_path()

if pathfmt.exists():
if archive:
if archive and self._archive_write_skip:
archive.add(kwdict)
self.handle_skip()
return
Expand Down Expand Up @@ -345,7 +345,7 @@ def handle_url(self, url, kwdict):
return

if not pathfmt.temppath:
if archive:
if archive and self._archive_write_skip:
archive.add(kwdict)
self.handle_skip()
return
Expand All @@ -359,7 +359,7 @@ def handle_url(self, url, kwdict):
pathfmt.finalize()
self.out.success(pathfmt.path)
self._skipcnt = 0
if archive:
if archive and self._archive_write_file:
archive.add(kwdict)
if "after" in hooks:
for callback in hooks["after"]:
Expand Down Expand Up @@ -561,6 +561,16 @@ def initialize(self, kwdict=None):
else:
extr.log.debug("Using download archive '%s'", archive_path)

events = cfg("archive-event")
if events is None:
self._archive_write_file = True
self._archive_write_skip = False
else:
if isinstance(events, str):
events = events.split(",")
self._archive_write_file = ("file" in events)
self._archive_write_skip = ("skip" in events)

skip = cfg("skip", True)
if skip:
self._skipexc = None
Expand Down Expand Up @@ -676,7 +686,7 @@ def handle_url(self, url, kwdict):
kwdict["extension"] = "jpg"
if self.sleep:
self.extractor.sleep(self.sleep(), "download")
if self.archive:
if self.archive and self._archive_write_skip:
self.archive.add(kwdict)
self.out.skip(self.pathfmt.build_filename(kwdict))

Expand Down

0 comments on commit ea81fa9

Please sign in to comment.