Skip to content

Commit

Permalink
[archive] add 'archive-mode' option (#5255)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed May 10, 2024
1 parent 2803922 commit fd734b9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
18 changes: 17 additions & 1 deletion docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,22 @@ Description
An alternative `format string`_ to build archive IDs with.


extractor.*.archive-mode
------------------------
Type
``string``
Default
``"file"``
Description
Controls when to write `archive IDs <extractor.*.archive-format_>`__
to the archive database.

* ``"file"``: Write IDs immediately
after completing or skipping a file download.
* ``"memory"``: Keep IDs in memory
and only write them after successful job completion.


extractor.*.archive-prefix
--------------------------
Type
Expand Down Expand Up @@ -6172,7 +6188,7 @@ Description

* format
* General format string for logging messages
or a dictionary with format strings for each loglevel.
or an ``object`` with format strings for each loglevel.

In addition to the default
`LogRecord attributes <https://docs.python.org/3/library/logging.html#logrecord-attributes>`__,
Expand Down
8 changes: 7 additions & 1 deletion gallery_dl/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,8 @@ def handle_queue(self, url, kwdict):

def handle_finalize(self):
if self.archive:
if not self.status:
self.archive.finalize()
self.archive.close()

pathfmt = self.pathfmt
Expand Down Expand Up @@ -530,7 +532,11 @@ def initialize(self, kwdict=None):
if "{" in archive_path:
archive_path = formatter.parse(
archive_path).format_map(kwdict)
self.archive = archive.DownloadArchive(
if cfg("archive-mode") == "memory":
archive_cls = archive.DownloadArchiveMemory
else:
archive_cls = archive.DownloadArchive
self.archive = archive_cls(
archive_path, archive_format, archive_pragma)
except Exception as exc:
extr.log.warning(
Expand Down

0 comments on commit fd734b9

Please sign in to comment.