mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Fix output formatting for full path (#101)
This commit is contained in:
parent
13f54c0da6
commit
4b33ef02c6
3 changed files with 18 additions and 31 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::cli::log::tab_info;
|
use crate::cli::log::tab_info;
|
||||||
use crate::cli::utils::{download_segments, find_resolution, FFmpegPreset, find_multiple_seasons_with_same_number, interactive_season_choosing};
|
use crate::cli::utils::{download_segments, find_resolution, FFmpegPreset, find_multiple_seasons_with_same_number, interactive_season_choosing};
|
||||||
use crate::utils::context::Context;
|
use crate::utils::context::Context;
|
||||||
use crate::utils::format::{format_string, Format};
|
use crate::utils::format::{Format, format_path};
|
||||||
use crate::utils::log::progress;
|
use crate::utils::log::progress;
|
||||||
use crate::utils::os::{free_file, has_ffmpeg, is_special_file, tempfile};
|
use crate::utils::os::{free_file, has_ffmpeg, is_special_file, tempfile};
|
||||||
use crate::utils::parse::{parse_url, UrlFilter};
|
use crate::utils::parse::{parse_url, UrlFilter};
|
||||||
|
|
@ -240,19 +240,11 @@ impl Execute for Archive {
|
||||||
for (formats, mut subtitles) in archive_formats {
|
for (formats, mut subtitles) in archive_formats {
|
||||||
let (primary, additionally) = formats.split_first().unwrap();
|
let (primary, additionally) = formats.split_first().unwrap();
|
||||||
|
|
||||||
let mut path = PathBuf::from(&self.output);
|
let path = free_file(format_path(if self.output.is_empty() {
|
||||||
path = free_file(
|
|
||||||
path.with_file_name(format_string(
|
|
||||||
if let Some(fname) = path.file_name() {
|
|
||||||
fname.to_str().unwrap()
|
|
||||||
} else {
|
|
||||||
"{title}.mkv"
|
"{title}.mkv"
|
||||||
}
|
} else {
|
||||||
.to_string(),
|
&self.output
|
||||||
primary,
|
}.into(), &primary, true));
|
||||||
true,
|
|
||||||
)),
|
|
||||||
);
|
|
||||||
|
|
||||||
info!(
|
info!(
|
||||||
"Downloading {} to '{}'",
|
"Downloading {} to '{}'",
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::cli::log::tab_info;
|
use crate::cli::log::tab_info;
|
||||||
use crate::cli::utils::{download_segments, find_resolution, FFmpegPreset, interactive_season_choosing, find_multiple_seasons_with_same_number};
|
use crate::cli::utils::{download_segments, find_resolution, FFmpegPreset, interactive_season_choosing, find_multiple_seasons_with_same_number};
|
||||||
use crate::utils::context::Context;
|
use crate::utils::context::Context;
|
||||||
use crate::utils::format::{format_string, Format};
|
use crate::utils::format::{Format, format_path};
|
||||||
use crate::utils::log::progress;
|
use crate::utils::log::progress;
|
||||||
use crate::utils::os::{free_file, has_ffmpeg, is_special_file};
|
use crate::utils::os::{free_file, has_ffmpeg, is_special_file};
|
||||||
use crate::utils::parse::{parse_url, UrlFilter};
|
use crate::utils::parse::{parse_url, UrlFilter};
|
||||||
|
|
@ -206,19 +206,11 @@ impl Execute for Download {
|
||||||
}
|
}
|
||||||
|
|
||||||
for format in formats {
|
for format in formats {
|
||||||
let mut path = PathBuf::from(&self.output);
|
let path = free_file(format_path(if self.output.is_empty() {
|
||||||
path = free_file(
|
"{title}.mkv"
|
||||||
path.with_file_name(format_string(
|
|
||||||
if let Some(fname) = path.file_name() {
|
|
||||||
fname.to_str().unwrap()
|
|
||||||
} else {
|
} else {
|
||||||
"{title}.ts"
|
&self.output
|
||||||
}
|
}.into(), &format, true));
|
||||||
.to_string(),
|
|
||||||
&format,
|
|
||||||
true,
|
|
||||||
)),
|
|
||||||
);
|
|
||||||
|
|
||||||
info!(
|
info!(
|
||||||
"Downloading {} to '{}'",
|
"Downloading {} to '{}'",
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
use std::path::PathBuf;
|
||||||
use crunchyroll_rs::media::VariantData;
|
use crunchyroll_rs::media::VariantData;
|
||||||
use crunchyroll_rs::{Episode, Locale, Media, Movie};
|
use crunchyroll_rs::{Episode, Locale, Media, Movie};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
@ -65,7 +66,7 @@ impl Format {
|
||||||
|
|
||||||
/// Formats the given string if it has specific pattern in it. It's possible to sanitize it which
|
/// Formats the given string if it has specific pattern in it. It's possible to sanitize it which
|
||||||
/// removes characters which can cause failures if the output string is used as a file name.
|
/// removes characters which can cause failures if the output string is used as a file name.
|
||||||
pub fn format_string(s: String, format: &Format, sanitize: bool) -> String {
|
pub fn format_path(path: PathBuf, format: &Format, sanitize: bool) -> PathBuf {
|
||||||
let sanitize_func = if sanitize {
|
let sanitize_func = if sanitize {
|
||||||
|s: &str| sanitize_filename::sanitize(s)
|
|s: &str| sanitize_filename::sanitize(s)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -73,7 +74,9 @@ pub fn format_string(s: String, format: &Format, sanitize: bool) -> String {
|
||||||
|s: &str| s.to_string()
|
|s: &str| s.to_string()
|
||||||
};
|
};
|
||||||
|
|
||||||
s.replace("{title}", &sanitize_func(&format.title))
|
let as_string = path.to_string_lossy().to_string();
|
||||||
|
|
||||||
|
PathBuf::from(as_string.replace("{title}", &sanitize_func(&format.title))
|
||||||
.replace("{series_name}", &sanitize_func(&format.series_name))
|
.replace("{series_name}", &sanitize_func(&format.series_name))
|
||||||
.replace("{season_name}", &sanitize_func(&format.season_title))
|
.replace("{season_name}", &sanitize_func(&format.season_title))
|
||||||
.replace("{audio}", &sanitize_func(&format.audio.to_string()))
|
.replace("{audio}", &sanitize_func(&format.audio.to_string()))
|
||||||
|
|
@ -99,5 +102,5 @@ pub fn format_string(s: String, format: &Format, sanitize: bool) -> String {
|
||||||
)
|
)
|
||||||
.replace("{series_id}", &sanitize_func(&format.series_id))
|
.replace("{series_id}", &sanitize_func(&format.series_id))
|
||||||
.replace("{season_id}", &sanitize_func(&format.season_id))
|
.replace("{season_id}", &sanitize_func(&format.season_id))
|
||||||
.replace("{episode_id}", &sanitize_func(&format.id))
|
.replace("{episode_id}", &sanitize_func(&format.id)))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue