mirror of
https://github.com/YGGverse/btracker.git
synced 2026-03-31 17:15:31 +00:00
update redb api
This commit is contained in:
parent
b4d379c650
commit
66c9e35481
2 changed files with 36 additions and 79 deletions
|
|
@ -23,6 +23,6 @@ urlencoding = "2.1"
|
|||
yggtracker-redb = "0.1"
|
||||
|
||||
[patch.crates-io]
|
||||
# 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" }
|
||||
yggtracker-redb = { git = "https://github.com/yggverse/yggtracker-redb.git", rev="9910e0b157591f2ba064aa53bd2720c247485243" }
|
||||
# yggtracker-redb = { path = "../yggtracker-redb" }
|
||||
|
|
|
|||
111
src/main.rs
111
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<PathBuf> = HashSet::with_capacity(
|
||||
let mut only_files = HashSet::with_capacity(
|
||||
config
|
||||
.preload_max_filecount
|
||||
.unwrap_or(config.index_capacity),
|
||||
);
|
||||
let mut only_files: HashSet<usize> = 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(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue