TorznabClient::search now returns a Vec<TorrentResult>
This commit is contained in:
parent
a93fef3ac5
commit
25bf4db796
22
src/main.rs
22
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");
|
||||
|
|
|
@ -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<Vec<TorrentResult>, 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<TorrentResult> = items.iter()
|
||||
.map(TorrentResult::from_item)
|
||||
.map(|i| TorrentResult::from_item(i.clone()))
|
||||
.collect::<Result<Vec<TorrentResult>, super::ResultError>>()?;
|
||||
|
||||
debug!("Found results: {:?}", torrents);
|
||||
|
||||
//Torrent::from
|
||||
|
||||
Ok(())
|
||||
Ok(torrents)
|
||||
}
|
||||
}
|
|
@ -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<u32>, */
|
||||
}
|
||||
|
||||
impl<'a> TorrentResult<'a> {
|
||||
pub fn from_item(item: &'a Item) -> Result<Self, ResultError> {
|
||||
impl TorrentResult {
|
||||
pub fn from_item(item: Item) -> Result<Self, ResultError> {
|
||||
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::<u64>());
|
||||
let categories = item.categories().ok_or(ResultError::MissingTitle)?; */
|
||||
|
||||
Ok(TorrentResult {
|
||||
name,
|
||||
link,
|
||||
name: String::from(name.clone()),
|
||||
link: String::from(link),
|
||||
/* size,
|
||||
categories, */
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue