Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
refactor: remove `--skip-referer-seen-before` option (#1619)
NTFSvolume5e2f94453789
diff --git a/cyberdrop_dl/config/config_model.py b/cyberdrop_dl/config/config_model.pyindex ed0a100c4..38b81b89c 100755--- a/cyberdrop_dl/config/config_model.py+++ b/cyberdrop_dl/config/config_model.py@@ -52,7 +52,6 @@ class DownloadOptions(BaseModel):separate_posts_format: NonEmptyStr = "{default}"separate_posts: bool = Falseskip_download_mark_completed: bool = False- skip_referer_seen_before: bool = Falsemaximum_thread_depth: NonNegativeInt = 0maximum_thread_folder_depth: NonNegativeInt | None = Nonediff --git a/cyberdrop_dl/crawlers/crawler.py b/cyberdrop_dl/crawlers/crawler.pyindex 0e4c1c089..f1f49aff7 100644--- a/cyberdrop_dl/crawlers/crawler.py+++ b/cyberdrop_dl/crawlers/crawler.py@@ -490,14 +490,6 @@ class Crawler(ABC):@finalasync def check_skip_by_config(self, media_item: MediaItem) -> bool:- if (- self.manager.config.download_options.skip_referer_seen_before- and await self.manager.db_manager.temp_referer_table.check_referer(media_item.referer)- ):- log(f"Download skip {media_item.url} as referer has been seen before", 10)- return True-- assert media_item.url.hostmedia_host = media_item.url.hostif (hosts := self.manager.config.ignore_options.skip_hosts) and any(host in media_host for host in hosts):diff --git a/cyberdrop_dl/database/__init__.py b/cyberdrop_dl/database/__init__.pyindex dcceb80a8..a793aba58 100644--- a/cyberdrop_dl/database/__init__.py+++ b/cyberdrop_dl/database/__init__.py@@ -4,7 +4,7 @@ from typing import TYPE_CHECKINGimport aiosqlite-from .tables import HashTable, HistoryTable, SchemaVersionTable, TempRefererTable+from .tables import HashTable, HistoryTable, SchemaVersionTableif TYPE_CHECKING:from pathlib import Path@@ -17,7 +17,6 @@ class Database:self.ignore_history = ignore_historyself.history_table: HistoryTableself.hash_table: HashTable- self.temp_referer_table: TempRefererTableasync def startup(self) -> None:"""Startup process for the DBManager."""@@ -25,18 +24,15 @@ class Database:self._db_conn.row_factory = aiosqlite.Rowself.history_table = HistoryTable(self)self.hash_table = HashTable(self)- self.temp_referer_table = TempRefererTable(self)self._schema_versions = SchemaVersionTable(self)await self._pre_allocate()await self.history_table.startup()await self.hash_table.startup()- await self.temp_referer_table.startup()await self._schema_versions.startup()async def close(self) -> None:"""Close the DBManager."""- await self.temp_referer_table.sql_drop_temp_referers()await self._db_conn.close()async def _pre_allocate(self) -> None:diff --git a/cyberdrop_dl/database/tables/__init__.py b/cyberdrop_dl/database/tables/__init__.pyindex 63dd2e9ae..54a6663e3 100644--- a/cyberdrop_dl/database/tables/__init__.py+++ b/cyberdrop_dl/database/tables/__init__.py@@ -1,6 +1,5 @@from .hash import HashTablefrom .history import HistoryTablefrom .schema import SchemaVersionTable-from .temp_referer import TempRefererTable-__all__ = ["HashTable", "HistoryTable", "SchemaVersionTable", "TempRefererTable"]+__all__ = ["HashTable", "HistoryTable", "SchemaVersionTable"]diff --git a/cyberdrop_dl/database/tables/definitions.py b/cyberdrop_dl/database/tables/definitions.pyindex a40eedc33..dbc59edae 100644--- a/cyberdrop_dl/database/tables/definitions.py+++ b/cyberdrop_dl/database/tables/definitions.py@@ -26,8 +26,6 @@ create_fixed_history = """CREATE TABLE IF NOT EXISTS media_copy (PRIMARY KEY (domain, url_path, original_filename));"""-create_temp_referer = """CREATE TABLE IF NOT EXISTS temp_referer (referer TEXT);"""-create_schema_version = """CREATE TABLE IF NOT EXISTS schema_version (version VARCHAR(50) NOT NULL PRIMARY KEY,diff --git a/cyberdrop_dl/database/tables/temp_referer.py b/cyberdrop_dl/database/tables/temp_referer.pydeleted file mode 100644index b222a7e43..000000000--- a/cyberdrop_dl/database/tables/temp_referer.py+++ /dev/null@@ -1,78 +0,0 @@-from __future__ import annotations--from typing import TYPE_CHECKING--from .definitions import create_temp_referer--if TYPE_CHECKING:- import aiosqlite- from yarl import URL-- from cyberdrop_dl.data_structures.url_objects import AbsoluteHttpURL- from cyberdrop_dl.database import Database---class TempRefererTable:- def __init__(self, database: Database) -> None:- self._database = database-- @property- def db_conn(self) -> aiosqlite.Connection:- return self._database._db_conn-- async def startup(self) -> None:- """Startup process for the TempRefererTable."""- await self.db_conn.execute(create_temp_referer)- await self.db_conn.commit()-- async def get_temp_referers(self) -> list[str]:- """Gets the list of temp referrer."""- query = "SELECT referer FROM temp_referer;"- cursor = await self.db_conn.execute(query)- rows = await cursor.fetchall()- return [row[0] for row in rows]-- async def sql_insert_temp_referer(self, referer: str) -> None:- """Inserts a temp referer into the temp_referers table."""- query = "INSERT OR IGNORE INTO temp_referer VALUES (?)"- await self.db_conn.execute(query, (referer,))- await self.db_conn.commit()-- async def sql_purge_temp_referers(self) -> None:- """Delete all records in temp_referers table."""- query = "DELETE FROM temp_referer;"- await self.db_conn.execute(query)- await self.db_conn.commit()-- async def sql_drop_temp_referers(self) -> None:- """Delete temp_referers table."""- query = "DROP TABLE IF EXISTS temp_referer"- await self.db_conn.execute(query)- await self.db_conn.commit()-- async def check_referer(self, referer: AbsoluteHttpURL) -> bool:- """Checks whether an individual referer url has already been recorded in the database."""- if self._database.ignore_history:- return False-- referer_str = str(referer)-- # TODO: This logic is broken- query = "SELECT url_path FROM media WHERE referer = ?"- cursor = await self.db_conn.execute(query, (referer_str,))- in_media_table = await cursor.fetchone()- in_temp_referer = await self._check_temp_referer(referer)- if not in_media_table:- await self.sql_insert_temp_referer(referer_str)- return False-- return not in_temp_referer-- async def _check_temp_referer(self, referer: URL) -> bool:- """Checks whether an individual referer url has already been recorded in this session."""- if self._database.ignore_history:- return False-- query = "SELECT referer FROM temp_referer WHERE referer = ?"- cursor = await self.db_conn.execute(query, (str(referer),))- return bool(await cursor.fetchone())diff --git a/docs/reference/configuration-options/settings/download_options.md b/docs/reference/configuration-options/settings/download_options.mdindex d6c7191ed..e955085df 100644--- a/docs/reference/configuration-options/settings/download_options.md+++ b/docs/reference/configuration-options/settings/download_options.md@@ -222,14 +222,6 @@ You can use any valid format string supported by python, with the following restSetting this to `true` will skip the download process for every file and mark them as downloaded in the database.-## `skip_referer_seen_before`--| Type | Default |-| ------ | ------- |-| `bool` | `false` |--Setting this to `true` will skip downloading files from any referer that have been scraped before. The file (s) will always be skipped, regardless of whether the referer was successfully scraped or not-## `maximum_thread_depth`| Type | Default |