Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
Add functions / some functionality to DB
Jules-WinnfieldX73102b7e349e
diff --git a/cyberdrop_dl/managers/db_manager.py b/cyberdrop_dl/managers/db_manager.pyindex c3edaf6de..9d04a0ad7 100644--- a/cyberdrop_dl/managers/db_manager.py+++ b/cyberdrop_dl/managers/db_manager.py@@ -13,6 +13,9 @@ class DBManager:self.db_conn: aiosqlite.Connection = field(init=False)self.db_path: Path = db_path+ self.ignore_cache: bool = False+ self.ignore_history: bool = False+self.cache_table: CacheTable = field(init=False)self.history_table: HistoryTable = field(init=False)self.temp_table: TempTable = field(init=False)@@ -25,6 +28,9 @@ class DBManager:self.history_table = HistoryTable(self.db_conn)self.temp_table = TempTable(self.db_conn)+ self.cache_table.ignore_cache = self.ignore_cache+ self.history_table.ignore_history = self.ignore_history+await self._pre_allocate()await self.cache_table.startup()diff --git a/cyberdrop_dl/managers/manager.py b/cyberdrop_dl/managers/manager.pyindex f66881b35..d1d2e83a3 100644--- a/cyberdrop_dl/managers/manager.py+++ b/cyberdrop_dl/managers/manager.py@@ -114,6 +114,8 @@ class Manager:MAX_NAME_LENGTHS['FILE'] = self.config_manager.global_settings_data['General']['max_file_name_length']MAX_NAME_LENGTHS['FOLDER'] = self.config_manager.global_settings_data['General']['max_folder_name_length']+ self.db_manager.ignore_history = self.config_manager.settings_data['Runtime_Options']['ignore_history']+ self.db_manager.ignore_cache = self.config_manager.settings_data['Runtime_Options']['ignore_cache']await self.db_manager.startup()async def close(self):diff --git a/cyberdrop_dl/utils/db/tables/history_table.py b/cyberdrop_dl/utils/db/tables/history_table.pyindex 7212f49c3..99ee5499d 100644--- a/cyberdrop_dl/utils/db/tables/history_table.py+++ b/cyberdrop_dl/utils/db/tables/history_table.py@@ -1,13 +1,42 @@import aiosqlite+from yarl import URLfrom cyberdrop_dl.utils.db.table_definitions import create_history+async def get_db_path(url: URL, referer: str = "") -> str:+ """Gets the URL path to be put into the DB and checked from the DB"""+ url_path = url.path++ if url.host and ('anonfiles' in url.host or 'bayfiles' in url.host):+ url_parts = url_path.split('/')+ url_parts.pop(0)+ if len(url_parts) > 1:+ url_parts.pop(1)+ url_path = '/' + '/'.join(url_parts)++ if referer and "e-hentai" in referer:+ url_path = url_path.split('keystamp')[0][:-1]++ return url_path++class HistoryTable:def __init__(self, db_conn: aiosqlite.Connection):self.db_conn: aiosqlite.Connection = db_conn+ self.ignore_history: bool = Falseasync def startup(self) -> None:"""Startup process for the HistoryTable"""await self.db_conn.execute(create_history)await self.db_conn.commit()++ async def check_complete(self, domain: str, url: URL) -> bool:+ """Checks whether an individual file has completed given its domain and url path"""+ if self.ignore_history:+ return False+ url_path = await get_db_path(url, domain)+ cursor = await self.db_conn.cursor()+ result = await cursor.execute("""SELECT completed FROM media WHERE domain = ? and url_path = ?""", (domain, url_path))+ sql_file_check = await result.fetchone()+ return sql_file_check and sql_file_check[0] != 0