This commit is contained in:
parent
f3a1676268
commit
55de117456
4 changed files with 15 additions and 7 deletions
2
migrations_postgres/0002_add_url_info.sql
Normal file
2
migrations_postgres/0002_add_url_info.sql
Normal 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';
|
2
migrations_sqlite/0002_add_url_info.sql
Normal file
2
migrations_sqlite/0002_add_url_info.sql
Normal 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';
|
16
src/db.rs
16
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;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue