From 55de117456d072d345d3b4560b9e5574717d1691 Mon Sep 17 00:00:00 2001 From: JMARyA Date: Thu, 12 Dec 2024 22:24:24 +0100 Subject: [PATCH] add more info --- migrations_postgres/0002_add_url_info.sql | 2 ++ migrations_sqlite/0002_add_url_info.sql | 2 ++ src/db.rs | 16 ++++++++++------ src/yt_dlp/mod.rs | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 migrations_postgres/0002_add_url_info.sql create mode 100644 migrations_sqlite/0002_add_url_info.sql diff --git a/migrations_postgres/0002_add_url_info.sql b/migrations_postgres/0002_add_url_info.sql new file mode 100644 index 0000000..017835d --- /dev/null +++ b/migrations_postgres/0002_add_url_info.sql @@ -0,0 +1,2 @@ +ALTER TABLE urls ADD COLUMN module TEXT NOT NULL DEFAULT 'unknown'; +ALTER TABLE urls ADD COLUMN name TEXT NOT NULL DEFAULT 'unknown'; diff --git a/migrations_sqlite/0002_add_url_info.sql b/migrations_sqlite/0002_add_url_info.sql new file mode 100644 index 0000000..017835d --- /dev/null +++ b/migrations_sqlite/0002_add_url_info.sql @@ -0,0 +1,2 @@ +ALTER TABLE urls ADD COLUMN module TEXT NOT NULL DEFAULT 'unknown'; +ALTER TABLE urls ADD COLUMN name TEXT NOT NULL DEFAULT 'unknown'; diff --git a/src/db.rs b/src/db.rs index 0e9bfb4..07302e3 100644 --- a/src/db.rs +++ b/src/db.rs @@ -55,9 +55,11 @@ impl DatabaseBackend { pub async fn query(&self, param: Query) -> Out { match param { - Query::InsertUrl(ref url) => { + Query::InsertUrl(ref module, ref name, ref url) => { if let Some(postgres) = self.postgres.as_ref() { - sqlx::query("INSERT INTO urls (url, timestamp) VALUES ($1, CURRENT_TIMESTAMP)") + sqlx::query("INSERT INTO urls (module, name, url, timestamp) VALUES ($1, $2, $3, CURRENT_TIMESTAMP)") + .bind(module) + .bind(name) .bind(url) .execute(postgres) .await @@ -65,8 +67,10 @@ impl DatabaseBackend { } else { if let Some(sqlite) = self.sqlite.as_ref() { sqlx::query( - "INSERT INTO urls (url, timestamp) VALUES ($1, CURRENT_TIMESTAMP)", + "INSERT INTO urls (module, name, url, timestamp) VALUES ($1, $2, $3, CURRENT_TIMESTAMP)", ) + .bind(module) + .bind(name) .bind(url) .execute(sqlite) .await @@ -136,7 +140,7 @@ impl DatabaseBackend { } pub enum Query { - InsertUrl(String), + InsertUrl(String, String, String), CheckForUrl(String), UpdateNewDownloads(String, String, String), } @@ -158,10 +162,10 @@ impl Database { } /// Insert a URL into the database as already downloaded - pub fn insert_url(&self, url: &str) { + pub fn insert_url(&self, module: &str, name: &str, url: &str) { let rt = tokio::runtime::Runtime::new().unwrap(); rt.block_on(async { - self.conn.query(Query::InsertUrl(url.to_string())).await; + self.conn.query(Query::InsertUrl(module.to_string(), name.to_string(), url.to_string())).await; }); } diff --git a/src/yt_dlp/mod.rs b/src/yt_dlp/mod.rs index 75e7eb8..5daf0c6 100644 --- a/src/yt_dlp/mod.rs +++ b/src/yt_dlp/mod.rs @@ -36,7 +36,7 @@ impl YtDlpModule { match self.download(&video_url, cwd) { Ok(()) => { // mark as downloaded - self.db.insert_url(&video_url); + self.db.insert_url(&self.name(), item, &video_url); self.db.update_new_downloads(&self.name(), item, item_url); log::info!("Downloaded \"{video_title}\""); self.webhook_notify(&video_url, &video_title, item, true);