mirror of
https://github.com/YGGverse/aquatic-crawler.git
synced 2026-03-31 17:15:35 +00:00
rename infohash_file to infohash, storage to optional preload, torrent_tracker to tracker
This commit is contained in:
parent
57b246a879
commit
ee78171a12
4 changed files with 48 additions and 33 deletions
24
README.md
24
README.md
|
|
@ -38,12 +38,12 @@ Crawler for [Aquatic](https://github.com/greatest-ape/aquatic) BitTorrent tracke
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
aquatic-crawler --infohash-file /path/to/info-hash-ipv4.json\
|
aquatic-crawler --infohash /path/to/info-hash-ipv4.json\
|
||||||
--infohash-file /path/to/info-hash-ipv6.json\
|
--infohash /path/to/info-hash-ipv6.json\
|
||||||
--infohash-file /path/to/another-source.json\
|
--infohash /path/to/another-source.json\
|
||||||
--torrent-tracker udp://host1:port\
|
--tracker udp://host1:port\
|
||||||
--torrent-tracker udp://host2:port\
|
--tracker udp://host2:port\
|
||||||
--storage /path/to/storage\
|
--preload /path/to/directory\
|
||||||
--enable-tcp
|
--enable-tcp
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -62,15 +62,12 @@ aquatic-crawler --infohash-file /path/to/info-hash-ipv4.json\
|
||||||
--clear
|
--clear
|
||||||
Clear previous index collected on crawl session start
|
Clear previous index collected on crawl session start
|
||||||
|
|
||||||
--infohash-file <INFOHASH_FILE>
|
--infohash <INFOHASH>
|
||||||
Absolute filename(s) to the Aquatic tracker info-hash JSON/API
|
Absolute path(s) or URL(s) to import infohashes from the Aquatic tracker JSON/API
|
||||||
|
|
||||||
* PR#233 feature
|
* PR#233 feature
|
||||||
|
|
||||||
--storage <STORAGE>
|
--tracker <TRACKER>
|
||||||
Directory path to store preloaded data (e.g. `.torrent` files)
|
|
||||||
|
|
||||||
--torrent-tracker <TORRENT_TRACKER>
|
|
||||||
Define custom tracker(s) to preload the `.torrent` files info
|
Define custom tracker(s) to preload the `.torrent` files info
|
||||||
|
|
||||||
--initial-peer <INITIAL_PEER>
|
--initial-peer <INITIAL_PEER>
|
||||||
|
|
@ -105,6 +102,9 @@ aquatic-crawler --infohash-file /path/to/info-hash-ipv4.json\
|
||||||
--enable-upload
|
--enable-upload
|
||||||
Enable upload
|
Enable upload
|
||||||
|
|
||||||
|
--preload <PRELOAD>
|
||||||
|
Directory path to store preloaded data (e.g. `.torrent` files)
|
||||||
|
|
||||||
--preload-regex <PRELOAD_REGEX>
|
--preload-regex <PRELOAD_REGEX>
|
||||||
Preload only files match regex pattern (list only without preload by default)
|
Preload only files match regex pattern (list only without preload by default)
|
||||||
* see also `preload_max_filesize`, `preload_max_filecount` options
|
* see also `preload_max_filesize`, `preload_max_filecount` options
|
||||||
|
|
|
||||||
|
|
@ -15,19 +15,15 @@ pub struct Config {
|
||||||
#[arg(long, default_value_t = false)]
|
#[arg(long, default_value_t = false)]
|
||||||
pub clear: bool,
|
pub clear: bool,
|
||||||
|
|
||||||
/// Absolute filename(s) to the Aquatic tracker info-hash JSON/API
|
/// Absolute path(s) or URL(s) to import infohashes from the Aquatic tracker JSON/API
|
||||||
///
|
///
|
||||||
/// * PR#233 feature
|
/// * PR#233 feature
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
pub infohash_file: Vec<String>,
|
pub infohash: Vec<String>,
|
||||||
|
|
||||||
/// Directory path to store preloaded data (e.g. `.torrent` files)
|
|
||||||
#[arg(long)]
|
|
||||||
pub storage: String,
|
|
||||||
|
|
||||||
/// Define custom tracker(s) to preload the `.torrent` files info
|
/// Define custom tracker(s) to preload the `.torrent` files info
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
pub torrent_tracker: Vec<String>,
|
pub tracker: Vec<String>,
|
||||||
|
|
||||||
/// Define initial peer(s) to preload the `.torrent` files info
|
/// Define initial peer(s) to preload the `.torrent` files info
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
|
|
@ -69,6 +65,10 @@ pub struct Config {
|
||||||
#[arg(long, default_value_t = false)]
|
#[arg(long, default_value_t = false)]
|
||||||
pub enable_upload: bool,
|
pub enable_upload: bool,
|
||||||
|
|
||||||
|
/// Directory path to store preloaded data (e.g. `.torrent` files)
|
||||||
|
#[arg(long)]
|
||||||
|
pub preload: Option<String>,
|
||||||
|
|
||||||
/// Preload only files match regex pattern (list only without preload by default)
|
/// Preload only files match regex pattern (list only without preload by default)
|
||||||
/// * see also `preload_max_filesize`, `preload_max_filecount` options
|
/// * see also `preload_max_filesize`, `preload_max_filecount` options
|
||||||
///
|
///
|
||||||
|
|
|
||||||
35
src/main.rs
35
src/main.rs
|
|
@ -3,17 +3,17 @@ mod config;
|
||||||
mod debug;
|
mod debug;
|
||||||
mod index;
|
mod index;
|
||||||
mod peers;
|
mod peers;
|
||||||
|
mod preload;
|
||||||
mod rss;
|
mod rss;
|
||||||
mod storage;
|
|
||||||
mod torrent;
|
mod torrent;
|
||||||
mod trackers;
|
mod trackers;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use debug::Debug;
|
use debug::Debug;
|
||||||
use index::Index;
|
use index::Index;
|
||||||
|
use preload::Preload;
|
||||||
use rss::Rss;
|
use rss::Rss;
|
||||||
use std::{collections::HashSet, num::NonZero, time::Duration};
|
use std::{collections::HashSet, num::NonZero, path::PathBuf, time::Duration};
|
||||||
use storage::Storage;
|
|
||||||
use torrent::Torrent;
|
use torrent::Torrent;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
|
@ -30,14 +30,19 @@ async fn main() -> Result<()> {
|
||||||
let config = config::Config::parse();
|
let config = config::Config::parse();
|
||||||
let debug = Debug::init(&config.debug)?;
|
let debug = Debug::init(&config.debug)?;
|
||||||
let peers = peers::Peers::init(&config.initial_peer)?;
|
let peers = peers::Peers::init(&config.initial_peer)?;
|
||||||
let storage = Storage::init(&config.storage, config.clear)?;
|
let preload = config
|
||||||
let trackers = trackers::Trackers::init(&config.torrent_tracker)?;
|
.preload
|
||||||
|
.map(|ref p| Preload::init(p, config.clear).unwrap());
|
||||||
|
let trackers = trackers::Trackers::init(&config.tracker)?;
|
||||||
let torrent = config.export_torrents.map(|p| Torrent::init(&p).unwrap());
|
let torrent = config.export_torrents.map(|p| Torrent::init(&p).unwrap());
|
||||||
let preload_regex = config
|
let preload_regex = config
|
||||||
.preload_regex
|
.preload_regex
|
||||||
.map(|ref r| regex::Regex::new(r).unwrap());
|
.map(|ref r| regex::Regex::new(r).unwrap());
|
||||||
let session = librqbit::Session::new_with_opts(
|
let session = librqbit::Session::new_with_opts(
|
||||||
storage.path(),
|
match preload {
|
||||||
|
Some(ref p) => p.path(),
|
||||||
|
None => PathBuf::new(),
|
||||||
|
},
|
||||||
SessionOptions {
|
SessionOptions {
|
||||||
connect: Some(ConnectionOptions {
|
connect: Some(ConnectionOptions {
|
||||||
enable_tcp: config.enable_tcp,
|
enable_tcp: config.enable_tcp,
|
||||||
|
|
@ -68,7 +73,10 @@ async fn main() -> Result<()> {
|
||||||
loop {
|
loop {
|
||||||
debug.info("Index queue begin...");
|
debug.info("Index queue begin...");
|
||||||
index.refresh();
|
index.refresh();
|
||||||
for source in &config.infohash_file {
|
for source in &config.infohash {
|
||||||
|
if source.contains("://") {
|
||||||
|
todo!("URL sources yet not supported")
|
||||||
|
}
|
||||||
debug.info(&format!("Index source `{source}`..."));
|
debug.info(&format!("Index source `{source}`..."));
|
||||||
// grab latest info-hashes from this source
|
// grab latest info-hashes from this source
|
||||||
// * aquatic server may update the stats at this moment, handle result manually
|
// * aquatic server may update the stats at this moment, handle result manually
|
||||||
|
|
@ -98,7 +106,9 @@ async fn main() -> Result<()> {
|
||||||
)),
|
)),
|
||||||
// the destination folder to preload files match `only_files_regex`
|
// the destination folder to preload files match `only_files_regex`
|
||||||
// * e.g. images for audio albums
|
// * e.g. images for audio albums
|
||||||
output_folder: storage.output_folder(&i, true).ok(),
|
output_folder: preload
|
||||||
|
.as_ref()
|
||||||
|
.map(|p| p.output_folder(&i, true).unwrap()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
|
|
@ -140,7 +150,10 @@ async fn main() -> Result<()> {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
only_files_size += info.len;
|
only_files_size += info.len;
|
||||||
only_files_keep.push(storage.absolute(&i, &info.relative_filename));
|
if let Some(ref p) = preload {
|
||||||
|
only_files_keep.push(
|
||||||
|
p.absolute(&i, &info.relative_filename))
|
||||||
|
}
|
||||||
only_files.insert(id);
|
only_files.insert(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -159,7 +172,9 @@ async fn main() -> Result<()> {
|
||||||
.delete(librqbit::api::TorrentIdOrHash::Id(id), false)
|
.delete(librqbit::api::TorrentIdOrHash::Id(id), false)
|
||||||
.await?;
|
.await?;
|
||||||
// cleanup irrelevant files (see rqbit#408)
|
// cleanup irrelevant files (see rqbit#408)
|
||||||
storage.cleanup(&i, Some(only_files_keep))?;
|
if let Some(p) = &preload {
|
||||||
|
p.cleanup(&i, Some(only_files_keep))?
|
||||||
|
}
|
||||||
|
|
||||||
index.insert(i, only_files_size, name)
|
index.insert(i, only_files_size, name)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
use anyhow::{Result, bail};
|
use anyhow::{Result, bail};
|
||||||
use std::{fs, path::PathBuf, str::FromStr};
|
use std::{fs, path::PathBuf, str::FromStr};
|
||||||
|
|
||||||
pub struct Storage(PathBuf);
|
pub struct Preload(PathBuf);
|
||||||
|
|
||||||
impl Storage {
|
impl Preload {
|
||||||
pub fn init(storage: &str, clear: bool) -> Result<Self> {
|
pub fn init(directory: &str, clear: bool) -> Result<Self> {
|
||||||
let p = PathBuf::from_str(storage)?;
|
let p = PathBuf::from_str(directory)?;
|
||||||
if let Ok(t) = fs::metadata(&p) {
|
if let Ok(t) = fs::metadata(&p) {
|
||||||
if t.is_file() {
|
if t.is_file() {
|
||||||
bail!("Storage destination is not directory!");
|
bail!("Storage destination is not directory!");
|
||||||
Loading…
Add table
Add a link
Reference in a new issue