diff --git a/src/args/mod.rs b/src/args/mod.rs index f7a9e4b..741d2b5 100644 --- a/src/args/mod.rs +++ b/src/args/mod.rs @@ -16,6 +16,7 @@ pub struct Args { pub c_audio_muted: bool, pub c_twitter_gif: bool, pub out_filename: Option, + pub c_fname_style: types::FilenamePattern, pub same_filenames: bool, pub help_flag: Option } @@ -36,6 +37,7 @@ impl Args { help_flag: None, method: None, bulk_array: None, + c_fname_style: types::FilenamePattern::Classic } } @@ -81,6 +83,7 @@ impl Args { "--mute-audio" => self.c_audio_muted = true, "--twitter-gif" => self.c_twitter_gif = true, "--output" => expected.push(ExpectedFlags::Output), + "--fname-style" => expected.push(ExpectedFlags::FilenamePattern), _ => { if self.c_url == None && arg.contains("https://") { self.c_url = Some(arg.clone()); @@ -108,6 +111,7 @@ impl Args { 'm' => self.c_audio_muted = true, 'g' => self.c_twitter_gif = true, 'o' => expected.push(ExpectedFlags::Output), + 's' => expected.push(ExpectedFlags::FilenamePattern), _ => return Err(types::ParseError::throw_invalid(&format!("Invalid character {c} in multi-flag argument: {arg}"))) } } @@ -145,6 +149,15 @@ impl Args { } else { return Err(types::ParseError::throw_invalid("Output filename must be a video file type (supported: mp4/webm/gif), or an audio file type (supported: mp3/ogg/wav/opus)\nMake sure you choose the right file type for the chosen codec/format!")); } + }, + ExpectedFlags::FilenamePattern => { + match arg.as_str() { + "classic" | "c" => self.c_fname_style = types::FilenamePattern::Classic, + "pretty" | "p" => self.c_fname_style = types::FilenamePattern::Pretty, + "basic" | "b" => self.c_fname_style = types::FilenamePattern::Basic, + "nerdy" | "n" => self.c_fname_style = types::FilenamePattern::Nerdy, + _ => return Err(types::ParseError::throw_invalid(&format!("Invalid filename style: {arg}"))) + } } } } @@ -264,5 +277,5 @@ impl Args { #[derive(Debug)] enum ExpectedFlags { - VideoCodec, VideoQuality, AudioFormat, Output, + VideoCodec, VideoQuality, AudioFormat, Output, FilenamePattern } diff --git a/src/args/types.rs b/src/args/types.rs index 8a2cd2e..670304a 100644 --- a/src/args/types.rs +++ b/src/args/types.rs @@ -28,6 +28,21 @@ impl AudioFormat { } } +#[derive(Debug, PartialEq, Eq, Clone)] +pub enum FilenamePattern { + Classic, Pretty, Basic, Nerdy +} +impl Default for FilenamePattern { + fn default() -> Self { + Self::Classic + } +} +impl FilenamePattern { + pub fn print(&self) -> String { + format!("{self:?}").to_lowercase() + } +} + #[derive(Debug, PartialEq, Eq, Clone)] pub enum Help { Get, List, Bulk, Help, Examples diff --git a/src/main.rs b/src/main.rs index 2a629f3..3c1ff31 100644 --- a/src/main.rs +++ b/src/main.rs @@ -267,7 +267,7 @@ const POST_TEMPLATE: &str = "{ \"vCodec\": \"\", \"vQuality\": \"\", \"aFormat\": \"\", - \"filenamePattern\": \"classic\", + \"filenamePattern\": \"\", \"isAudioOnly\": , \"isTTFullAudio\": false, \"tiktokH265\": false, @@ -282,6 +282,7 @@ fn cobalt_args(args_in: &Args) -> String { .replace("", &args_in.c_video_codec.print()) .replace("", &args_in.c_video_quality.to_string()) .replace("", &args_in.c_audio_format.print()) + .replace("", &args_in.c_fname_style.print()) .replace("", &args_in.c_audio_only.to_string()) .replace("", &args_in.c_audio_muted.to_string()) .replace("", &args_in.c_twitter_gif.to_string()) diff --git a/src/strings/usage.txt b/src/strings/usage.txt index 809e08c..232504c 100644 --- a/src/strings/usage.txt +++ b/src/strings/usage.txt @@ -31,6 +31,9 @@ Options: -a --audio-only Tells cobalt to only download and output the audio of the link -m --mute-audio Tells cobalt to mute the audio from the downloaded content -g --twitter-gif Tells cobalt to download the given twitter content as a gif + -s --fname_style