mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Format code
This commit is contained in:
parent
56411c6547
commit
fc6511a361
13 changed files with 42 additions and 48 deletions
|
|
@ -296,7 +296,7 @@ impl Downloader {
|
|||
]);
|
||||
// the empty language metadata is created to avoid that metadata from the original track
|
||||
// is copied
|
||||
metadata.extend([format!("-metadata:s:v:{}", i), format!("language=")])
|
||||
metadata.extend([format!("-metadata:s:v:{}", i), "language=".to_string()])
|
||||
}
|
||||
for (i, meta) in audios.iter().enumerate() {
|
||||
input.extend(["-i".to_string(), meta.path.to_string_lossy().to_string()]);
|
||||
|
|
@ -675,7 +675,7 @@ impl Downloader {
|
|||
|
||||
let result = download().await;
|
||||
if result.is_err() {
|
||||
after_download_sender.send((-1 as i32, vec![]))?;
|
||||
after_download_sender.send((-1, vec![]))?;
|
||||
}
|
||||
|
||||
result
|
||||
|
|
@ -747,7 +747,7 @@ impl Downloader {
|
|||
}
|
||||
}
|
||||
|
||||
fn estimate_variant_file_size(variant_data: &VariantData, segments: &Vec<VariantSegment>) -> u64 {
|
||||
fn estimate_variant_file_size(variant_data: &VariantData, segments: &[VariantSegment]) -> u64 {
|
||||
(variant_data.bandwidth / 8) * segments.iter().map(|s| s.length.as_secs()).sum::<u64>()
|
||||
}
|
||||
|
||||
|
|
@ -788,9 +788,8 @@ pub fn get_video_length(path: &Path) -> Result<NaiveTime> {
|
|||
/// [crunchy-labs/crunchy-cli#208](https://github.com/crunchy-labs/crunchy-cli/issues/208) for more
|
||||
/// information.
|
||||
fn fix_subtitles(raw: &mut Vec<u8>, max_length: NaiveTime) {
|
||||
let re =
|
||||
Regex::new(r#"^Dialogue:\s\d+,(?P<start>\d+:\d+:\d+\.\d+),(?P<end>\d+:\d+:\d+\.\d+),"#)
|
||||
.unwrap();
|
||||
let re = Regex::new(r"^Dialogue:\s\d+,(?P<start>\d+:\d+:\d+\.\d+),(?P<end>\d+:\d+:\d+\.\d+),")
|
||||
.unwrap();
|
||||
|
||||
// chrono panics if we try to format NaiveTime with `%2f` and the nano seconds has more than 2
|
||||
// digits so them have to be reduced manually to avoid the panic
|
||||
|
|
@ -832,7 +831,7 @@ fn fix_subtitles(raw: &mut Vec<u8>, max_length: NaiveTime) {
|
|||
line,
|
||||
format!(
|
||||
"Dialogue: {},{},",
|
||||
format_naive_time(start.clone()),
|
||||
format_naive_time(start),
|
||||
&length_as_string
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ impl FFmpegPreset {
|
|||
description_details.push(format!("{} video quality/compression", q.to_string()))
|
||||
}
|
||||
|
||||
let description = if description_details.len() == 0 {
|
||||
let description = if description_details.is_empty() {
|
||||
format!(
|
||||
"{} encoded with default video quality/compression",
|
||||
codec.to_string()
|
||||
|
|
@ -239,7 +239,7 @@ impl FFmpegPreset {
|
|||
hwaccel.clone(),
|
||||
quality.clone(),
|
||||
)) {
|
||||
return Err(format!("ffmpeg preset is not supported"));
|
||||
return Err("ffmpeg preset is not supported".to_string());
|
||||
}
|
||||
Ok(FFmpegPreset::Predefined(
|
||||
c,
|
||||
|
|
@ -247,7 +247,7 @@ impl FFmpegPreset {
|
|||
quality.unwrap_or(FFmpegQuality::Normal),
|
||||
))
|
||||
} else {
|
||||
Err(format!("cannot use ffmpeg preset with without a codec"))
|
||||
Err("cannot use ffmpeg preset with without a codec".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -170,10 +170,7 @@ impl SingleFormat {
|
|||
}
|
||||
|
||||
pub fn is_episode(&self) -> bool {
|
||||
match self.source {
|
||||
MediaCollection::Episode(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self.source, MediaCollection::Episode(_))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -181,7 +178,7 @@ struct SingleFormatCollectionEpisodeKey(f32);
|
|||
|
||||
impl PartialOrd for SingleFormatCollectionEpisodeKey {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
self.0.partial_cmp(&other.0)
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
impl Ord for SingleFormatCollectionEpisodeKey {
|
||||
|
|
@ -198,6 +195,7 @@ impl Eq for SingleFormatCollectionEpisodeKey {}
|
|||
|
||||
struct SingleFormatCollectionSeasonKey((u32, String));
|
||||
|
||||
#[allow(clippy::incorrect_partial_ord_impl_on_ord_type)]
|
||||
impl PartialOrd for SingleFormatCollectionSeasonKey {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
let mut cmp = self.0 .0.partial_cmp(&other.0 .0);
|
||||
|
|
@ -250,7 +248,7 @@ impl SingleFormatCollection {
|
|||
format.season_number,
|
||||
format.season_id.clone(),
|
||||
)))
|
||||
.or_insert(BTreeMap::new())
|
||||
.or_default()
|
||||
.insert(
|
||||
SingleFormatCollectionEpisodeKey(format.sequence_number),
|
||||
single_formats,
|
||||
|
|
@ -340,6 +338,7 @@ pub struct Format {
|
|||
}
|
||||
|
||||
impl Format {
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub fn from_single_formats(
|
||||
mut single_formats: Vec<(SingleFormat, VariantData, Vec<(Subtitle, bool)>)>,
|
||||
) -> Self {
|
||||
|
|
@ -349,7 +348,7 @@ impl Format {
|
|||
(
|
||||
single_format.audio.clone(),
|
||||
subtitles
|
||||
.into_iter()
|
||||
.iter()
|
||||
.map(|(s, _)| s.locale.clone())
|
||||
.collect::<Vec<Locale>>(),
|
||||
)
|
||||
|
|
@ -440,7 +439,7 @@ impl Format {
|
|||
info!(
|
||||
"Downloading {} to {}",
|
||||
self.title,
|
||||
if is_special_file(&dst) || dst.to_str().unwrap() == "-" {
|
||||
if is_special_file(dst) || dst.to_str().unwrap() == "-" {
|
||||
dst.to_string_lossy().to_string()
|
||||
} else {
|
||||
format!("'{}'", dst.to_str().unwrap())
|
||||
|
|
|
|||
|
|
@ -19,8 +19,7 @@ pub fn system_locale() -> Locale {
|
|||
pub fn all_locale_in_locales(locales: Vec<Locale>) -> Vec<Locale> {
|
||||
if locales
|
||||
.iter()
|
||||
.find(|l| l.to_string().to_lowercase().trim() == "all")
|
||||
.is_some()
|
||||
.any(|l| l.to_string().to_lowercase().trim() == "all")
|
||||
{
|
||||
Locale::all()
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -57,7 +57,6 @@ macro_rules! tab_info {
|
|||
}
|
||||
pub(crate) use tab_info;
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub struct CliLogger {
|
||||
level: LevelFilter,
|
||||
progress: Mutex<Option<ProgressBar>>,
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ pub fn has_ffmpeg() -> bool {
|
|||
/// Get the temp directory either by the specified `CRUNCHY_CLI_TEMP_DIR` env variable or the dir
|
||||
/// provided by the os.
|
||||
pub fn temp_directory() -> PathBuf {
|
||||
env::var("CRUNCHY_CLI_TEMP_DIR").map_or(env::temp_dir(), |d| PathBuf::from(d))
|
||||
env::var("CRUNCHY_CLI_TEMP_DIR").map_or(env::temp_dir(), PathBuf::from)
|
||||
}
|
||||
|
||||
/// Any tempfile should be created with this function. The prefix and directory of every file
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue