diff --git a/Cargo.toml b/Cargo.toml index 2b8a614..5aad895 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,6 @@ urlencoding = "2.1" yggtracker-redb = "0.1" [patch.crates-io] +librqbit = { git = "https://github.com/ikatson/rqbit.git", rev="b580a9610ae7c6eaacd305a3905f7e2d3202ca69" } +yggtracker-redb = { git = "https://github.com/yggverse/yggtracker-redb.git", rev="9910e0b157591f2ba064aa53bd2720c247485243" } # yggtracker-redb = { path = "../yggtracker-redb" } -yggtracker-redb = { git = "https://github.com/YGGverse/yggtracker-redb.git", rev="ca9ebedd790b67caf64c049a26d3f45f8e6529d1" } -librqbit = { git = "https://github.com/ikatson/rqbit.git", rev="b580a9610ae7c6eaacd305a3905f7e2d3202ca69" } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 3ceb219..f47b0c6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,14 +12,12 @@ use librqbit::{ }; use peers::Peers; use preload::Preload; -use std::{ - collections::HashSet, num::NonZero, os::unix::ffi::OsStrExt, path::PathBuf, time::Duration, -}; +use std::{collections::HashSet, num::NonZero, os::unix::ffi::OsStrExt, time::Duration}; use trackers::Trackers; use url::Url; use yggtracker_redb::{ Database, - torrent::{Torrent, meta::*}, + torrent::{Image, Torrent}, }; #[tokio::main] @@ -139,20 +137,20 @@ async fn main() -> Result<()> { { Ok(r) => match r { Ok(AddTorrentResponse::Added(id, mt)) => { - let mut images: HashSet = HashSet::with_capacity( + let mut only_files = HashSet::with_capacity( config .preload_max_filecount .unwrap_or(config.index_capacity), ); - let mut only_files: HashSet = HashSet::with_capacity( + let mut images = Vec::with_capacity( config .preload_max_filecount .unwrap_or(config.index_capacity), ); mt.wait_until_initialized().await?; - let (name, files, is_private, length, bytes) = mt.with_metadata(|m| { + let bytes = mt.with_metadata(|m| { for info in &m.file_infos { - if preload.max_filecount.is_some_and(|limit| images.len() + 1 > limit) { + if preload.max_filecount.is_some_and(|limit| only_files.len() + 1 > limit) { if config.debug { println!( "\t\t\ttotal files count limit ({}) for `{i}` reached!", @@ -173,77 +171,37 @@ async fn main() -> Result<()> { } continue; } - assert!(images.insert(info.relative_filename.clone())); - assert!(only_files.insert(id)) + assert!(only_files.insert(id)); + images.push(info.relative_filename.clone()); } - let mi = m.info.info(); - ( - mi.name.as_ref().map(|s| s.to_string()), - mi.files.as_ref().map(|f| { - let mut b = Vec::with_capacity(f.len()); - let mut i = f.iter(); - for f in i.by_ref() { - b.push(File { - path: String::from_utf8( - f.path - .iter() - .enumerate() - .flat_map(|(n, b)| { - if n == 0 { - b.0.to_vec() - } else { - let mut p = vec![b'/']; - p.extend(b.0.to_vec()); - p - } - }) - .collect(), - ) - .ok(), - length: f.length, - }); - } - b.sort_by(|a, b| a.path.cmp(&b.path)); // @TODO optional - b - }), - mi.private, - mi.length, - m.torrent_bytes.clone().into() - ) + m.info_bytes.to_vec() })?; session.update_only_files(&mt, &only_files).await?; session.unpause(&mt).await?; mt.wait_until_completed().await?; - assert!( - database - .set_torrent( - &i, - Torrent { - bytes, - meta: Meta { - comment: None, // @TODO - files, - images: if images.is_empty() { - None - } else { - let mut b = Vec::with_capacity(images.len()); - for p in images { - b.push(Image { - bytes: preload.bytes(&p)?, - path: p.to_string_lossy().to_string(), - }) - } - Some(b) - }, - is_private, - name, - length, - time: chrono::Utc::now(), - }, - }, - )? - .is_none() - ); + + // persist torrent data resolved + database.set_torrent( + &i, + Torrent { + bytes, + images: if images.is_empty() { + None + } else { + Some( + images + .into_iter() + .map(|i| Image { + alt: i.to_str().map(|p| p.to_string()), + bytes: preload.bytes(&i).unwrap(), + }) + .collect(), + ) + }, + time: chrono::Utc::now(), + }, + )?; + // remove torrent from session as indexed session .delete(librqbit::api::TorrentIdOrHash::Id(id), false) @@ -254,7 +212,7 @@ async fn main() -> Result<()> { preload.clear_output_folder(&i)?; if config.debug { - println!("\t\t\tadd `{i}` to index.") + println!("\t\t\ttorrent data successfully resolved.") } } Ok(_) => panic!(), @@ -270,8 +228,7 @@ async fn main() -> Result<()> { } if config.debug { println!( - "Queue completed on {time_queue}\n\ttotal: {}\n\ttime: {} s\n\tuptime: {} s\n\tawait {} seconds to continue...", - database.torrents_total()?, + "Queue completed on {time_queue}\n\ttime: {} s\n\tuptime: {} s\n\tawait {} seconds to continue...", Local::now() .signed_duration_since(time_queue) .as_seconds_f32(),