Add optional imdb_id

This commit is contained in:
Marc Plano-Lesay 2025-05-01 20:53:37 +10:00
parent 90c3fc5ee3
commit df6e3476cc
Signed by: kernald
GPG key ID: 66A41B08CC62A6CF
7 changed files with 14 additions and 0 deletions

View file

@ -0,0 +1 @@
ALTER TABLE magnets DROP COLUMN imdb_id;

View file

@ -0,0 +1,2 @@
ALTER TABLE magnets
ADD imdb_id VARCHAR;

View file

@ -18,6 +18,7 @@ use std::path::{Path, PathBuf};
pub struct SourceConfig { pub struct SourceConfig {
pub username: String, pub username: String,
pub title_filter: Option<String>, pub title_filter: Option<String>,
pub imdb_id: Option<String>,
} }
/// Main application configuration /// Main application configuration

View file

@ -99,6 +99,7 @@ impl Database {
subreddit: post.subreddit.as_str(), subreddit: post.subreddit.as_str(),
link: m, link: m,
published_at: &published_at, published_at: &published_at,
imdb_id: post.imdb_id.as_deref(),
}) })
.collect::<Vec<NewMagnet>>(); .collect::<Vec<NewMagnet>>();
@ -167,6 +168,7 @@ mod tests {
"magnet:?xt=urn:btih:test2".to_string(), "magnet:?xt=urn:btih:test2".to_string(),
], ],
timestamp: Utc::now(), timestamp: Utc::now(),
imdb_id: None,
}; };
let expected_timestamp = post_info.timestamp.naive_utc(); let expected_timestamp = post_info.timestamp.naive_utc();
@ -205,6 +207,7 @@ mod tests {
"magnet:?xt=urn:btih:test2".to_string(), "magnet:?xt=urn:btih:test2".to_string(),
], ],
timestamp: Utc::now(), timestamp: Utc::now(),
imdb_id: None,
}; };
// First insertion should succeed and insert 2 links // First insertion should succeed and insert 2 links
@ -222,6 +225,7 @@ mod tests {
"magnet:?xt=urn:btih:test3".to_string(), // New "magnet:?xt=urn:btih:test3".to_string(), // New
], ],
timestamp: Utc::now(), timestamp: Utc::now(),
imdb_id: Some("tt1234567".to_string()),
}; };
// Second insertion should succeed but only insert the new link // Second insertion should succeed but only insert the new link
@ -243,6 +247,7 @@ mod tests {
"magnet:?xt=urn:btih:test2".to_string(), // Duplicate "magnet:?xt=urn:btih:test2".to_string(), // Duplicate
], ],
timestamp: Utc::now(), timestamp: Utc::now(),
imdb_id: None,
}; };
// Third insertion should succeed but insert 0 links // Third insertion should succeed but insert 0 links

View file

@ -31,6 +31,7 @@ struct PostInfo {
magnet_links: Vec<Magnet>, magnet_links: Vec<Magnet>,
subreddit: String, subreddit: String,
timestamp: DateTime<Utc>, timestamp: DateTime<Utc>,
imdb_id: Option<String>,
} }
/// Filters posts based on a title filter pattern /// Filters posts based on a title filter pattern
@ -112,6 +113,7 @@ async fn main() -> Result<()> {
subreddit: subreddit.to_string(), subreddit: subreddit.to_string(),
magnet_links, magnet_links,
timestamp: post.created, timestamp: post.created,
imdb_id: source_config.imdb_id.clone(),
}; };
// Store the post info in the database // Store the post info in the database

View file

@ -12,6 +12,7 @@ pub struct Magnet {
pub subreddit: String, pub subreddit: String,
pub link: String, pub link: String,
pub published_at: NaiveDateTime, pub published_at: NaiveDateTime,
pub imdb_id: Option<String>,
} }
#[derive(Insertable)] #[derive(Insertable)]
@ -23,6 +24,7 @@ pub struct NewMagnet<'a> {
pub subreddit: &'a str, pub subreddit: &'a str,
pub link: &'a str, pub link: &'a str,
pub published_at: &'a NaiveDateTime, pub published_at: &'a NaiveDateTime,
pub imdb_id: Option<&'a str>,
} }
#[derive(Queryable, Selectable)] #[derive(Queryable, Selectable)]

View file

@ -8,6 +8,7 @@ diesel::table! {
subreddit -> Text, subreddit -> Text,
link -> Text, link -> Text,
published_at -> Timestamp, published_at -> Timestamp,
imdb_id -> Nullable<Text>,
} }
} }