mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
add universal output flag (#319)
* add universal filenames setting * rename flag and help
This commit is contained in:
parent
a4abb14ae3
commit
982e521e0b
4 changed files with 35 additions and 23 deletions
|
|
@ -408,11 +408,11 @@ impl Format {
|
|||
}
|
||||
|
||||
/// Formats the given string if it has specific pattern in it. It also sanitizes the filename.
|
||||
pub fn format_path(&self, path: PathBuf) -> PathBuf {
|
||||
pub fn format_path(&self, path: PathBuf, universal: bool) -> PathBuf {
|
||||
let path = path
|
||||
.to_string_lossy()
|
||||
.to_string()
|
||||
.replace("{title}", &sanitize(&self.title, true))
|
||||
.replace("{title}", &sanitize(&self.title, true, universal))
|
||||
.replace(
|
||||
"{audio}",
|
||||
&sanitize(
|
||||
|
|
@ -421,30 +421,30 @@ impl Format {
|
|||
.map(|(a, _)| a.to_string())
|
||||
.collect::<Vec<String>>()
|
||||
.join("|"),
|
||||
true,
|
||||
true, universal,
|
||||
),
|
||||
)
|
||||
.replace("{resolution}", &sanitize(self.resolution.to_string(), true))
|
||||
.replace("{resolution}", &sanitize(self.resolution.to_string(), true, universal))
|
||||
.replace(
|
||||
"{width}",
|
||||
&sanitize(self.resolution.width.to_string(), true),
|
||||
&sanitize(self.resolution.width.to_string(), true, universal),
|
||||
)
|
||||
.replace(
|
||||
"{height}",
|
||||
&sanitize(self.resolution.height.to_string(), true),
|
||||
&sanitize(self.resolution.height.to_string(), true, universal),
|
||||
)
|
||||
.replace("{series_id}", &sanitize(&self.series_id, true))
|
||||
.replace("{series_name}", &sanitize(&self.series_name, true))
|
||||
.replace("{season_id}", &sanitize(&self.season_id, true))
|
||||
.replace("{season_name}", &sanitize(&self.season_title, true))
|
||||
.replace("{series_id}", &sanitize(&self.series_id, true, universal))
|
||||
.replace("{series_name}", &sanitize(&self.series_name, true, universal))
|
||||
.replace("{season_id}", &sanitize(&self.season_id, true, universal))
|
||||
.replace("{season_name}", &sanitize(&self.season_title, true, universal))
|
||||
.replace(
|
||||
"{season_number}",
|
||||
&format!("{:0>2}", sanitize(self.season_number.to_string(), true)),
|
||||
&format!("{:0>2}", sanitize(self.season_number.to_string(), true, universal)),
|
||||
)
|
||||
.replace("{episode_id}", &sanitize(&self.episode_id, true))
|
||||
.replace("{episode_id}", &sanitize(&self.episode_id, true, universal))
|
||||
.replace(
|
||||
"{episode_number}",
|
||||
&format!("{:0>2}", sanitize(&self.episode_number, true)),
|
||||
&format!("{:0>2}", sanitize(&self.episode_number, true, universal)),
|
||||
)
|
||||
.replace(
|
||||
"{relative_episode_number}",
|
||||
|
|
@ -452,13 +452,13 @@ impl Format {
|
|||
"{:0>2}",
|
||||
sanitize(
|
||||
self.relative_episode_number.unwrap_or_default().to_string(),
|
||||
true,
|
||||
true, universal,
|
||||
)
|
||||
),
|
||||
)
|
||||
.replace(
|
||||
"{sequence_number}",
|
||||
&format!("{:0>2}", sanitize(self.sequence_number.to_string(), true)),
|
||||
&format!("{:0>2}", sanitize(self.sequence_number.to_string(), true, universal)),
|
||||
)
|
||||
.replace(
|
||||
"{relative_sequence_number}",
|
||||
|
|
@ -468,21 +468,21 @@ impl Format {
|
|||
self.relative_sequence_number
|
||||
.unwrap_or_default()
|
||||
.to_string(),
|
||||
true,
|
||||
true, universal,
|
||||
)
|
||||
),
|
||||
)
|
||||
.replace(
|
||||
"{release_year}",
|
||||
&sanitize(self.release_year.to_string(), true),
|
||||
&sanitize(self.release_year.to_string(), true, universal),
|
||||
)
|
||||
.replace(
|
||||
"{release_month}",
|
||||
&format!("{:0>2}", sanitize(self.release_month.to_string(), true)),
|
||||
&format!("{:0>2}", sanitize(self.release_month.to_string(), true, universal)),
|
||||
)
|
||||
.replace(
|
||||
"{release_day}",
|
||||
&format!("{:0>2}", sanitize(self.release_day.to_string(), true)),
|
||||
&format!("{:0>2}", sanitize(self.release_day.to_string(), true, universal)),
|
||||
);
|
||||
|
||||
PathBuf::from(path)
|
||||
|
|
|
|||
|
|
@ -191,7 +191,7 @@ lazy_static::lazy_static! {
|
|||
}
|
||||
|
||||
/// Sanitizes a filename with the option to include/exclude the path separator from sanitizing.
|
||||
pub fn sanitize<S: AsRef<str>>(path: S, include_path_separator: bool) -> String {
|
||||
pub fn sanitize<S: AsRef<str>>(path: S, include_path_separator: bool, universal: bool) -> String {
|
||||
let path = Cow::from(path.as_ref().trim());
|
||||
|
||||
let path = RESERVED_RE.replace(&path, "");
|
||||
|
|
@ -204,7 +204,7 @@ pub fn sanitize<S: AsRef<str>>(path: S, include_path_separator: bool) -> String
|
|||
}
|
||||
};
|
||||
|
||||
if cfg!(windows) {
|
||||
if universal || cfg!(windows) {
|
||||
let path = WINDOWS_NON_PRINTABLE_RE.replace_all(&path, "");
|
||||
let path = WINDOWS_ILLEGAL_RE.replace_all(&path, "");
|
||||
let path = WINDOWS_RESERVED_RE.replace_all(&path, "");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue