This commit is contained in:
ByteDream 2022-12-08 01:37:37 +01:00
parent a32d3aef87
commit 54018f9773
3 changed files with 18 additions and 7 deletions

View file

@ -68,7 +68,12 @@ impl Execute for Download {
fn pre_check(&self) -> Result<()> {
if has_ffmpeg() {
debug!("FFmpeg detected")
} else if PathBuf::from(&self.output).extension().unwrap_or_default().to_string_lossy() != "ts" {
} else if PathBuf::from(&self.output)
.extension()
.unwrap_or_default()
.to_string_lossy()
!= "ts"
{
bail!("File extension is not '.ts'. If you want to use a custom file format, please install ffmpeg")
}

View file

@ -12,11 +12,13 @@ use std::{env, fs};
mod cli;
mod utils;
pub use cli::{archive::Archive, download::Download, login::Login};
pub use cli::{archive::Archive, download::Download, login::Login, search::Search};
#[async_trait::async_trait(?Send)]
trait Execute {
fn pre_check(&self) -> Result<()> { Ok(()) }
fn pre_check(&self) -> Result<()> {
Ok(())
}
async fn execute(self, ctx: Context) -> Result<()>;
}
@ -57,6 +59,7 @@ enum Command {
Archive(Archive),
Download(Download),
Login(Login),
Search(Search),
}
#[derive(Debug, Parser)]
@ -153,7 +156,7 @@ pub async fn cli_entrypoint() {
debug!("Created ctrl-c handler");
match cli.command {
Command::Archive(archive) => execute_executor(archive,ctx).await,
Command::Archive(archive) => execute_executor(archive, ctx).await,
Command::Download(download) => execute_executor(download, ctx).await,
Command::Login(login) => {
if login.remove {
@ -162,6 +165,7 @@ pub async fn cli_entrypoint() {
execute_executor(login, ctx).await
}
}
Command::Search(search) => execute_executor(search, ctx).await,
};
}

View file

@ -44,8 +44,8 @@ pub fn free_file(mut path: PathBuf) -> PathBuf {
let ext = path.extension().unwrap().to_string_lossy();
let mut filename = path.file_stem().unwrap().to_str().unwrap();
if filename.ends_with(&format!(" ({})", i-1)) {
filename = filename.strip_suffix(&format!(" ({})", i-1)).unwrap();
if filename.ends_with(&format!(" ({})", i - 1)) {
filename = filename.strip_suffix(&format!(" ({})", i - 1)).unwrap();
}
path.set_file_name(format!("{} ({}).{}", filename, i, ext))
@ -55,5 +55,7 @@ pub fn free_file(mut path: PathBuf) -> PathBuf {
/// 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()))
path.with_file_name(sanitize_filename::sanitize(
path.file_name().unwrap().to_string_lossy(),
))
}