Duplicate Detection#
The duplicate detection system prevents re-downloading already-downloaded works (videos, image sets, live recordings). It combines two independent checks โ a strict ID-based check against a SQLite database and a lenient file-existence check โ controlled by a runtime Record toggle.
Key Components#
| Component | File | Role |
|---|---|---|
DownloadRecorder | src/manager/recorder.py | Async wrapper gating all ID lookups/writes behind the switch flag |
Database | src/manager/database.py | aiosqlite-backed store owning the download_data table |
Downloader | src/downloader/download.py | Runs both guards before queuing any download |
The Record Toggle#
The Record setting is stored in the config_data table of DouK-Downloader.db, defaulting to 1 (enabled) . When switch=False, every call to has_id / update_id / delete_id on DownloadRecorder is a no-op .
Users toggle recording at runtime via "ๅฏ็จ / ็ฆ็จไฝๅไธ่ฝฝ่ฎฐๅฝ" in the main menu. A companion menu entry, "ๅ ้คไฝๅไธ่ฝฝ่ฎฐๅฝ", lets users delete specific IDs or clear all records .
Important: When
Recordis disabled, the system falls back to filename-based file-existence checks only. If a creator changes a work's title/tags (which alters the filename), the file-existence check will miss it and re-download the work.
SQLite Storage#
download_data is a single-column table: ID TEXT PRIMARY KEY . The three operations exposed by DownloadRecorder:
has_id(id_)โ queriesDatabase.has_download_data(id_)โSELECT โฆ WHERE ID=?, returnsboolupdate_id(id_)โ callsDatabase.write_download_data(id_)โINSERT OR IGNOREafter a successful savedelete_id(id_)/delete_ids(ids)โ removes specific IDs or all records on demand
IDs are 19-digit integers matching \d{19}, corresponding to the platform's work ID field .
The database file is DouK-Downloader.db, stored at the project root. A compatibility migration moves the file if it exists in the parent directory from an older installation .
Two-Path Skip Logic#
Downloader runs two guards:
is_downloaded(id_) โ recorder.has_id(id_) โ DB lookup
is_exists(path) โ path.exists() โ filesystem check
is_downloaded(id_)โ strict/ID-based path: skips immediately if the ID was recorded in a prior session, regardless of whether the file is on disk.is_exists(path)โ lenient/file-existence path: catches cases where a file was manually placed or the DB record was lost.is_skip(id_, path)โ combines both: returnsTrueif either condition holds. Used for video items.
For image set items, the two checks run in sequence inside the per-image loop: the ID check short-circuits the entire set, while the file-existence check skips individual frames .
Known gap: Cover images and music use only is_exists(path) โ they lack the ID-based database check. This means a cover can be re-downloaded if the filename changes between runs (e.g., creator edits the title), while the associated video would be correctly skipped via the DB record.
ID Write / Rollback#
The work ID is written to the database only after the file is fully saved to disk inside download_file():
- On success:
recorder.update_id(id_)is called post-save_file. - On interrupt:
recorder.delete_id(id_)removes any partially-recorded ID, keeping the store consistent for a future retry.
Primary Source References#
DownloadRecorderโ public async API (has_id,update_id,delete_id,delete_ids)Downloader.is_downloaded/is_exists/is_skipโ pre-download gateDownloader.download_fileโ post-saveupdate_idand interruptdelete_id- Issue #776 โ behaviour when
Recordis disabled and filenames change - Issue #789 โ cover/music lacking ID-based skip, video vs. cover asymmetry