From 59818afa95c636b90933af912d7c68807e895a26 Mon Sep 17 00:00:00 2001 From: khyernet Date: Thu, 2 May 2024 18:24:29 -0800 Subject: [PATCH] feat: add custom instance support --- src/args/mod.rs | 13 ++++++++++++- src/main.rs | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/args/mod.rs b/src/args/mod.rs index 8fc770a..1fa774d 100644 --- a/src/args/mod.rs +++ b/src/args/mod.rs @@ -24,6 +24,7 @@ pub struct Args { pub c_fname_style: types::FilenamePattern, pub same_filenames: bool, pub picker_choice: u8, + pub cobalt_instance: String, pub help_flag: Option } impl Args { @@ -49,6 +50,7 @@ impl Args { c_tt_h265: false, c_dublang: false, c_disable_metadata: false, + cobalt_instance: String::from("co.wuk.sh"), accept_language: String::from("en") } } @@ -104,6 +106,7 @@ impl Args { "--output" => expected.push(ExpectedFlags::Output), "--fname-style" => expected.push(ExpectedFlags::FilenamePattern), "--pick" => expected.push(ExpectedFlags::Picker), + "--instance" => expected.push(ExpectedFlags::Instance), _ => { if self.c_url == None && arg.contains("https://") { self.c_url = Some(arg.clone()); @@ -140,6 +143,7 @@ impl Args { 'o' => expected.push(ExpectedFlags::Output), 's' => expected.push(ExpectedFlags::FilenamePattern), 'p' => expected.push(ExpectedFlags::Picker), + 'i' => expected.push(ExpectedFlags::Instance), _ => return Err(types::ParseError::throw_invalid(&format!("Invalid character {c} in multi-flag argument: {arg}"))) } } @@ -196,6 +200,13 @@ impl Args { }, ExpectedFlags::Language => { self.accept_language = arg.clone(); + }, + ExpectedFlags::Instance => { + let mut url = arg.replace("https://", ""); + if let Some(idx) = url.find('/') { + url.truncate(idx); + } + self.cobalt_instance = url; } } } @@ -315,5 +326,5 @@ impl Args { #[derive(Debug)] enum ExpectedFlags { - VideoCodec, VideoQuality, AudioFormat, Output, FilenamePattern, Picker, Language + VideoCodec, VideoQuality, AudioFormat, Output, FilenamePattern, Picker, Language, Instance } diff --git a/src/main.rs b/src/main.rs index 3e5201d..e844a97 100644 --- a/src/main.rs +++ b/src/main.rs @@ -114,7 +114,7 @@ async fn execute_get_media(args: Args, bulk: u16, debug: bool) -> bool { let json = proc::cobalt_args(&args); let download_url: &str = args.c_url.as_ref().unwrap(); - let request = reqwest::Client::new().post("https://co.wuk.sh/api/json") + let request = reqwest::Client::new().post(format!("https://{}/api/json", &args.cobalt_instance)) .header("User-Agent", &format!("tcobalt {}", VERSION.trim())) .header("Accept", "application/json") .header("Content-Type", "application/json")