Skip to content

Bulk asynchronous downloader for multiple file hosts

Fix downloads creating abandoned partial files and new iterated files.

Jules-WinnfieldX5bd9ee959f39
diff --git a/cyberdrop_dl/downloader/downloader.py b/cyberdrop_dl/downloader/downloader.py
index cb67b74ba..bd47d392a 100644
--- a/cyberdrop_dl/downloader/downloader.py
+++ b/cyberdrop_dl/downloader/downloader.py
@@ -230,6 +230,7 @@ class Downloader:
complete_file = media_item.download_folder / media_item.filename
partial_file = complete_file.with_suffix(complete_file.suffix + '.part')
+ media_item.download_filename = complete_file.name
return complete_file, partial_file, proceed
async def iterate_filename(self, complete_file: Path, media_item: MediaItem) -> Tuple[Path, Path]:
@@ -253,7 +254,6 @@ class Downloader:
if media_item.current_attempt == self.manager.config_manager.global_settings_data['Rate_Limiting_Options']['download_attempts']:
return
- await self.mark_incomplete(media_item)
if not await self.check_file_can_download(media_item):
return
@@ -274,6 +274,7 @@ class Downloader:
partial_file = complete_file.with_suffix(complete_file.suffix + '.part')
complete_file, partial_file, proceed = await self.get_final_file_info(complete_file, partial_file, media_item)
+ await self.mark_incomplete(media_item)
if not proceed:
return
diff --git a/cyberdrop_dl/utils/db/tables/history_table.py b/cyberdrop_dl/utils/db/tables/history_table.py
index 42479b1db..e1220951b 100644
--- a/cyberdrop_dl/utils/db/tables/history_table.py
+++ b/cyberdrop_dl/utils/db/tables/history_table.py
@@ -50,14 +50,15 @@ class HistoryTable:
async def insert_uncompleted(self, domain: str, media_item: MediaItem) -> None:
"""Inserts an uncompleted file into the database"""
url_path = await get_db_path(media_item.url, str(media_item.referer))
- await self.db_conn.execute("""INSERT OR IGNORE INTO media (domain, url_path, referer, original_filename, completed) VALUES (?, ?, ?, ?, ?)""", (domain, url_path, str(media_item.referer), media_item.original_filename, 0))
+ download_filename = media_item.download_filename if isinstance(media_item.download_filename, str) else ""
+ await self.db_conn.execute("""INSERT OR IGNORE INTO media (domain, url_path, referer, download_filename, original_filename, completed) VALUES (?, ?, ?, ?, ?, ?)""", (domain, url_path, str(media_item.referer), download_filename, media_item.original_filename, 0))
await self.db_conn.commit()
async def mark_complete(self, domain: str, media_item: MediaItem) -> None:
"""Mark a download as completed in the database"""
url_path = await get_db_path(media_item.url, str(media_item.referer))
download_filename = media_item.download_filename if isinstance(media_item.download_filename, str) else ""
- await self.db_conn.execute("""UPDATE media SET completed = 1, download_filename = ? WHERE domain = ? and url_path = ?""", (download_filename, domain, url_path))
+ await self.db_conn.execute("""UPDATE media SET completed = 1 WHERE domain = ? and url_path = ?""", (domain, url_path))
await self.db_conn.commit()
async def check_filename_exists(self, filename: str):
@@ -71,6 +72,6 @@ class HistoryTable:
"""Returns the downloaded filename from the database"""
url_path = await get_db_path(media_item.url, str(media_item.referer))
cursor = await self.db_conn.cursor()
- result = await cursor.execute("""SELECT downloaded_filename FROM media WHERE domain = ? and url_path = ?""", (domain, url_path))
+ result = await cursor.execute("""SELECT download_filename FROM media WHERE domain = ? and url_path = ?""", (domain, url_path))
sql_file_check = await result.fetchone()
return sql_file_check[0] if sql_file_check else None