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

Commit

Permalink
feat: add support for other default filename patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
khyerdev committed Apr 30, 2024
1 parent be45acb commit 48204d2
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub struct Args {
pub c_audio_muted: bool,
pub c_twitter_gif: bool,
pub out_filename: Option<String>,
pub c_fname_style: types::FilenamePattern,
pub same_filenames: bool,
pub help_flag: Option<types::Help>
}
Expand All @@ -36,6 +37,7 @@ impl Args {
help_flag: None,
method: None,
bulk_array: None,
c_fname_style: types::FilenamePattern::Classic
}
}

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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}")))
}
}
Expand Down Expand Up @@ -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}")))
}
}
}
}
Expand Down Expand Up @@ -264,5 +277,5 @@ impl Args {

#[derive(Debug)]
enum ExpectedFlags {
VideoCodec, VideoQuality, AudioFormat, Output,
VideoCodec, VideoQuality, AudioFormat, Output, FilenamePattern
}
15 changes: 15 additions & 0 deletions src/args/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ const POST_TEMPLATE: &str = "{
\"vCodec\": \"<vcodec>\",
\"vQuality\": \"<vquality>\",
\"aFormat\": \"<aformat>\",
\"filenamePattern\": \"classic\",
\"filenamePattern\": \"<fname-style>\",
\"isAudioOnly\": <audio-only>,
\"isTTFullAudio\": false,
\"tiktokH265\": false,
Expand All @@ -282,6 +282,7 @@ fn cobalt_args(args_in: &Args) -> String {
.replace("<vcodec>", &args_in.c_video_codec.print())
.replace("<vquality>", &args_in.c_video_quality.to_string())
.replace("<aformat>", &args_in.c_audio_format.print())
.replace("<fname-style>", &args_in.c_fname_style.print())
.replace("<audio-only>", &args_in.c_audio_only.to_string())
.replace("<audio-muted>", &args_in.c_audio_muted.to_string())
.replace("<twitter-gif>", &args_in.c_twitter_gif.to_string())
Expand Down
3 changes: 3 additions & 0 deletions src/strings/usage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 <style> Tells cobalt which filename style to return. Styles: classic, pretty, basic, nerdy, Default: classic
This option will not matter if -o or --output is specified.
[TODO: show examples of styles, give output an option to still use the internal name]
-o --output <filename> The output filename. Make sure to include the proper file extension.
If no filename is specified, it uses the internal filename of the video, or the hash of the url if none is available.

Expand Down

0 comments on commit 48204d2

Please sign in to comment.