diff --git a/Cargo.lock b/Cargo.lock index 2e73125..8a7f4ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1192,7 +1192,7 @@ dependencies = [ [[package]] name = "tootube" -version = "0.7.3" +version = "0.8.0" dependencies = [ "async-stream", "clap", diff --git a/Cargo.toml b/Cargo.toml index ca0301e..3fc63f5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "tootube" authors = ["VC "] -version = "0.7.3" +version = "0.8.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/lib.rs b/src/lib.rs index fae0868..fd6c298 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,7 +15,7 @@ pub use youtube::register as register_youtube; use youtube::YouTube; #[tokio::main] -pub async fn run(config: Config, pl: Vec) { +pub async fn run(config: Config, pl: Vec, pt_video_id: Option<&str>) { // Create PeerTube struct let peertube = match &config.peertube.oauth2 { Some(s) => PeerTube::new(&config.peertube.base_url) @@ -24,10 +24,17 @@ pub async fn run(config: Config, pl: Vec) { .unwrap_or_else(|e| panic!("Cannot instantiate PeerTube struct: {}", e)), None => PeerTube::new(&config.peertube.base_url), }; - // Get the latest video object - let latest_vid = peertube.get_latest_video().await.unwrap_or_else(|e| { - panic!("Cannot retrieve the latest video, something must have gone terribly wrong: {e}") - }); + // Get the latest video object or the targeted pt_video_id + let latest_vid = match pt_video_id { + None => peertube.get_latest_video().await.unwrap_or_else(|e| { + panic!("Cannot retrieve the latest video, something must have gone terribly wrong: {e}") + }), + Some(v) => peertube.get_video_detail(v).await.unwrap_or_else(|e| { + panic!( + "Cannot retrieve the specified video, something must have gone terribly wrong: {e}" + ) + }), + }; // We have a refresh_token, try to use it let source_url = match &config.peertube.oauth2 { diff --git a/src/main.rs b/src/main.rs index de93fb5..444679a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,12 +27,21 @@ fn main() { .num_args(0..) .display_order(2), ) + .arg( + Arg::new("id") + .short('i') + .long("id") + .value_name("ID") + .help("Specify the PeerTube Video ID") + .num_args(0..=1) + .display_order(3), + ) .arg( Arg::new("vice") .long("vice") .aliases(["chybrare", "coquinou"]) .action(clap::ArgAction::SetTrue) - .display_order(3), + .display_order(4), ) .subcommand( Command::new("register") @@ -85,7 +94,9 @@ fn main() { .map(|v| v.to_string()) .collect(); + let pt_video_id = matches.get_one::("id").map(|s| s.as_str()); + env_logger::init(); - run(config, playlists); + run(config, playlists, pt_video_id); } diff --git a/src/peertube.rs b/src/peertube.rs index e837f19..4ca673e 100644 --- a/src/peertube.rs +++ b/src/peertube.rs @@ -279,7 +279,7 @@ impl PeerTube { } /// This gets all the crispy details about one particular video - async fn get_video_detail(&self, v: &str) -> Result> { + pub async fn get_video_detail(&self, v: &str) -> Result> { let body = self .client .get(format!("{}/videos/{}", self.base_url, v))