Restore URLs with better filenames
This commit is contained in:
parent
8d10a8a69c
commit
ecf41de72b
1 changed files with 17 additions and 14 deletions
|
|
@ -63,12 +63,21 @@ impl TorrentFileTreeNode {
|
||||||
match self.real_torrent_file_id {
|
match self.real_torrent_file_id {
|
||||||
Some(fid) => {
|
Some(fid) => {
|
||||||
let filename = &torrent.shared().file_infos[fid].relative_filename;
|
let filename = &torrent.shared().file_infos[fid].relative_filename;
|
||||||
let extension = filename.extension().and_then(|e| e.to_str());
|
// Torrent path joined with "/"
|
||||||
// Samsung TVs don't support utf-8 in URLs, so just use the ID instead of the actual title.
|
let last_url_bit = torrent
|
||||||
let last_url_bit = match extension {
|
.shared()
|
||||||
Some(e) => format!("{encoded_id}.{e}"),
|
.info
|
||||||
None => format!("{encoded_id}"),
|
.iter_filenames_and_lengths()
|
||||||
};
|
.ok()
|
||||||
|
.and_then(|mut it| it.nth(fid))
|
||||||
|
.and_then(|(fi, _)| fi.to_vec().ok())
|
||||||
|
.map(|components| {
|
||||||
|
components
|
||||||
|
.into_iter()
|
||||||
|
.map(|c| urlencoding::encode(&c).into_owned())
|
||||||
|
.join("/")
|
||||||
|
})
|
||||||
|
.unwrap_or_else(|| self.title.clone());
|
||||||
ItemOrContainer::Item(Item {
|
ItemOrContainer::Item(Item {
|
||||||
id: encoded_id,
|
id: encoded_id,
|
||||||
parent_id: encoded_parent_id.unwrap_or_default(),
|
parent_id: encoded_parent_id.unwrap_or_default(),
|
||||||
|
|
@ -569,10 +578,7 @@ mod tests {
|
||||||
parent_id: 0,
|
parent_id: 0,
|
||||||
title: "f1".into(),
|
title: "f1".into(),
|
||||||
mime_type: None,
|
mime_type: None,
|
||||||
url: format!(
|
url: "http://127.0.0.1:9005/torrents/0/stream/0/f1".into()
|
||||||
"http://127.0.0.1:9005/torrents/0/stream/0/{}",
|
|
||||||
encode_id(0, 0)
|
|
||||||
)
|
|
||||||
}),
|
}),
|
||||||
ItemOrContainer::Container(Container {
|
ItemOrContainer::Container(Container {
|
||||||
id: encode_id(0, 1),
|
id: encode_id(0, 1),
|
||||||
|
|
@ -600,10 +606,7 @@ mod tests {
|
||||||
parent_id: encode_id(1, 1),
|
parent_id: encode_id(1, 1),
|
||||||
title: "f2".into(),
|
title: "f2".into(),
|
||||||
mime_type: None,
|
mime_type: None,
|
||||||
url: format!(
|
url: "http://127.0.0.1:9005/torrents/1/stream/0/d1/f2".into(),
|
||||||
"http://127.0.0.1:9005/torrents/1/stream/0/{}",
|
|
||||||
encode_id(2, 1)
|
|
||||||
)
|
|
||||||
})]
|
})]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue