Add a send to Transmission action
This commit is contained in:
parent
88419cbf97
commit
3f2b002f52
10 changed files with 952 additions and 83 deletions
52
src/main.rs
52
src/main.rs
|
|
@ -1,5 +1,9 @@
|
|||
use crate::actions::transmission::{TransmissionAction, TransmissionConfig};
|
||||
use crate::db::Database;
|
||||
use crate::magnet::{extract_magnet_links, Magnet};
|
||||
use chrono::{DateTime, Utc};
|
||||
use clap::Parser;
|
||||
use clap_verbosity_flag::{InfoLevel, Verbosity};
|
||||
use color_eyre::eyre::{eyre, Result, WrapErr};
|
||||
use directories::ProjectDirs;
|
||||
use figment::providers::Env;
|
||||
|
|
@ -8,18 +12,16 @@ use figment::{
|
|||
Figment,
|
||||
};
|
||||
use figment_file_provider_adapter::FileAdapter;
|
||||
use log::{debug, warn};
|
||||
use log::{debug, info, warn};
|
||||
use multimap::MultiMap;
|
||||
use reddit_client::RedditClient;
|
||||
use regex::Regex;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::fs::create_dir_all;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use crate::db::Database;
|
||||
use crate::magnet::{extract_magnet_links, Magnet};
|
||||
use reddit_client::RedditClient;
|
||||
|
||||
mod actions;
|
||||
mod db;
|
||||
mod magnet;
|
||||
mod models;
|
||||
|
|
@ -34,6 +36,9 @@ struct SourceConfig {
|
|||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
struct Config {
|
||||
#[serde(default)]
|
||||
transmission: Option<TransmissionConfig>,
|
||||
|
||||
#[serde(default)]
|
||||
sources: HashMap<String, SourceConfig>,
|
||||
}
|
||||
|
|
@ -57,6 +62,9 @@ struct Args {
|
|||
/// Path to the database file
|
||||
#[arg(short, long)]
|
||||
db: Option<String>,
|
||||
|
||||
#[command(flatten)]
|
||||
verbose: Verbosity<InfoLevel>,
|
||||
}
|
||||
|
||||
/// Filters posts based on a title filter pattern
|
||||
|
|
@ -110,6 +118,10 @@ async fn main() -> Result<()> {
|
|||
|
||||
let args = Args::parse();
|
||||
|
||||
pretty_env_logger::formatted_timed_builder()
|
||||
.filter_level(args.verbose.log_level_filter())
|
||||
.init();
|
||||
|
||||
// Initialize database
|
||||
let db_path = match args.db {
|
||||
Some(path) => PathBuf::from(path),
|
||||
|
|
@ -168,6 +180,7 @@ async fn main() -> Result<()> {
|
|||
user_posts.insert_many(username, submissions);
|
||||
}
|
||||
|
||||
// Process sources and store magnet links
|
||||
for (source_name, source_config) in conf.sources {
|
||||
println!("\nProcessing source [{}]", source_name);
|
||||
|
||||
|
|
@ -214,5 +227,34 @@ async fn main() -> Result<()> {
|
|||
}
|
||||
}
|
||||
|
||||
// Process magnet links with Transmission if enabled
|
||||
if let Some(transmission_config) = conf.transmission {
|
||||
if transmission_config.enable {
|
||||
info!("Processing magnet links with Transmission");
|
||||
match TransmissionAction::new(&transmission_config, db).await {
|
||||
Ok(mut transmission_action) => {
|
||||
match transmission_action.process_unprocessed_magnets().await {
|
||||
Ok(count) => {
|
||||
info!(
|
||||
"Successfully processed {} magnet links with Transmission",
|
||||
count
|
||||
);
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Failed to process magnet links with Transmission: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Failed to initialize Transmission action: {}", e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
debug!("Transmission action is disabled");
|
||||
}
|
||||
} else {
|
||||
debug!("No Transmission configuration found");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue