mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Extend function to get free file
This commit is contained in:
parent
e9b3088cde
commit
afab3826c9
6 changed files with 37 additions and 17 deletions
|
|
@ -206,8 +206,7 @@ impl Execute for Archive {
|
|||
.to_string(),
|
||||
primary,
|
||||
)),
|
||||
)
|
||||
.0;
|
||||
);
|
||||
|
||||
info!(
|
||||
"Downloading {} to '{}'",
|
||||
|
|
@ -387,7 +386,7 @@ async fn download_video(ctx: &Context, format: &Format, only_audio: bool) -> Res
|
|||
ctx,
|
||||
&mut ffmpeg.stdin.unwrap(),
|
||||
Some(format!("Download {}", format.audio)),
|
||||
format.stream.clone()
|
||||
format.stream.clone(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
|
|
|||
|
|
@ -178,8 +178,7 @@ impl Execute for Download {
|
|||
.to_string(),
|
||||
&format,
|
||||
)),
|
||||
)
|
||||
.0;
|
||||
);
|
||||
|
||||
let use_ffmpeg = if let Some(extension) = path.extension() {
|
||||
if extension != "ts" {
|
||||
|
|
@ -228,11 +227,7 @@ impl Execute for Download {
|
|||
}
|
||||
}
|
||||
|
||||
async fn download_ffmpeg(
|
||||
ctx: &Context,
|
||||
variant_data: VariantData,
|
||||
target: &Path,
|
||||
) -> Result<()> {
|
||||
async fn download_ffmpeg(ctx: &Context, variant_data: VariantData, target: &Path) -> Result<()> {
|
||||
let ffmpeg = Command::new("ffmpeg")
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::null())
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ pub fn has_ffmpeg() -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
/// Any tempfiles should be created with this function. The prefix and directory of every file
|
||||
/// Any tempfile should be created with this function. The prefix and directory of every file
|
||||
/// created with this method stays the same which is helpful to query all existing tempfiles and
|
||||
/// e.g. remove them in a case of ctrl-c. Having one function also good to prevent mistakes like
|
||||
/// setting the wrong prefix if done manually.
|
||||
|
|
@ -36,17 +36,20 @@ pub fn tempfile<S: AsRef<str>>(suffix: S) -> io::Result<NamedTempFile> {
|
|||
}
|
||||
|
||||
/// Check if the given path exists and rename it until the new (renamed) file does not exist.
|
||||
pub fn free_file(mut path: PathBuf) -> (PathBuf, bool) {
|
||||
pub fn free_file(mut path: PathBuf) -> PathBuf {
|
||||
let mut i = 0;
|
||||
while path.exists() {
|
||||
i += 1;
|
||||
|
||||
let ext = path.extension().unwrap().to_str().unwrap();
|
||||
let mut filename = path.file_name().unwrap().to_str().unwrap();
|
||||
|
||||
filename = &filename[0..filename.len() - ext.len() - 1];
|
||||
let ext = path.extension().unwrap().to_string_lossy();
|
||||
let filename = path.file_stem().unwrap().to_string_lossy();
|
||||
|
||||
path.set_file_name(format!("{} ({}).{}", filename, i, ext))
|
||||
}
|
||||
(path, i != 0)
|
||||
sanitize_file(path)
|
||||
}
|
||||
|
||||
/// Sanitizes the given path to not contain any invalid file character.
|
||||
pub fn sanitize_file(path: PathBuf) -> PathBuf {
|
||||
path.with_file_name(sanitize_filename::sanitize(path.file_name().unwrap().to_string_lossy()))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue