implement 'archive-pragma' option
This commit is contained in:
@@ -760,6 +760,19 @@ Description
|
|||||||
Prefix for archive IDs.
|
Prefix for archive IDs.
|
||||||
|
|
||||||
|
|
||||||
|
extractor.*.archive-pragma
|
||||||
|
--------------------------
|
||||||
|
Type
|
||||||
|
``list`` of ``strings``
|
||||||
|
Example
|
||||||
|
``["journal_mode=WAL", "synchronous=NORMAL"]``
|
||||||
|
Description
|
||||||
|
A list of SQLite ``PRAGMA`` statements to run during archive initialization.
|
||||||
|
|
||||||
|
See `<https://www.sqlite.org/pragma.html>`__
|
||||||
|
for available ``PRAGMA`` statements and further details.
|
||||||
|
|
||||||
|
|
||||||
extractor.*.postprocessors
|
extractor.*.postprocessors
|
||||||
--------------------------
|
--------------------------
|
||||||
Type
|
Type
|
||||||
@@ -4027,9 +4040,11 @@ Description
|
|||||||
File to store IDs of executed commands in,
|
File to store IDs of executed commands in,
|
||||||
similar to `extractor.*.archive`_.
|
similar to `extractor.*.archive`_.
|
||||||
|
|
||||||
``archive-format`` and ``archive-prefix`` options,
|
``archive-format``, ``archive-prefix``, and ``archive-pragma`` options,
|
||||||
akin to `extractor.*.archive-format`_ and `extractor.*.archive-prefix`_,
|
akin to
|
||||||
are supported as well.
|
`extractor.*.archive-format`_,
|
||||||
|
`extractor.*.archive-prefix`_, and
|
||||||
|
`extractor.*.archive-pragma`_, are supported as well.
|
||||||
|
|
||||||
|
|
||||||
exec.async
|
exec.async
|
||||||
@@ -4287,9 +4302,11 @@ Description
|
|||||||
File to store IDs of generated metadata files in,
|
File to store IDs of generated metadata files in,
|
||||||
similar to `extractor.*.archive`_.
|
similar to `extractor.*.archive`_.
|
||||||
|
|
||||||
``archive-format`` and ``archive-prefix`` options,
|
``archive-format``, ``archive-prefix``, and ``archive-pragma`` options,
|
||||||
akin to `extractor.*.archive-format`_ and `extractor.*.archive-prefix`_,
|
akin to
|
||||||
are supported as well.
|
`extractor.*.archive-format`_,
|
||||||
|
`extractor.*.archive-prefix`_, and
|
||||||
|
`extractor.*.archive-pragma`_, are supported as well.
|
||||||
|
|
||||||
|
|
||||||
metadata.mtime
|
metadata.mtime
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
"#": "set global archive file for all extractors",
|
"#": "set global archive file for all extractors",
|
||||||
"archive": "~/gallery-dl/archive.sqlite3",
|
"archive": "~/gallery-dl/archive.sqlite3",
|
||||||
|
"archive-pragma": ["journal_mode=WAL", "synchronous=NORMAL"],
|
||||||
|
|
||||||
"#": "add two custom keywords into the metadata dictionary",
|
"#": "add two custom keywords into the metadata dictionary",
|
||||||
"#": "these can be used to further refine your output directories or filenames",
|
"#": "these can be used to further refine your output directories or filenames",
|
||||||
@@ -36,7 +37,7 @@
|
|||||||
|
|
||||||
"pixiv":
|
"pixiv":
|
||||||
{
|
{
|
||||||
"#": "override global archive setting for pixiv",
|
"#": "override global archive path for pixiv",
|
||||||
"archive": "~/gallery-dl/archive-pixiv.sqlite3",
|
"archive": "~/gallery-dl/archive-pixiv.sqlite3",
|
||||||
|
|
||||||
"#": "set custom directory and filename format strings for all pixiv downloads",
|
"#": "set custom directory and filename format strings for all pixiv downloads",
|
||||||
|
|||||||
@@ -436,10 +436,12 @@ class DownloadJob(Job):
|
|||||||
archive = util.expand_path(archive)
|
archive = util.expand_path(archive)
|
||||||
archive_format = (cfg("archive-prefix", extr.category) +
|
archive_format = (cfg("archive-prefix", extr.category) +
|
||||||
cfg("archive-format", extr.archive_fmt))
|
cfg("archive-format", extr.archive_fmt))
|
||||||
|
archive_pragma = (cfg("archive-pragma"))
|
||||||
try:
|
try:
|
||||||
if "{" in archive:
|
if "{" in archive:
|
||||||
archive = formatter.parse(archive).format_map(kwdict)
|
archive = formatter.parse(archive).format_map(kwdict)
|
||||||
self.archive = util.DownloadArchive(archive, archive_format)
|
self.archive = util.DownloadArchive(
|
||||||
|
archive, archive_format, archive_pragma)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
extr.log.warning(
|
extr.log.warning(
|
||||||
"Failed to open download archive at '%s' ('%s: %s')",
|
"Failed to open download archive at '%s' ('%s: %s')",
|
||||||
|
|||||||
@@ -36,7 +36,9 @@ class PostProcessor():
|
|||||||
archive = formatter.parse(archive).format_map(
|
archive = formatter.parse(archive).format_map(
|
||||||
job.pathfmt.kwdict)
|
job.pathfmt.kwdict)
|
||||||
self.archive = util.DownloadArchive(
|
self.archive = util.DownloadArchive(
|
||||||
archive, archive_format, "_archive_" + self.name)
|
archive, archive_format,
|
||||||
|
options.get("archive-pragma"),
|
||||||
|
"_archive_" + self.name)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
self.log.warning(
|
self.log.warning(
|
||||||
"Failed to open %s archive at '%s' ('%s: %s')",
|
"Failed to open %s archive at '%s' ('%s: %s')",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright 2017-2022 Mike Fährmann
|
# Copyright 2017-2023 Mike Fährmann
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License version 2 as
|
# it under the terms of the GNU General Public License version 2 as
|
||||||
@@ -831,7 +831,8 @@ class ExtendedUrl():
|
|||||||
|
|
||||||
class DownloadArchive():
|
class DownloadArchive():
|
||||||
|
|
||||||
def __init__(self, path, format_string, cache_key="_archive_key"):
|
def __init__(self, path, format_string, pragma=None,
|
||||||
|
cache_key="_archive_key"):
|
||||||
try:
|
try:
|
||||||
con = sqlite3.connect(path, timeout=60, check_same_thread=False)
|
con = sqlite3.connect(path, timeout=60, check_same_thread=False)
|
||||||
except sqlite3.OperationalError:
|
except sqlite3.OperationalError:
|
||||||
@@ -839,20 +840,23 @@ class DownloadArchive():
|
|||||||
con = sqlite3.connect(path, timeout=60, check_same_thread=False)
|
con = sqlite3.connect(path, timeout=60, check_same_thread=False)
|
||||||
con.isolation_level = None
|
con.isolation_level = None
|
||||||
|
|
||||||
self.close = con.close
|
|
||||||
self.cursor = con.cursor()
|
|
||||||
|
|
||||||
from . import formatter
|
from . import formatter
|
||||||
self.keygen = formatter.parse(format_string).format_map
|
self.keygen = formatter.parse(format_string).format_map
|
||||||
|
self.close = con.close
|
||||||
|
self.cursor = cursor = con.cursor()
|
||||||
self._cache_key = cache_key
|
self._cache_key = cache_key
|
||||||
|
|
||||||
|
if pragma:
|
||||||
|
for stmt in pragma:
|
||||||
|
cursor.execute("PRAGMA " + stmt)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.cursor.execute("CREATE TABLE IF NOT EXISTS archive "
|
cursor.execute("CREATE TABLE IF NOT EXISTS archive "
|
||||||
"(entry TEXT PRIMARY KEY) WITHOUT ROWID")
|
"(entry TEXT PRIMARY KEY) WITHOUT ROWID")
|
||||||
except sqlite3.OperationalError:
|
except sqlite3.OperationalError:
|
||||||
# fallback for missing WITHOUT ROWID support (#553)
|
# fallback for missing WITHOUT ROWID support (#553)
|
||||||
self.cursor.execute("CREATE TABLE IF NOT EXISTS archive "
|
cursor.execute("CREATE TABLE IF NOT EXISTS archive "
|
||||||
"(entry TEXT PRIMARY KEY)")
|
"(entry TEXT PRIMARY KEY)")
|
||||||
|
|
||||||
def check(self, kwdict):
|
def check(self, kwdict):
|
||||||
"""Return True if the item described by 'kwdict' exists in archive"""
|
"""Return True if the item described by 'kwdict' exists in archive"""
|
||||||
|
|||||||
Reference in New Issue
Block a user