Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
feat: add custom instance support
Browse files Browse the repository at this point in the history
  • Loading branch information
khyerdev committed May 3, 2024
1 parent bfc5a28 commit 59818af
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<types::Help>
}
impl Args {
Expand All @@ -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")
}
}
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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}")))
}
}
Expand Down Expand Up @@ -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;
}
}
}
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 59818af

Please sign in to comment.