mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 04:02:00 -06:00
Add native-tls/openssl tls backend for linux
This commit is contained in:
parent
566422cb06
commit
4ec9a0d309
3 changed files with 207 additions and 1 deletions
|
|
@ -30,5 +30,11 @@ tempfile = "3.6"
|
|||
tokio = { version = "1.29", features = ["macros", "rt-multi-thread", "time"] }
|
||||
sys-locale = "0.3"
|
||||
|
||||
[target.'cfg(target_os = "linux")'.dependencies]
|
||||
reqwest = { version = "0.11", default-features = false, features = ["socks", "native-tls-alpn", "native-tls-vendored"] }
|
||||
|
||||
[target.'cfg(not(target_os = "linux"))'.dependencies]
|
||||
reqwest = { version = "0.11", default-features = false, features = ["socks"] }
|
||||
|
||||
[build-dependencies]
|
||||
chrono = "0.4"
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use crunchyroll_rs::crunchyroll::CrunchyrollBuilder;
|
|||
use crunchyroll_rs::error::CrunchyrollError;
|
||||
use crunchyroll_rs::{Crunchyroll, Locale};
|
||||
use log::{debug, error, warn, LevelFilter};
|
||||
use reqwest::Proxy;
|
||||
use reqwest::{Client, ClientBuilder, Proxy, StatusCode};
|
||||
use std::{env, fs};
|
||||
|
||||
mod archive;
|
||||
|
|
@ -264,8 +264,19 @@ async fn crunchyroll_session(cli: &mut Cli) -> Result<Crunchyroll> {
|
|||
lang
|
||||
};
|
||||
|
||||
let proxy = cli.proxy.clone();
|
||||
let mut builder = Crunchyroll::builder()
|
||||
.locale(locale)
|
||||
.client(
|
||||
get_client(|| {
|
||||
if let Some(p) = &proxy {
|
||||
CrunchyrollBuilder::predefined_client_builder().proxy(p.clone())
|
||||
} else {
|
||||
CrunchyrollBuilder::predefined_client_builder()
|
||||
}
|
||||
})
|
||||
.await?,
|
||||
)
|
||||
.stabilization_locales(cli.experimental_fixes)
|
||||
.stabilization_season_number(cli.experimental_fixes);
|
||||
if let Command::Download(download) = &cli.command {
|
||||
|
|
@ -340,3 +351,25 @@ async fn crunchyroll_session(cli: &mut Cli) -> Result<Crunchyroll> {
|
|||
|
||||
Ok(crunchy)
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
async fn get_client<F: Fn() -> ClientBuilder>(f: F) -> Result<Client> {
|
||||
let client = f().build().unwrap();
|
||||
if client
|
||||
.get("https://www.crunchyroll.com")
|
||||
.send()
|
||||
.await?
|
||||
.status()
|
||||
!= StatusCode::FORBIDDEN
|
||||
{
|
||||
return Ok(client);
|
||||
}
|
||||
|
||||
debug!("rustls tls backend probably triggered the cloudflare bot check, using openssl instead");
|
||||
Ok(f().use_native_tls().build().unwrap())
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
async fn get_client<F: Fn() -> ClientBuilder>(f: F) -> Result<Client> {
|
||||
Ok(f().build().unwrap())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue