fix: dl function

This commit is contained in:
VC
2023-09-29 17:59:07 +02:00
parent 65cbb89eb5
commit f2a7119a11

View File

@@ -46,19 +46,17 @@ pub fn get_latest_video(u: &str) -> Result<PeerTubeVideo, Box<dyn Error>> {
/// This returns the direct download URL for with the maximum resolution
pub fn get_max_resolution_dl(p: &Vec<PeerTubeVideoStreamingPlaylists>) -> String {
let max_res = p[0].files.iter().fold(std::u16::MIN, |a,b| a.resolution.id.max(&b.resolution.id));
// let mut res = 0;
// let mut dl_url = String::new();
//
// for i in p[0].files.iter() {
// if i.resolution.id > res {
// res = i.resolution.id;
// dl_url = i.file_download_url.clone();
// }
// }
//
// dl_url
"blah".to_string()
let mut res = 0;
let mut dl_url = String::new();
for i in p[0].files.iter() {
if i.resolution.id > res {
res = i.resolution.id;
dl_url = i.file_download_url.clone();
}
}
dl_url
}
/// This gets all the crispy details about one particular video
@@ -75,16 +73,27 @@ mod tests {
#[test]
fn test_get_max_resolution_dl() {
let str_plist: Vec<PeerTubeVideoStreamingPlaylists> = vec![
PeerTubeVideoStreamingPlaylists {
files: vec![PeerTubeVideoStreamingPlaylistsFiles { id: 1025, resolution: PeerTubeVideoStreamingPlaylistsFilesResolution { id: 990 }, file_download_url: "meh!".to_string() },
PeerTubeVideoStreamingPlaylistsFiles { id: 1027, resolution: PeerTubeVideoStreamingPlaylistsFilesResolution { id: 1720 }, file_download_url: "blah".to_string() },
PeerTubeVideoStreamingPlaylistsFiles { id: 1026, resolution: PeerTubeVideoStreamingPlaylistsFilesResolution { id: 360 }, file_download_url: "nope".to_string() },
]
}
];
let str_plist: Vec<PeerTubeVideoStreamingPlaylists> =
vec![PeerTubeVideoStreamingPlaylists {
files: vec![
PeerTubeVideoStreamingPlaylistsFiles {
id: 1025,
resolution: PeerTubeVideoStreamingPlaylistsFilesResolution { id: 990 },
file_download_url: "meh!".to_string(),
},
PeerTubeVideoStreamingPlaylistsFiles {
id: 1027,
resolution: PeerTubeVideoStreamingPlaylistsFilesResolution { id: 1720 },
file_download_url: "blah".to_string(),
},
PeerTubeVideoStreamingPlaylistsFiles {
id: 1026,
resolution: PeerTubeVideoStreamingPlaylistsFilesResolution { id: 360 },
file_download_url: "nope".to_string(),
},
],
}];
assert_eq!("blah".to_string(), get_max_resolution_dl(&str_plist));
}
}