Skip to content

Bulk asynchronous downloader for multiple file hosts

Update DB to include download path.

Jules-WinnfieldX578e4afbb644
diff --git a/cyberdrop_dl/utils/database/table_definitions.py b/cyberdrop_dl/utils/database/table_definitions.py
index 365f8008f..2818a33de 100644
--- a/cyberdrop_dl/utils/database/table_definitions.py
+++ b/cyberdrop_dl/utils/database/table_definitions.py
@@ -1,6 +1,7 @@
create_history = """CREATE TABLE IF NOT EXISTS media (domain TEXT,
url_path TEXT,
referer TEXT,
+ download_path TEXT,
download_filename TEXT,
original_filename TEXT,
completed INTEGER NOT NULL,
diff --git a/cyberdrop_dl/utils/database/tables/history_table.py b/cyberdrop_dl/utils/database/tables/history_table.py
index ab4d74c03..0d02c22d5 100644
--- a/cyberdrop_dl/utils/database/tables/history_table.py
+++ b/cyberdrop_dl/utils/database/tables/history_table.py
@@ -47,7 +47,7 @@ class HistoryTable:
"""Inserts an uncompleted file into 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("""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.execute("""INSERT OR IGNORE INTO media (domain, url_path, referer, download_path, download_filename, original_filename, completed) VALUES (?, ?, ?, ?, ?, ?, ?)""", (domain, url_path, str(media_item.referer), str(media_item.download_folder), download_filename, media_item.original_filename, 0))
await self.db_conn.commit()
async def mark_complete(self, domain: str, media_item: MediaItem) -> None:
diff --git a/cyberdrop_dl/utils/transfer/transfer_v4_db.py b/cyberdrop_dl/utils/transfer/transfer_v4_db.py
index f521e9007..73fa17882 100644
--- a/cyberdrop_dl/utils/transfer/transfer_v4_db.py
+++ b/cyberdrop_dl/utils/transfer/transfer_v4_db.py
@@ -12,10 +12,16 @@ def transfer_v4_db(db_path: Path, new_db_path: Path) -> None:
new_db_connection.execute(create_history)
new_db_connection.execute(create_temp)
- query = "SELECT domain, url_path, referer, download_filename, original_filename, completed FROM media WHERE completed = 1"
+ query = "SELECT domain, url_path, referer, download_path, download_filename, original_filename, completed FROM media WHERE completed = 1"
old_data_history = old_db_connection.execute(query).fetchall()
- new_db_connection.executemany("insert into media values (?, ?, ?, ?, ?, ?)", old_data_history)
+ old_data_revised = []
+ for row in old_data_history:
+ row = list(row)
+ row[3] = str(Path(row[3]).parent)
+ old_data_revised.append(tuple(row))
+
+ new_db_connection.executemany("insert or ignore into media values (?, ?, ?, ?, ?, ?, ?)", old_data_revised)
del old_data_history
new_db_connection.commit()