Add root flag to set custom user agent

This commit is contained in:
bytedream 2023-09-06 03:02:40 +02:00
parent b477ca982c
commit 0f7e6c9120

View file

@ -63,6 +63,10 @@ pub struct Cli {
#[arg(value_parser = crate::utils::clap::clap_parse_proxy)] #[arg(value_parser = crate::utils::clap::clap_parse_proxy)]
proxy: Option<Proxy>, proxy: Option<Proxy>,
#[arg(help = "Use custom user agent")]
#[clap(long)]
user_agent: Option<String>,
#[clap(subcommand)] #[clap(subcommand)]
command: Command, command: Command,
} }
@ -261,15 +265,17 @@ async fn crunchyroll_session(cli: &mut Cli) -> Result<Crunchyroll> {
lang lang
}; };
let proxy = cli.proxy.clone();
let mut builder = Crunchyroll::builder() let mut builder = Crunchyroll::builder()
.locale(locale) .locale(locale)
.client({ .client({
let builder = if let Some(p) = &proxy { let mut builder = CrunchyrollBuilder::predefined_client_builder();
CrunchyrollBuilder::predefined_client_builder().proxy(p.clone()) if let Some(p) = &cli.proxy {
} else { builder = builder.proxy(p.clone())
CrunchyrollBuilder::predefined_client_builder() }
}; if let Some(ua) = &cli.user_agent {
builder = builder.user_agent(ua)
}
#[cfg(any(feature = "openssl", feature = "openssl-static"))] #[cfg(any(feature = "openssl", feature = "openssl-static"))]
let client = { let client = {
let mut builder = builder.use_native_tls().tls_built_in_root_certs(false); let mut builder = builder.use_native_tls().tls_built_in_root_certs(false);
@ -292,14 +298,6 @@ async fn crunchyroll_session(cli: &mut Cli) -> Result<Crunchyroll> {
if let Command::Download(download) = &cli.command { if let Command::Download(download) = &cli.command {
builder = builder.preferred_audio_locale(download.audio.clone()) builder = builder.preferred_audio_locale(download.audio.clone())
} }
if let Some(p) = &cli.proxy {
builder = builder.client(
CrunchyrollBuilder::predefined_client_builder()
.proxy(p.clone())
.build()
.unwrap(),
)
}
let root_login_methods_count = cli.login_method.credentials.is_some() as u8 let root_login_methods_count = cli.login_method.credentials.is_some() as u8
+ cli.login_method.etp_rt.is_some() as u8 + cli.login_method.etp_rt.is_some() as u8