mirror of
https://framagit.org/veretcle/tootube.git
synced 2025-07-20 12:31:19 +02:00
refactor: remove get_max_resolution_dl (ord makes it redundant)
This commit is contained in:
10
src/lib.rs
10
src/lib.rs
@@ -7,7 +7,7 @@ pub use config::parse_toml;
|
|||||||
use config::Config;
|
use config::Config;
|
||||||
|
|
||||||
mod peertube;
|
mod peertube;
|
||||||
use peertube::{get_latest_video, get_max_resolution_dl};
|
use peertube::get_latest_video;
|
||||||
|
|
||||||
mod youtube;
|
mod youtube;
|
||||||
pub use youtube::register;
|
pub use youtube::register;
|
||||||
@@ -22,7 +22,13 @@ pub async fn run(config: Config, pl: Vec<String>) {
|
|||||||
panic!("Cannot retrieve the latest video, something must have gone terribly wrong: {e}")
|
panic!("Cannot retrieve the latest video, something must have gone terribly wrong: {e}")
|
||||||
});
|
});
|
||||||
|
|
||||||
let dl_url = get_max_resolution_dl(latest_vid.streaming_playlists.as_ref().unwrap());
|
let dl_url = latest_vid.streaming_playlists.as_ref().unwrap()[0]
|
||||||
|
.files
|
||||||
|
.iter()
|
||||||
|
.max()
|
||||||
|
.unwrap()
|
||||||
|
.file_download_url
|
||||||
|
.clone();
|
||||||
debug!("PT download URL: {}", &dl_url);
|
debug!("PT download URL: {}", &dl_url);
|
||||||
|
|
||||||
let resumable_upload_url = create_resumable_upload(&config.youtube, &latest_vid)
|
let resumable_upload_url = create_resumable_upload(&config.youtube, &latest_vid)
|
||||||
|
@@ -65,11 +65,6 @@ pub async fn get_latest_video(u: &str) -> Result<PeerTubeVideo, Box<dyn Error>>
|
|||||||
Ok(vid)
|
Ok(vid)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This returns the direct download URL for with the maximum resolution
|
|
||||||
pub fn get_max_resolution_dl(p: &[PeerTubeVideoStreamingPlaylists]) -> String {
|
|
||||||
p[0].files.iter().max().unwrap().file_download_url.clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// This gets all the crispy details about one particular video
|
/// This gets all the crispy details about one particular video
|
||||||
async fn get_video_detail(u: &str, v: &str) -> Result<PeerTubeVideo, Box<dyn Error>> {
|
async fn get_video_detail(u: &str, v: &str) -> Result<PeerTubeVideo, Box<dyn Error>> {
|
||||||
let body = reqwest::get(format!("{}/api/v1/videos/{}", u, v))
|
let body = reqwest::get(format!("{}/api/v1/videos/{}", u, v))
|
||||||
@@ -79,34 +74,3 @@ async fn get_video_detail(u: &str, v: &str) -> Result<PeerTubeVideo, Box<dyn Err
|
|||||||
|
|
||||||
Ok(body)
|
Ok(body)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[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(),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}];
|
|
||||||
|
|
||||||
assert_eq!("blah".to_string(), get_max_resolution_dl(&str_plist));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user