diff --git a/README.md b/README.md index 5fdebca..0f31512 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,12 @@ aquatic-crawler --infohash /path/to/info-hash-ipv4.bin\ --index-list Index torrent files + --index-list-limit + Limit torrent files quantity to index + * insert the `...` placeholder as the last item, with total size left + + [default: 100] + --index-timeout Remove records from index older than `seconds` diff --git a/src/config.rs b/src/config.rs index 61b3fd1..14ab5a9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -121,6 +121,11 @@ pub struct Config { #[arg(long, default_value_t = false)] pub index_list: bool, + /// Limit torrent files quantity to index + /// * insert the `...` placeholder as the last item, with total size left + #[arg(long, default_value_t = 100)] + pub index_list_limit: usize, + /// Remove records from index older than `seconds` #[arg(long)] pub index_timeout: Option, diff --git a/src/main.rs b/src/main.rs index fc4f3e4..8aa2da6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -188,7 +188,7 @@ async fn main() -> Result<()> { ( m.info.name.as_ref().map(|n| n.to_string()), size(&m.info), - list(&m.info), + list(&m.info, config.index_list_limit), ) })?; session.update_only_files(&mt, &only_files).await?; @@ -219,7 +219,7 @@ async fn main() -> Result<()> { i, 0, size(&r.info), - list(&r.info), + list(&r.info, config.index_list_limit), r.info.name.map(|n| n.to_string()), ) } @@ -312,17 +312,29 @@ fn size(info: &TorrentMetaV1Info) -> u64 { t } -fn list(info: &TorrentMetaV1Info) -> Option> { +fn list(info: &TorrentMetaV1Info, limit: usize) -> Option> { info.files.as_ref().map(|files| { - files - .iter() - .map(|f| { - ( + let mut b = Vec::with_capacity(files.len()); + let mut i = files.iter(); + let mut t = 0; + while let Some(f) = i.next() { + t += 1; + if t < limit { + b.push(( String::from_utf8(f.path.iter().flat_map(|b| b.to_vec()).collect()) .unwrap_or_default(), f.length, - ) - }) - .collect() + )) + } else { + // limit reached: count sizes left and use placeholder as the last item name + let mut l = 0; + while let Some(f) = i.next() { + l += f.length + } + b.push(("...".to_string(), l)); + break; + } + } + b }) }