diff --git a/migrations/2025-05-01-103700_add_imdb_id/down.sql b/migrations/2025-05-01-103700_add_imdb_id/down.sql new file mode 100644 index 0000000..4c19b7a --- /dev/null +++ b/migrations/2025-05-01-103700_add_imdb_id/down.sql @@ -0,0 +1 @@ +ALTER TABLE magnets DROP COLUMN imdb_id; diff --git a/migrations/2025-05-01-103700_add_imdb_id/up.sql b/migrations/2025-05-01-103700_add_imdb_id/up.sql new file mode 100644 index 0000000..539f8e1 --- /dev/null +++ b/migrations/2025-05-01-103700_add_imdb_id/up.sql @@ -0,0 +1,2 @@ +ALTER TABLE magnets + ADD imdb_id VARCHAR; \ No newline at end of file diff --git a/src/config.rs b/src/config.rs index c2ed482..1c33a37 100644 --- a/src/config.rs +++ b/src/config.rs @@ -18,6 +18,7 @@ use std::path::{Path, PathBuf}; pub struct SourceConfig { pub username: String, pub title_filter: Option, + pub imdb_id: Option, } /// Main application configuration diff --git a/src/db.rs b/src/db.rs index 9cd52b4..462d174 100644 --- a/src/db.rs +++ b/src/db.rs @@ -99,6 +99,7 @@ impl Database { subreddit: post.subreddit.as_str(), link: m, published_at: &published_at, + imdb_id: post.imdb_id.as_deref(), }) .collect::>(); @@ -167,6 +168,7 @@ mod tests { "magnet:?xt=urn:btih:test2".to_string(), ], timestamp: Utc::now(), + imdb_id: None, }; let expected_timestamp = post_info.timestamp.naive_utc(); @@ -205,6 +207,7 @@ mod tests { "magnet:?xt=urn:btih:test2".to_string(), ], timestamp: Utc::now(), + imdb_id: None, }; // First insertion should succeed and insert 2 links @@ -222,6 +225,7 @@ mod tests { "magnet:?xt=urn:btih:test3".to_string(), // New ], timestamp: Utc::now(), + imdb_id: Some("tt1234567".to_string()), }; // Second insertion should succeed but only insert the new link @@ -243,6 +247,7 @@ mod tests { "magnet:?xt=urn:btih:test2".to_string(), // Duplicate ], timestamp: Utc::now(), + imdb_id: None, }; // Third insertion should succeed but insert 0 links diff --git a/src/main.rs b/src/main.rs index dadbca7..818c7d6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,6 +31,7 @@ struct PostInfo { magnet_links: Vec, subreddit: String, timestamp: DateTime, + imdb_id: Option, } /// Filters posts based on a title filter pattern @@ -112,6 +113,7 @@ async fn main() -> Result<()> { subreddit: subreddit.to_string(), magnet_links, timestamp: post.created, + imdb_id: source_config.imdb_id.clone(), }; // Store the post info in the database diff --git a/src/models.rs b/src/models.rs index ace44d4..284bbcc 100644 --- a/src/models.rs +++ b/src/models.rs @@ -12,6 +12,7 @@ pub struct Magnet { pub subreddit: String, pub link: String, pub published_at: NaiveDateTime, + pub imdb_id: Option, } #[derive(Insertable)] @@ -23,6 +24,7 @@ pub struct NewMagnet<'a> { pub subreddit: &'a str, pub link: &'a str, pub published_at: &'a NaiveDateTime, + pub imdb_id: Option<&'a str>, } #[derive(Queryable, Selectable)] diff --git a/src/schema.rs b/src/schema.rs index e7dabdc..a129276 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -8,6 +8,7 @@ diesel::table! { subreddit -> Text, link -> Text, published_at -> Timestamp, + imdb_id -> Nullable, } }