Add access to new fields
This commit is contained in:
parent
98f011673e
commit
18755d8971
7 changed files with 78 additions and 70 deletions
|
|
@ -533,23 +533,23 @@ fn make_torrent_details(
|
|||
output_folder: String,
|
||||
) -> Result<TorrentDetailsResponse> {
|
||||
let files = info
|
||||
.iter_filenames_and_lengths()
|
||||
.iter_file_details()
|
||||
.context("error iterating filenames and lengths")?
|
||||
.enumerate()
|
||||
.map(|(idx, (filename_it, length))| {
|
||||
let name = match filename_it.to_string() {
|
||||
.map(|(idx, d)| {
|
||||
let name = match d.filename.to_string() {
|
||||
Ok(s) => s,
|
||||
Err(err) => {
|
||||
warn!("error reading filename: {:?}", err);
|
||||
"<INVALID NAME>".to_string()
|
||||
}
|
||||
};
|
||||
let components = filename_it.to_vec().unwrap_or_default();
|
||||
let components = d.filename.to_vec().unwrap_or_default();
|
||||
let included = only_files.map(|o| o.contains(&idx)).unwrap_or(true);
|
||||
TorrentDetailsResponseFile {
|
||||
name,
|
||||
components,
|
||||
length,
|
||||
length: d.len,
|
||||
included,
|
||||
}
|
||||
})
|
||||
|
|
@ -568,10 +568,11 @@ fn torrent_file_mime_type(
|
|||
info: &TorrentMetaV1Info<ByteBufOwned>,
|
||||
file_idx: usize,
|
||||
) -> Result<&'static str> {
|
||||
info.iter_filenames_and_lengths()?
|
||||
info.iter_file_details()?
|
||||
.nth(file_idx)
|
||||
.and_then(|(f, _)| {
|
||||
f.iter_components()
|
||||
.and_then(|d| {
|
||||
d.filename
|
||||
.iter_components()
|
||||
.last()
|
||||
.and_then(|r| r.ok())
|
||||
.and_then(|s| mime_guess::from_path(s).first_raw())
|
||||
|
|
|
|||
|
|
@ -181,7 +181,8 @@ impl<'a> FileOps<'a> {
|
|||
|
||||
let mut piece_remaining_bytes = piece_length as usize;
|
||||
|
||||
for (file_idx, (name, file_len)) in self.torrent.iter_filenames_and_lengths()?.enumerate() {
|
||||
for (file_idx, file_details) in self.torrent.iter_file_details()?.enumerate() {
|
||||
let file_len = file_details.len;
|
||||
if absolute_offset > file_len {
|
||||
absolute_offset -= file_len;
|
||||
continue;
|
||||
|
|
@ -205,7 +206,10 @@ impl<'a> FileOps<'a> {
|
|||
to_read_in_file,
|
||||
)
|
||||
.with_context(|| {
|
||||
format!("error reading {to_read_in_file} bytes, file_id: {file_idx} (\"{name:?}\")")
|
||||
format!(
|
||||
"error reading {to_read_in_file} bytes, file_id: {file_idx} (\"{:?}\")",
|
||||
file_details.filename
|
||||
)
|
||||
})?;
|
||||
|
||||
piece_remaining_bytes -= to_read_in_file;
|
||||
|
|
@ -292,7 +296,8 @@ impl<'a> FileOps<'a> {
|
|||
let mut buf = data.block.as_ref();
|
||||
let mut absolute_offset = self.lengths.chunk_absolute_offset(chunk_info);
|
||||
|
||||
for (file_idx, (name, file_len)) in self.torrent.iter_filenames_and_lengths()?.enumerate() {
|
||||
for (file_idx, file_details) in self.torrent.iter_file_details()?.enumerate() {
|
||||
let file_len = file_details.len;
|
||||
if absolute_offset > file_len {
|
||||
absolute_offset -= file_len;
|
||||
continue;
|
||||
|
|
@ -313,7 +318,12 @@ impl<'a> FileOps<'a> {
|
|||
);
|
||||
self.files
|
||||
.pwrite_all(file_idx, absolute_offset, &buf[..to_write])
|
||||
.with_context(|| format!("error writing to file {file_idx} (\"{name:?}\")"))?;
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"error writing to file {file_idx} (\"{:?}\")",
|
||||
file_details.filename
|
||||
)
|
||||
})?;
|
||||
buf = &buf[to_write..];
|
||||
if buf.is_empty() {
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -153,10 +153,10 @@ impl HttpApi {
|
|||
let mut playlist_items = handle
|
||||
.shared()
|
||||
.info
|
||||
.iter_filenames_and_lengths()?
|
||||
.iter_file_details()?
|
||||
.enumerate()
|
||||
.filter_map(|(file_idx, (filename, _))| {
|
||||
let filename = filename.to_vec().ok()?.join("/");
|
||||
.filter_map(|(file_idx, file_details)| {
|
||||
let filename = file_details.filename.to_vec().ok()?.join("/");
|
||||
let is_playable = mime_guess::from_path(&filename)
|
||||
.first()
|
||||
.map(|mime| {
|
||||
|
|
|
|||
|
|
@ -156,8 +156,9 @@ fn compute_only_files_regex<ByteBuf: AsRef<[u8]>>(
|
|||
) -> anyhow::Result<Vec<usize>> {
|
||||
let filename_re = regex::Regex::new(filename_re).context("filename regex is incorrect")?;
|
||||
let mut only_files = Vec::new();
|
||||
for (idx, (filename, _)) in torrent.iter_filenames_and_lengths()?.enumerate() {
|
||||
let full_path = filename
|
||||
for (idx, fd) in torrent.iter_file_details()?.enumerate() {
|
||||
let full_path = fd
|
||||
.filename
|
||||
.to_pathbuf()
|
||||
.with_context(|| format!("filename of file {idx} is not valid utf8"))?;
|
||||
if filename_re.is_match(full_path.to_str().unwrap()) {
|
||||
|
|
@ -191,12 +192,12 @@ fn compute_only_files(
|
|||
}
|
||||
(None, Some(filename_re)) => {
|
||||
let only_files = compute_only_files_regex(info, &filename_re)?;
|
||||
for (idx, (filename, _)) in info.iter_filenames_and_lengths()?.enumerate() {
|
||||
for (idx, fd) in info.iter_file_details()?.enumerate() {
|
||||
if !only_files.contains(&idx) {
|
||||
continue;
|
||||
}
|
||||
if !list_only {
|
||||
info!(?filename, "will download");
|
||||
info!(filename=?fd.filename, "will download");
|
||||
}
|
||||
}
|
||||
Ok(Some(only_files))
|
||||
|
|
@ -1043,8 +1044,8 @@ impl Session {
|
|||
info: &TorrentMetaV1Info<ByteBufOwned>,
|
||||
) -> anyhow::Result<Option<PathBuf>> {
|
||||
let files = info
|
||||
.iter_filenames_and_lengths()?
|
||||
.map(|(f, l)| Ok((f.to_pathbuf()?, l)))
|
||||
.iter_file_details()?
|
||||
.map(|fd| Ok((fd.filename.to_pathbuf()?, fd.len)))
|
||||
.collect::<anyhow::Result<Vec<(PathBuf, u64)>>>()?;
|
||||
if files.len() < 2 {
|
||||
return Ok(None);
|
||||
|
|
@ -1145,7 +1146,7 @@ impl Session {
|
|||
.map(|fd| {
|
||||
Ok::<_, anyhow::Error>(FileInfo {
|
||||
relative_filename: fd.details.filename.to_pathbuf()?,
|
||||
offset_in_torrent: fd.details.offset,
|
||||
offset_in_torrent: fd.offset,
|
||||
piece_range: fd.pieces,
|
||||
len: fd.details.len,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -68,10 +68,10 @@ impl TorrentFileTreeNode {
|
|||
let last_url_bit = torrent
|
||||
.shared()
|
||||
.info
|
||||
.iter_filenames_and_lengths()
|
||||
.iter_file_details()
|
||||
.ok()
|
||||
.and_then(|mut it| it.nth(fid))
|
||||
.and_then(|(fi, _)| fi.to_vec().ok())
|
||||
.and_then(|fd| fd.filename.to_vec().ok())
|
||||
.map(|components| {
|
||||
components
|
||||
.into_iter()
|
||||
|
|
@ -111,10 +111,10 @@ struct TorrentFileTree {
|
|||
}
|
||||
|
||||
fn is_single_file_at_root(info: &TorrentMetaV1Info<ByteBufOwned>) -> bool {
|
||||
info.iter_filenames_and_lengths()
|
||||
info.iter_file_details()
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.flat_map(|(f, _)| f.iter_components())
|
||||
.flat_map(|fd| fd.filename.iter_components())
|
||||
.nth(1)
|
||||
.is_none()
|
||||
}
|
||||
|
|
@ -123,10 +123,10 @@ impl TorrentFileTree {
|
|||
fn build(torent_id: TorrentId, info: &TorrentMetaV1Info<ByteBufOwned>) -> anyhow::Result<Self> {
|
||||
if is_single_file_at_root(info) {
|
||||
let filename = info
|
||||
.iter_filenames_and_lengths()?
|
||||
.iter_file_details()?
|
||||
.next()
|
||||
.context("bug")?
|
||||
.0
|
||||
.filename
|
||||
.iter_components()
|
||||
.last()
|
||||
.context("bug")??;
|
||||
|
|
@ -159,8 +159,8 @@ impl TorrentFileTree {
|
|||
|
||||
let mut name_cache = HashMap::new();
|
||||
|
||||
for (fid, (fi, _)) in info.iter_filenames_and_lengths()?.enumerate() {
|
||||
let components = match fi.to_vec() {
|
||||
for (fid, fd) in info.iter_file_details()?.enumerate() {
|
||||
let components = match fd.filename.to_vec() {
|
||||
Ok(v) => v,
|
||||
Err(_) => continue,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue