Add proxy flag (#142)

This commit is contained in:
ByteDream 2023-04-11 21:14:06 +02:00 committed by ByteDream
parent 5f98cfb186
commit d33e2fa36b
4 changed files with 47 additions and 5 deletions

28
Cargo.lock generated
View file

@ -361,6 +361,7 @@ dependencies = [
"log", "log",
"num_cpus", "num_cpus",
"regex", "regex",
"reqwest",
"sanitize-filename", "sanitize-filename",
"serde", "serde",
"serde_json", "serde_json",
@ -374,9 +375,9 @@ dependencies = [
[[package]] [[package]]
name = "crunchyroll-rs" name = "crunchyroll-rs"
version = "0.3.2" version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "942a21f27140a954654d3b6b4aab8e8e3888b33cec736a51f0feab5e7fedc15f" checksum = "be975d4a27439853f6e80311b497e910fc49fd24525afdc12ca27ace18b84eeb"
dependencies = [ dependencies = [
"aes", "aes",
"async-trait", "async-trait",
@ -401,9 +402,9 @@ dependencies = [
[[package]] [[package]]
name = "crunchyroll-rs-internal" name = "crunchyroll-rs-internal"
version = "0.3.2" version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d90bc631b1f94891b3f5d5b9ca0b8c7f7a33e4e8d9ae98dbc6bcb5aee56b817" checksum = "b8d71a343838c462ace0531b2f5556fd1ea6b677d7a3e61ac28251e87d158c47"
dependencies = [ dependencies = [
"darling 0.14.4", "darling 0.14.4",
"quote", "quote",
@ -595,6 +596,12 @@ dependencies = [
"windows-sys 0.45.0", "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]] [[package]]
name = "encode_unicode" name = "encode_unicode"
version = "0.3.6" version = "0.3.6"
@ -1399,6 +1406,7 @@ dependencies = [
"tokio", "tokio",
"tokio-native-tls", "tokio-native-tls",
"tokio-rustls", "tokio-rustls",
"tokio-socks",
"tower-service", "tower-service",
"url", "url",
"wasm-bindgen", "wasm-bindgen",
@ -1874,6 +1882,18 @@ dependencies = [
"webpki", "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]] [[package]]
name = "tokio-util" name = "tokio-util"
version = "0.7.7" version = "0.7.7"

View file

@ -9,7 +9,7 @@ anyhow = "1.0"
async-trait = "0.1" async-trait = "0.1"
clap = { version = "4.2", features = ["derive", "string"] } clap = { version = "4.2", features = ["derive", "string"] }
chrono = "0.4" chrono = "0.4"
crunchyroll-rs = { version = "0.3", features = ["dash-stream"] } crunchyroll-rs = { version = "0.3.3", features = ["dash-stream"] }
ctrlc = "3.2" ctrlc = "3.2"
dirs = "5.0" dirs = "5.0"
derive_setters = "0.1" derive_setters = "0.1"
@ -19,6 +19,7 @@ lazy_static = "1.4"
log = { version = "0.4", features = ["std"] } log = { version = "0.4", features = ["std"] }
num_cpus = "1.15" num_cpus = "1.15"
regex = "1.7" regex = "1.7"
reqwest = { version = "0.11", features = ["socks"] }
sanitize-filename = "0.4" sanitize-filename = "0.4"
serde = "1.0" serde = "1.0"
serde_json = "1.0" serde_json = "1.0"

View file

@ -4,8 +4,10 @@ use crate::utils::log::{progress, CliLogger};
use anyhow::bail; use anyhow::bail;
use anyhow::Result; use anyhow::Result;
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
use crunchyroll_rs::crunchyroll::CrunchyrollBuilder;
use crunchyroll_rs::{Crunchyroll, Locale}; use crunchyroll_rs::{Crunchyroll, Locale};
use log::{debug, error, warn, LevelFilter}; use log::{debug, error, warn, LevelFilter};
use reqwest::Proxy;
use std::{env, fs}; use std::{env, fs};
mod archive; mod archive;
@ -50,6 +52,14 @@ pub struct Cli {
#[clap(flatten)] #[clap(flatten)]
login_method: LoginMethod, 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<Proxy>,
#[clap(subcommand)] #[clap(subcommand)]
command: Command, command: Command,
} }
@ -234,7 +244,13 @@ async fn crunchyroll_session(cli: &Cli) -> Result<Crunchyroll> {
lang 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() let mut builder = Crunchyroll::builder()
.client(client_builder.build()?)
.locale(locale) .locale(locale)
.stabilization_locales(cli.experimental_fixes) .stabilization_locales(cli.experimental_fixes)
.stabilization_season_number(cli.experimental_fixes); .stabilization_season_number(cli.experimental_fixes);

View file

@ -1,6 +1,11 @@
use crate::utils::parse::parse_resolution; use crate::utils::parse::parse_resolution;
use crunchyroll_rs::media::Resolution; use crunchyroll_rs::media::Resolution;
use reqwest::Proxy;
pub fn clap_parse_resolution(s: &str) -> Result<Resolution, String> { pub fn clap_parse_resolution(s: &str) -> Result<Resolution, String> {
parse_resolution(s.to_string()).map_err(|e| e.to_string()) parse_resolution(s.to_string()).map_err(|e| e.to_string())
} }
pub fn clap_parse_proxy(s: &str) -> Result<Proxy, String> {
Proxy::all(s).map_err(|e| e.to_string())
}