fix adding keys to download archive when using skip=false
This commit is contained in:
@@ -188,7 +188,7 @@ class DownloadJob(Job):
|
|||||||
|
|
||||||
# download succeeded
|
# download succeeded
|
||||||
if self.archive:
|
if self.archive:
|
||||||
self.archive.add()
|
self.archive.add(keywords)
|
||||||
|
|
||||||
def handle_urllist(self, urls, keywords):
|
def handle_urllist(self, urls, keywords):
|
||||||
"""Download the resource specified in 'url'"""
|
"""Download the resource specified in 'url'"""
|
||||||
@@ -203,7 +203,7 @@ class DownloadJob(Job):
|
|||||||
self.sleep = self.extractor.config("sleep")
|
self.sleep = self.extractor.config("sleep")
|
||||||
archive = self.extractor.config("archive")
|
archive = self.extractor.config("archive")
|
||||||
if archive:
|
if archive:
|
||||||
self.archive = util.DownloadArchive(self.extractor, archive)
|
self.archive = util.DownloadArchive(archive, self.extractor)
|
||||||
self.pathfmt.set_directory(keywords)
|
self.pathfmt.set_directory(keywords)
|
||||||
|
|
||||||
def handle_queue(self, url, keywords):
|
def handle_queue(self, url, keywords):
|
||||||
|
|||||||
@@ -390,6 +390,7 @@ class PathFormat():
|
|||||||
return open(self.partpath or self.realpath, mode)
|
return open(self.partpath or self.realpath, mode)
|
||||||
|
|
||||||
def exists(self, archive=None):
|
def exists(self, archive=None):
|
||||||
|
"""Return True if the file exists on disk or in 'archive'"""
|
||||||
if (self.has_extension and os.path.exists(self.realpath) or
|
if (self.has_extension and os.path.exists(self.realpath) or
|
||||||
archive and archive.check(self.keywords)):
|
archive and archive.check(self.keywords)):
|
||||||
if self._skipexc:
|
if self._skipexc:
|
||||||
@@ -539,23 +540,23 @@ class OAuthSession():
|
|||||||
|
|
||||||
class DownloadArchive():
|
class DownloadArchive():
|
||||||
|
|
||||||
def __init__(self, extractor, path):
|
def __init__(self, path, extractor):
|
||||||
con = sqlite3.connect(path)
|
con = sqlite3.connect(path)
|
||||||
con.isolation_level = None
|
con.isolation_level = None
|
||||||
self.cursor = con.cursor()
|
self.cursor = con.cursor()
|
||||||
self.cursor.execute("CREATE TABLE IF NOT EXISTS archive "
|
self.cursor.execute("CREATE TABLE IF NOT EXISTS archive "
|
||||||
"(entry PRIMARY KEY) WITHOUT ROWID")
|
"(entry PRIMARY KEY) WITHOUT ROWID")
|
||||||
self.keygen = (extractor.category + extractor.archive_fmt).format_map
|
self.keygen = (extractor.category + extractor.archive_fmt).format_map
|
||||||
self._key = None
|
|
||||||
|
|
||||||
def check(self, kwdict):
|
def check(self, kwdict):
|
||||||
"""Return True if item described by 'kwdict' exists in archive"""
|
"""Return True if item described by 'kwdict' exists in archive"""
|
||||||
self._key = self.keygen(kwdict)
|
key = self.keygen(kwdict)
|
||||||
self.cursor.execute(
|
self.cursor.execute(
|
||||||
"SELECT 1 FROM archive WHERE entry=? LIMIT 1", (self._key,))
|
"SELECT 1 FROM archive WHERE entry=? LIMIT 1", (key,))
|
||||||
return self.cursor.fetchone()
|
return self.cursor.fetchone()
|
||||||
|
|
||||||
def add(self):
|
def add(self, kwdict):
|
||||||
"""Add last item used in 'check()' to archive"""
|
"""Add item described by 'kwdict' to archive"""
|
||||||
|
key = self.keygen(kwdict)
|
||||||
self.cursor.execute(
|
self.cursor.execute(
|
||||||
"INSERT OR IGNORE INTO archive VALUES (?)", (self._key,))
|
"INSERT OR IGNORE INTO archive VALUES (?)", (key,))
|
||||||
|
|||||||
Reference in New Issue
Block a user