diff --git a/Cargo.lock b/Cargo.lock index cd468a4..6531bcd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -361,6 +361,7 @@ dependencies = [ "log", "num_cpus", "regex", + "reqwest", "sanitize-filename", "serde", "serde_json", @@ -374,9 +375,9 @@ dependencies = [ [[package]] name = "crunchyroll-rs" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "942a21f27140a954654d3b6b4aab8e8e3888b33cec736a51f0feab5e7fedc15f" +checksum = "be975d4a27439853f6e80311b497e910fc49fd24525afdc12ca27ace18b84eeb" dependencies = [ "aes", "async-trait", @@ -401,9 +402,9 @@ dependencies = [ [[package]] name = "crunchyroll-rs-internal" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d90bc631b1f94891b3f5d5b9ca0b8c7f7a33e4e8d9ae98dbc6bcb5aee56b817" +checksum = "b8d71a343838c462ace0531b2f5556fd1ea6b677d7a3e61ac28251e87d158c47" dependencies = [ "darling 0.14.4", "quote", @@ -595,6 +596,12 @@ dependencies = [ "windows-sys 0.45.0", ] +[[package]] +name = "either" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" + [[package]] name = "encode_unicode" version = "0.3.6" @@ -1399,6 +1406,7 @@ dependencies = [ "tokio", "tokio-native-tls", "tokio-rustls", + "tokio-socks", "tower-service", "url", "wasm-bindgen", @@ -1874,6 +1882,18 @@ dependencies = [ "webpki", ] +[[package]] +name = "tokio-socks" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51165dfa029d2a65969413a6cc96f354b86b464498702f174a4efa13608fd8c0" +dependencies = [ + "either", + "futures-util", + "thiserror", + "tokio", +] + [[package]] name = "tokio-util" version = "0.7.7" diff --git a/crunchy-cli-core/Cargo.toml b/crunchy-cli-core/Cargo.toml index 5def6c3..407383b 100644 --- a/crunchy-cli-core/Cargo.toml +++ b/crunchy-cli-core/Cargo.toml @@ -9,7 +9,7 @@ anyhow = "1.0" async-trait = "0.1" clap = { version = "4.2", features = ["derive", "string"] } chrono = "0.4" -crunchyroll-rs = { version = "0.3", features = ["dash-stream"] } +crunchyroll-rs = { version = "0.3.3", features = ["dash-stream"] } ctrlc = "3.2" dirs = "5.0" derive_setters = "0.1" @@ -19,6 +19,7 @@ lazy_static = "1.4" log = { version = "0.4", features = ["std"] } num_cpus = "1.15" regex = "1.7" +reqwest = { version = "0.11", features = ["socks"] } sanitize-filename = "0.4" serde = "1.0" serde_json = "1.0" diff --git a/crunchy-cli-core/src/lib.rs b/crunchy-cli-core/src/lib.rs index 8bb6768..e2a584c 100644 --- a/crunchy-cli-core/src/lib.rs +++ b/crunchy-cli-core/src/lib.rs @@ -4,8 +4,10 @@ use crate::utils::log::{progress, CliLogger}; use anyhow::bail; use anyhow::Result; use clap::{Parser, Subcommand}; +use crunchyroll_rs::crunchyroll::CrunchyrollBuilder; use crunchyroll_rs::{Crunchyroll, Locale}; use log::{debug, error, warn, LevelFilter}; +use reqwest::Proxy; use std::{env, fs}; mod archive; @@ -50,6 +52,14 @@ pub struct Cli { #[clap(flatten)] login_method: LoginMethod, + #[arg(help = "Use a proxy to route all traffic through")] + #[arg(long_help = "Use a proxy to route all traffic through. \ + Make sure that the proxy can either forward TLS requests, which is needed to bypass the (cloudflare) bot protection, or that it is configured so that the proxy can bypass the protection itself" + )] + #[clap(long)] + #[arg(value_parser = crate::utils::clap::clap_parse_proxy)] + proxy: Option, + #[clap(subcommand)] command: Command, } @@ -234,7 +244,13 @@ async fn crunchyroll_session(cli: &Cli) -> Result { lang }; + let mut client_builder = CrunchyrollBuilder::predefined_client_builder(); + if let Some(proxy) = &cli.proxy { + client_builder = client_builder.proxy(proxy.clone()) + } + let mut builder = Crunchyroll::builder() + .client(client_builder.build()?) .locale(locale) .stabilization_locales(cli.experimental_fixes) .stabilization_season_number(cli.experimental_fixes); diff --git a/crunchy-cli-core/src/utils/clap.rs b/crunchy-cli-core/src/utils/clap.rs index 4e27a5e..c3088d8 100644 --- a/crunchy-cli-core/src/utils/clap.rs +++ b/crunchy-cli-core/src/utils/clap.rs @@ -1,6 +1,11 @@ use crate::utils::parse::parse_resolution; use crunchyroll_rs::media::Resolution; +use reqwest::Proxy; pub fn clap_parse_resolution(s: &str) -> Result { parse_resolution(s.to_string()).map_err(|e| e.to_string()) } + +pub fn clap_parse_proxy(s: &str) -> Result { + Proxy::all(s).map_err(|e| e.to_string()) +}