Clean things up a bit
This commit is contained in:
parent
a91e243ecc
commit
3275f4890d
18 changed files with 572 additions and 249 deletions
|
|
@ -11,7 +11,7 @@ pub struct BitmagnetAction {
|
|||
}
|
||||
|
||||
impl BitmagnetAction {
|
||||
pub async fn new(config: &BitmagnetConfig) -> Result<Self> {
|
||||
pub fn new(config: &BitmagnetConfig) -> Result<Self> {
|
||||
let client = BitmagnetClient::new(config)?;
|
||||
|
||||
Ok(BitmagnetAction { client })
|
||||
|
|
@ -21,10 +21,14 @@ impl BitmagnetAction {
|
|||
#[async_trait::async_trait]
|
||||
impl Action for BitmagnetAction {
|
||||
/// Return the name of the action
|
||||
fn name(&self) -> &str {
|
||||
fn name() -> &'static str {
|
||||
"Bitmagnet"
|
||||
}
|
||||
|
||||
fn get_name(&self) -> &'static str {
|
||||
Self::name()
|
||||
}
|
||||
|
||||
/// Process all unprocessed magnet links and return the list of processed magnets
|
||||
async fn process_unprocessed_magnets(&mut self, db: &mut Database) -> Result<ProcessedMagnets> {
|
||||
let unprocessed_magnets =
|
||||
|
|
@ -45,7 +49,8 @@ impl Action for BitmagnetAction {
|
|||
{
|
||||
Ok(_) => {
|
||||
debug!(
|
||||
"Successfully submitted magnet link to Bitmagnet: {}",
|
||||
"Successfully submitted magnet link to {}: {}",
|
||||
Self::name(),
|
||||
magnet.title
|
||||
);
|
||||
debug!("Magnet link: {}", magnet.link);
|
||||
|
|
@ -53,7 +58,7 @@ impl Action for BitmagnetAction {
|
|||
processed_magnets.push(magnet);
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Failed to submit magnet link to Bitmagnet: {}", e);
|
||||
warn!("Failed to submit magnet link to {}: {}", Self::name(), e);
|
||||
failed_magnets.push(magnet);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
use crate::actions::bitmagnet::config::BitmagnetConfig;
|
||||
use chrono::{DateTime, Utc};
|
||||
use color_eyre::eyre::{eyre, Result, WrapErr};
|
||||
use log::{info, warn};
|
||||
use magnet_url::Magnet;
|
||||
use reqwest::Client;
|
||||
use serde_json::json;
|
||||
|
|
@ -95,35 +94,4 @@ impl BitmagnetClient {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Extract the info hash from a magnet link
|
||||
fn extract_info_hash(magnet: &str) -> Result<String> {
|
||||
// Magnet links typically have the format: magnet:?xt=urn:btih:<info_hash>&dn=<name>&...
|
||||
let parts: Vec<&str> = magnet.split('&').collect();
|
||||
|
||||
for part in parts {
|
||||
if part.starts_with("magnet:?xt=urn:btih:") {
|
||||
return Ok(part[20..].to_string());
|
||||
}
|
||||
if part.starts_with("xt=urn:btih:") {
|
||||
return Ok(part[12..].to_string());
|
||||
}
|
||||
}
|
||||
|
||||
Err(eyre!("Info hash not found in magnet link"))
|
||||
}
|
||||
|
||||
/// Extract the name from a magnet link
|
||||
fn extract_name(magnet: &str) -> Option<String> {
|
||||
// Magnet links typically have the format: magnet:?xt=urn:btih:<info_hash>&dn=<name>&...
|
||||
let parts: Vec<&str> = magnet.split('&').collect();
|
||||
|
||||
for part in parts {
|
||||
if part.starts_with("dn=") {
|
||||
return Some(part[3..].to_string());
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,15 @@
|
|||
use crate::app::Enableable;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Configuration for the Bitmagnet action
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct BitmagnetConfig {
|
||||
pub enable: bool,
|
||||
pub host: String,
|
||||
}
|
||||
|
||||
impl Enableable for BitmagnetConfig {
|
||||
fn is_enabled(&self) -> bool {
|
||||
self.enable
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,5 +3,4 @@ mod client;
|
|||
mod config;
|
||||
|
||||
pub use action::BitmagnetAction;
|
||||
pub use client::BitmagnetClient;
|
||||
pub use config::BitmagnetConfig;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue