UPNP: add size attribute

This commit is contained in:
Igor Katson 2024-09-02 12:04:50 +01:00
parent bf910d39f2
commit ff7924ff78
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
4 changed files with 14 additions and 5 deletions

View file

@ -62,7 +62,8 @@ impl TorrentFileTreeNode {
let encoded_parent_id = self.parent_id.map(|p| encode_id(p, torrent.id()));
match self.real_torrent_file_id {
Some(fid) => {
let filename = &torrent.shared().file_infos[fid].relative_filename;
let fi = &torrent.shared().file_infos[fid];
let filename = &fi.relative_filename;
// Torrent path joined with "/"
let last_url_bit = torrent
.shared()
@ -91,6 +92,7 @@ impl TorrentFileTreeNode {
fid,
last_url_bit
),
size: fi.len,
})
}
None => ItemOrContainer::Container(Container {
@ -588,7 +590,8 @@ mod tests {
parent_id: 0,
title: "f1".into(),
mime_type: None,
url: "http://127.0.0.1:9005/torrents/0/stream/0/f1".into()
url: "http://127.0.0.1:9005/torrents/0/stream/0/f1".into(),
size: 1,
}),
ItemOrContainer::Container(Container {
id: encode_id(0, 1),
@ -606,7 +609,8 @@ mod tests {
parent_id: 0,
title: "f1".into(),
mime_type: None,
url: "http://127.0.0.1:9005/torrents/0/stream/0/f1".into()
url: "http://127.0.0.1:9005/torrents/0/stream/0/f1".into(),
size: 1,
})]
);
@ -648,6 +652,7 @@ mod tests {
title: "f2".into(),
mime_type: None,
url: "http://127.0.0.1:9005/torrents/1/stream/0/d1/f2".into(),
size: 1,
})]
);
@ -659,6 +664,7 @@ mod tests {
title: "f2".into(),
mime_type: None,
url: "http://127.0.0.1:9005/torrents/1/stream/0/d1/f2".into(),
size: 1,
})]
);
}

View file

@ -26,6 +26,7 @@ async fn main() -> anyhow::Result<()> {
url: "http://192.168.0.165:3030/torrents/4/stream/0/file.mkv".to_owned(),
id: 1,
parent_id: 0,
size: 1,
})];
const HTTP_PORT: u16 = 9005;

View file

@ -1,5 +1,5 @@
<item id="{id}" parentID="{parent_id}" restricted="true">
<dc:title>{title}</dc:title>
<upnp:class>{upnp_class}</upnp:class>
<res protocolInfo="http-get:*:{mime_type}:DLNA.ORG_OP=01">{url}</res>
<res protocolInfo="http-get:*:{mime_type}:DLNA.ORG_OP=01" size="{size}">{url}</res>
</item>

View file

@ -76,6 +76,7 @@ pub mod browse {
pub title: String,
pub mime_type: Option<mime_guess::Mime>,
pub url: String,
pub size: u64,
}
#[derive(Debug, Clone, PartialEq, Eq)]
@ -103,7 +104,8 @@ pub mod browse {
mime_type = mime,
url = item.url,
upnp_class = upnp_class,
title = item.title
title = item.title,
size = item.size
))
}