mirror of
https://framagit.org/veretcle/tootube.git
synced 2025-07-20 20:41:17 +02:00
fix: dl function
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user