From 84a52a92567fde7cfcda9f9a02e00c6e8ec5a15d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Mon, 29 Jan 2018 22:13:06 +0100 Subject: [PATCH] add DownloadArchive class --- gallery_dl/extractor/common.py | 1 + gallery_dl/util.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/gallery_dl/extractor/common.py b/gallery_dl/extractor/common.py index 36037387..84c02dd8 100644 --- a/gallery_dl/extractor/common.py +++ b/gallery_dl/extractor/common.py @@ -28,6 +28,7 @@ class Extractor(): categorytransfer = False directory_fmt = ["{category}"] filename_fmt = "{name}.{extension}" + archive_fmt = "" cookiedomain = "" def __init__(self): diff --git a/gallery_dl/util.py b/gallery_dl/util.py index 931b196d..c72c9114 100644 --- a/gallery_dl/util.py +++ b/gallery_dl/util.py @@ -19,6 +19,7 @@ import shutil import string import _string import hashlib +import sqlite3 import datetime import itertools import urllib.parse @@ -517,3 +518,30 @@ class OAuthSession(): @staticmethod def quote(value, _=None, encoding=None, errors=None): return urllib.parse.quote(value, "~", encoding, errors) + + +class DownloadArchive(): + + def __init__(self, extractor, path): + con = sqlite3.connect(path) + con.isolation_level = None + self.cursor = con.cursor() + self.cursor.execute("CREATE TABLE IF NOT EXISTS archive " + "(entry PRIMARY KEY) WITHOUT ROWID") + self.keygen = ( + extractor.category + + (extractor.archive_fmt or extractor.filename_fmt) + ).format_map + self._key = None + + def check(self, kwdict): + """Return True if item described by 'kwdict' exists in archive""" + self._key = self.keygen(kwdict) + self.cursor.execute( + "SELECT 1 FROM archive WHERE entry=? LIMIT 1", (self._key,)) + return self.cursor.fetchone() + + def add(self): + """Add last item used in 'check()' to archive""" + self.cursor.execute( + "INSERT OR IGNORE INTO archive VALUES (?)", (self._key,))