add more info
All checks were successful
ci/woodpecker/push/build Pipeline was successful

This commit is contained in:
JMARyA 2024-12-12 22:24:24 +01:00
parent f3a1676268
commit 55de117456
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
4 changed files with 15 additions and 7 deletions

View file

@ -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';

View file

@ -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';

View file

@ -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;
});
}

View file

@ -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);