Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Add dates to history #884

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cyberdrop_dl/utils/database/table_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
download_filename TEXT,
original_filename TEXT,
completed INTEGER NOT NULL,
created_at TIMESTAMP,
completed_at TIMESTAMP,
PRIMARY KEY (domain, url_path, original_filename)
);"""

Expand Down
16 changes: 12 additions & 4 deletions cyberdrop_dl/utils/database/tables/history_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async def insert_incompleted(self, domain: str, media_item: MediaItem) -> None:
(domain, media_item.album_id, url_path, str(media_item.referer)))
except IntegrityError:
await self.db_conn.execute("""DELETE FROM media WHERE domain = 'no_crawler' and url_path = ?""", (url_path,))
await self.db_conn.execute("""INSERT OR IGNORE INTO media (domain, url_path, referer, album_id, download_path, download_filename, original_filename, completed) VALUES (?, ?, ?, ?, ?, ?, ?, ?)""",
await self.db_conn.execute("""INSERT OR IGNORE INTO media (domain, url_path, referer, album_id, download_path, download_filename, original_filename, completed, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)""",
(domain, url_path, str(media_item.referer), media_item.album_id, str(media_item.download_folder), download_filename, media_item.original_filename, 0))
await self.db_conn.execute("""UPDATE media SET download_filename = ? WHERE domain = ? and url_path = ?""",
(download_filename, domain, url_path))
Expand All @@ -115,7 +115,7 @@ async def mark_complete(self, domain: str, media_item: MediaItem) -> None:
"""Mark a download as completed in the database"""
domain = await get_db_domain(domain)
url_path = await get_db_path(media_item.url, str(media_item.referer))
await self.db_conn.execute("""UPDATE media SET completed = 1 WHERE domain = ? and url_path = ?""",
await self.db_conn.execute("""UPDATE media SET completed = 1, completed_at = CURRENT_TIMESTAMP WHERE domain = ? and url_path = ?""",
(domain, url_path))
await self.db_conn.commit()

Expand Down Expand Up @@ -154,7 +154,7 @@ async def fix_bunkr_v4_entries(self) -> None:
for entry in bunkr_entries:
entry = list(entry)
entry[0] = "bunkrr"
await self.db_conn.execute("""INSERT or REPLACE INTO media VALUES (?, ?, ?, ?, ?, ?, ?, ?)""", entry)
await self.db_conn.execute("""INSERT or REPLACE INTO media VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""", entry)
await self.db_conn.commit()

await self.db_conn.execute("""DELETE FROM media WHERE domain = 'bunkr'""")
Expand All @@ -177,7 +177,7 @@ async def fix_primary_keys(self) -> None:

await self.db_conn.execute("""ALTER TABLE media_copy RENAME TO media""")
await self.db_conn.commit()

async def add_columns(self) -> None:
cursor = await self.db_conn.cursor()
result = await cursor.execute("""pragma table_info(media)""")
Expand All @@ -187,3 +187,11 @@ async def add_columns(self) -> None:
if "album_id" not in current_cols:
await self.db_conn.execute("""ALTER TABLE media ADD COLUMN album_id TEXT""")
await self.db_conn.commit()

if "created_at" not in current_cols:
await self.db_conn.execute("""ALTER TABLE media ADD COLUMN created_at TIMESTAMP""")
await self.db_conn.commit()

if "completed_at" not in current_cols:
await self.db_conn.execute("""ALTER TABLE media ADD COLUMN completed_at TIMESTAMP""")
await self.db_conn.commit()
Loading