From 25bf4db796b7157031a543837a2fe1370101776a Mon Sep 17 00:00:00 2001 From: seanomik Date: Mon, 20 Jun 2022 22:56:55 -0400 Subject: [PATCH] TorznabClient::search now returns a Vec --- src/main.rs | 22 +++++++++++++++++----- src/torznab/client.rs | 10 +++------- src/torznab/torrent_result.rs | 14 +++++++------- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/main.rs b/src/main.rs index e1ba1c7..a71caa7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ mod config; mod torznab; use config::Config; +use lava_torrent::bencode::BencodeElem; use tracing::{info, Level, debug}; use std::path::{Path, PathBuf}; @@ -64,8 +65,6 @@ async fn main() { let torrent_files = read_torrents(config.torrents_path()).unwrap(); info!("Found {} torrents", torrent_files.len()); - //panic!("rhfhujergfre"); - // Convert the indexers to be async friendly. let mut indexers = indexers.iter() .map(|indexer| Arc::new(RwLock::new(indexer.clone()))) @@ -74,8 +73,19 @@ async fn main() { let mut indexer_handles = vec![]; for torrent_path in torrent_files.iter() { - let torrent = Arc::new(Torrent::read_from_file(torrent_path).unwrap()); - info!("{}:", torrent.name); + let torrent = Torrent::read_from_file(torrent_path).unwrap(); + + // To check for private torrents + /* if let Some(extra_info) = &torrent.extra_info_fields { + if let Some(BencodeElem::Integer(is_private)) = extra_info.get("private") { + if *is_private == 1 { + + } + } + } */ + + let torrent = Arc::new(torrent); + //info!("{}:", torrent.name); for indexer in indexers.iter() { let mut indexer = Arc::clone(indexer); @@ -87,7 +97,9 @@ async fn main() { let generic = GenericSearchParametersBuilder::new() .query(torrent.name.clone()) .build(); - client.search(SearchFunction::Search, generic).await.unwrap(); + let results = client.search(SearchFunction::Search, generic).await.unwrap(); + + //println!("Results: {:?}", results); }, None => { panic!("idfk"); diff --git a/src/torznab/client.rs b/src/torznab/client.rs index e123618..f66a559 100644 --- a/src/torznab/client.rs +++ b/src/torznab/client.rs @@ -81,7 +81,7 @@ impl TorznabClient { } /// Search for torrents. - pub async fn search(&self, func: SearchFunction, generic_params: GenericSearchParameters) -> Result<(), ClientError> { + pub async fn search(&self, func: SearchFunction, generic_params: GenericSearchParameters) -> Result, ClientError> { let param_str = format!("{}{}", func.to_params(), generic_params.to_params()); let bytes = self.request(param_str).await?; @@ -91,13 +91,9 @@ impl TorznabClient { let items = channel.into_items(); let torrents: Vec = items.iter() - .map(TorrentResult::from_item) + .map(|i| TorrentResult::from_item(i.clone())) .collect::, super::ResultError>>()?; - debug!("Found results: {:?}", torrents); - - //Torrent::from - - Ok(()) + Ok(torrents) } } \ No newline at end of file diff --git a/src/torznab/torrent_result.rs b/src/torznab/torrent_result.rs index a41cfbe..ddbf9bc 100644 --- a/src/torznab/torrent_result.rs +++ b/src/torznab/torrent_result.rs @@ -7,23 +7,23 @@ pub enum ResultError { } #[derive(Debug, Clone, PartialEq, Eq)] -pub struct TorrentResult<'a> { - name: &'a str, - link: &'a str, +pub struct TorrentResult { + name: String, + link: String, /* size: u64, categories: Vec, */ } -impl<'a> TorrentResult<'a> { - pub fn from_item(item: &'a Item) -> Result { +impl TorrentResult { + pub fn from_item(item: Item) -> Result { let name = item.title().ok_or(ResultError::MissingTitle)?; let link = item.link().ok_or(ResultError::MissingLink)?; /* let size = item.enclosure().map(|e| e.length().parse::()); let categories = item.categories().ok_or(ResultError::MissingTitle)?; */ Ok(TorrentResult { - name, - link, + name: String::from(name.clone()), + link: String::from(link), /* size, categories, */ })