From f3ad81716d7725c1aa63b093f1d9682ceb13c424 Mon Sep 17 00:00:00 2001 From: VC Date: Thu, 19 Oct 2023 11:12:16 +0200 Subject: [PATCH] refactor: remove get_max_resolution_dl (ord makes it redundant) --- src/lib.rs | 10 ++++++++-- src/peertube.rs | 36 ------------------------------------ 2 files changed, 8 insertions(+), 38 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2175604..3c221b6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,7 +7,7 @@ pub use config::parse_toml; use config::Config; mod peertube; -use peertube::{get_latest_video, get_max_resolution_dl}; +use peertube::get_latest_video; mod youtube; pub use youtube::register; @@ -22,7 +22,13 @@ pub async fn run(config: Config, pl: Vec) { 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); let resumable_upload_url = create_resumable_upload(&config.youtube, &latest_vid) diff --git a/src/peertube.rs b/src/peertube.rs index d872adf..8d11700 100644 --- a/src/peertube.rs +++ b/src/peertube.rs @@ -65,11 +65,6 @@ pub async fn get_latest_video(u: &str) -> Result> 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 async fn get_video_detail(u: &str, v: &str) -> Result> { let body = reqwest::get(format!("{}/api/v1/videos/{}", u, v)) @@ -79,34 +74,3 @@ async fn get_video_detail(u: &str, v: &str) -> Result = - 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)); - } -}