mirror of
https://github.com/YGGverse/aquatic-crawler.git
synced 2026-03-31 17:15:35 +00:00
implement --index-list-limit option
This commit is contained in:
parent
aa2e87cb51
commit
51ffa4d93d
3 changed files with 33 additions and 10 deletions
|
|
@ -152,6 +152,12 @@ aquatic-crawler --infohash /path/to/info-hash-ipv4.bin\
|
||||||
--index-list
|
--index-list
|
||||||
Index torrent files
|
Index torrent files
|
||||||
|
|
||||||
|
--index-list-limit <INDEX_LIST_LIMIT>
|
||||||
|
Limit torrent files quantity to index
|
||||||
|
* insert the `...` placeholder as the last item, with total size left
|
||||||
|
|
||||||
|
[default: 100]
|
||||||
|
|
||||||
--index-timeout <INDEX_TIMEOUT>
|
--index-timeout <INDEX_TIMEOUT>
|
||||||
Remove records from index older than `seconds`
|
Remove records from index older than `seconds`
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -121,6 +121,11 @@ pub struct Config {
|
||||||
#[arg(long, default_value_t = false)]
|
#[arg(long, default_value_t = false)]
|
||||||
pub index_list: bool,
|
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`
|
/// Remove records from index older than `seconds`
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
pub index_timeout: Option<i64>,
|
pub index_timeout: Option<i64>,
|
||||||
|
|
|
||||||
32
src/main.rs
32
src/main.rs
|
|
@ -188,7 +188,7 @@ async fn main() -> Result<()> {
|
||||||
(
|
(
|
||||||
m.info.name.as_ref().map(|n| n.to_string()),
|
m.info.name.as_ref().map(|n| n.to_string()),
|
||||||
size(&m.info),
|
size(&m.info),
|
||||||
list(&m.info),
|
list(&m.info, config.index_list_limit),
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
session.update_only_files(&mt, &only_files).await?;
|
session.update_only_files(&mt, &only_files).await?;
|
||||||
|
|
@ -219,7 +219,7 @@ async fn main() -> Result<()> {
|
||||||
i,
|
i,
|
||||||
0,
|
0,
|
||||||
size(&r.info),
|
size(&r.info),
|
||||||
list(&r.info),
|
list(&r.info, config.index_list_limit),
|
||||||
r.info.name.map(|n| n.to_string()),
|
r.info.name.map(|n| n.to_string()),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -312,17 +312,29 @@ fn size(info: &TorrentMetaV1Info<ByteBufOwned>) -> u64 {
|
||||||
t
|
t
|
||||||
}
|
}
|
||||||
|
|
||||||
fn list(info: &TorrentMetaV1Info<ByteBufOwned>) -> Option<Vec<(String, u64)>> {
|
fn list(info: &TorrentMetaV1Info<ByteBufOwned>, limit: usize) -> Option<Vec<(String, u64)>> {
|
||||||
info.files.as_ref().map(|files| {
|
info.files.as_ref().map(|files| {
|
||||||
files
|
let mut b = Vec::with_capacity(files.len());
|
||||||
.iter()
|
let mut i = files.iter();
|
||||||
.map(|f| {
|
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())
|
String::from_utf8(f.path.iter().flat_map(|b| b.to_vec()).collect())
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
f.length,
|
f.length,
|
||||||
)
|
))
|
||||||
})
|
} else {
|
||||||
.collect()
|
// 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
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue