From 5ce84c44a6844f692258066c83e04df875e0aa91 Mon Sep 17 00:00:00 2001 From: ThetaDev Date: Fri, 20 Dec 2024 03:06:03 +0100 Subject: [PATCH] fix: error 400 when fetching player with login --- cli/src/main.rs | 20 +++++++++++++++++++- src/client/mod.rs | 4 ++++ src/client/player.rs | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index a1793e0..1e0fc2d 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -14,6 +14,7 @@ use futures_util::stream::{self, StreamExt}; use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; use owo_colors::OwoColorize; use rustypipe::{ + cache::FileStorage, client::{ClientType, RustyPipe}, model::{ richtext::{RichText, ToPlaintext}, @@ -53,6 +54,12 @@ struct Cli { /// YouTube content country #[clap(long, global = true)] country: Option, + #[clap(long, global = true)] + /// RustyPipe cache file + cache_file: Option, + /// RustyPipe report folder + #[clap(long, global = true)] + report_dir: Option, } #[derive(Parser)] @@ -618,12 +625,23 @@ async fn run() -> anyhow::Result<()> { let mut storage_dir = dirs::data_dir().expect("no data dir"); storage_dir.push("rustypipe"); - std::fs::create_dir_all(&storage_dir).expect("could not create data dir"); + + if cli.cache_file.is_none() || cli.report_dir.is_none() { + std::fs::create_dir_all(&storage_dir).expect("could not create data dir"); + } let mut rp = RustyPipe::builder() .storage_dir(storage_dir) .visitor_data_opt(cli.vdata) .timeout(Duration::from_secs(15)); + + if let Some(cache_file) = cli.cache_file { + rp = rp.storage(Box::new(FileStorage::new(cache_file))); + } + if let Some(report_dir) = cli.report_dir { + rp = rp.reporter(Box::new(FileReporter::new(report_dir))); + } + if cli.report { rp = rp .report() diff --git a/src/client/mod.rs b/src/client/mod.rs index cef5916..2fec2a1 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -1458,6 +1458,10 @@ impl RustyPipeQuery { } /// Enable authentication for this request + /// + /// RustyPipe uses YouTube TV's OAuth authentication. This means that authentication + /// only works when using the TV client. Enabling authentication for other clients + /// results in a 400 error. #[must_use] pub fn authenticated(mut self) -> Self { self.opts.auth = Some(true); diff --git a/src/client/player.rs b/src/client/player.rs index 47fb7a0..bdfd0e9 100644 --- a/src/client/player.rs +++ b/src/client/player.rs @@ -90,7 +90,7 @@ impl RustyPipeQuery { match self .clone() .authenticated() - .player_from_client(video_id, *client) + .player_from_client(video_id, ClientType::Tv) .await { Ok(res) => return Ok(res),