Skip to content

Commit 1555f51

Browse files
author
yggverse
committed
update preload_regex logic (None to resolve .torrent files only)
1 parent d4acf8d commit 1555f51

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

crates/crawler/src/config.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub struct Config {
6060
#[arg(long)]
6161
pub bind: Option<String>,
6262

63-
/// Preload only files match regex pattern (list only without preload by default)
63+
/// Preload content file (names) match regex pattern (.torrent file only if `None`)
6464
/// * see also `preload_max_filesize`, `preload_max_filecount` options
6565
///
6666
/// ## Example:
@@ -69,8 +69,6 @@ pub struct Config {
6969
/// ```
7070
/// --preload-regex '\.(png|gif|jpeg|jpg|webp|svg|log|nfo|txt)$'
7171
/// ```
72-
///
73-
/// * requires `storage` argument defined
7472
#[arg(long)]
7573
pub preload_regex: Option<Regex>,
7674

crates/crawler/src/main.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ async fn main() -> Result<()> {
223223
config.initial_peer.clone()
224224
}
225225
},
226-
list_only: false,
226+
list_only: preload.regex.is_none(),
227227
// the destination folder to preload files match `preload_regex`
228228
// * e.g. images for audio albums
229229
output_folder: preload.tmp_dir(&h, true)?.to_str().map(|s| s.to_string()),
@@ -234,7 +234,14 @@ async fn main() -> Result<()> {
234234
.await
235235
{
236236
Ok(r) => match r {
237+
Ok(AddTorrentResponse::ListOnly(l)) => {
238+
assert!(preload.regex.is_none());
239+
debug!("persist bytes for torrent file `{h}`...");
240+
preload.commit(&h, l.torrent_bytes.to_vec(), None)?;
241+
info!("torrent `{h}` resolved.")
242+
}
237243
Ok(AddTorrentResponse::Added(_, mt)) => {
244+
assert!(preload.regex.is_some());
238245
assert!(mt.is_paused());
239246
let mut keep_files = HashSet::with_capacity(
240247
config.preload_max_filecount.unwrap_or_default(),
@@ -264,10 +271,10 @@ async fn main() -> Result<()> {
264271
);
265272
continue;
266273
}
267-
if preload.regex.as_ref().is_none_or(|r| {
274+
if preload.regex.as_ref().is_some_and(|r| {
268275
!r.is_match(&info.relative_filename.to_string_lossy())
269276
}) {
270-
debug!("regex filter, skip file `{id}` for `{h}` at `{}`",
277+
debug!("regex filter match: skip `{id}` for `{h}` at `{}`",
271278
info.relative_filename.to_string_lossy());
272279
continue;
273280
}
@@ -302,7 +309,7 @@ async fn main() -> Result<()> {
302309
preload.commit(&h, bytes, Some(keep_files))?;
303310
info!("torrent `{h}` resolved.")
304311
}
305-
Ok(_) => panic!(),
312+
Ok(_) => unreachable!(),
306313
Err(e) => {
307314
warn!("failed to resolve torrent `{h}`: `{e}`, ban for the next queue.");
308315
assert!(ban.insert(i))

0 commit comments

Comments
 (0)