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
|
/// This returns the direct download URL for with the maximum resolution
|
||||||
pub fn get_max_resolution_dl(p: &Vec<PeerTubeVideoStreamingPlaylists>) -> String {
|
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 res = 0;
|
let mut dl_url = String::new();
|
||||||
// let mut dl_url = String::new();
|
|
||||||
//
|
for i in p[0].files.iter() {
|
||||||
// for i in p[0].files.iter() {
|
if i.resolution.id > res {
|
||||||
// if i.resolution.id > res {
|
res = i.resolution.id;
|
||||||
// res = i.resolution.id;
|
dl_url = i.file_download_url.clone();
|
||||||
// dl_url = i.file_download_url.clone();
|
}
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
//
|
dl_url
|
||||||
// dl_url
|
|
||||||
"blah".to_string()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This gets all the crispy details about one particular video
|
/// This gets all the crispy details about one particular video
|
||||||
@@ -75,16 +73,27 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_max_resolution_dl() {
|
fn test_get_max_resolution_dl() {
|
||||||
let str_plist: Vec<PeerTubeVideoStreamingPlaylists> = vec![
|
let str_plist: Vec<PeerTubeVideoStreamingPlaylists> =
|
||||||
PeerTubeVideoStreamingPlaylists {
|
vec![PeerTubeVideoStreamingPlaylists {
|
||||||
files: vec![PeerTubeVideoStreamingPlaylistsFiles { id: 1025, resolution: PeerTubeVideoStreamingPlaylistsFilesResolution { id: 990 }, file_download_url: "meh!".to_string() },
|
files: vec![
|
||||||
PeerTubeVideoStreamingPlaylistsFiles { id: 1027, resolution: PeerTubeVideoStreamingPlaylistsFilesResolution { id: 1720 }, file_download_url: "blah".to_string() },
|
PeerTubeVideoStreamingPlaylistsFiles {
|
||||||
PeerTubeVideoStreamingPlaylistsFiles { id: 1026, resolution: PeerTubeVideoStreamingPlaylistsFilesResolution { id: 360 }, file_download_url: "nope".to_string() },
|
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));
|
assert_eq!("blah".to_string(), get_max_resolution_dl(&str_plist));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user