mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 04:02:00 -06:00
Add progress indicator for subtitle download
This commit is contained in:
parent
751735477c
commit
49de7bbba9
2 changed files with 49 additions and 20 deletions
|
|
@ -204,22 +204,51 @@ impl Downloader {
|
|||
},
|
||||
})
|
||||
}
|
||||
if !format.subtitles.is_empty() {
|
||||
#[cfg(not(windows))]
|
||||
let pb = ProgressBar::new_spinner()
|
||||
.with_style(
|
||||
ProgressStyle::with_template(
|
||||
format!(
|
||||
":: {:<1$} {{msg}} {{spinner}}",
|
||||
"Downloading subtitles", fmt_space
|
||||
)
|
||||
.as_str(),
|
||||
)
|
||||
.unwrap()
|
||||
.tick_strings(&["—", "\\", "|", "/", ""]),
|
||||
)
|
||||
.with_finish(ProgressFinish::Abandon);
|
||||
pb.enable_steady_tick(Duration::from_millis(100));
|
||||
|
||||
let len = get_video_length(&video_path)?;
|
||||
for (subtitle, not_cc) in format.subtitles.iter() {
|
||||
let subtitle_path = self.download_subtitle(subtitle.clone(), len).await?;
|
||||
let mut progress_message = pb.message();
|
||||
if !progress_message.is_empty() {
|
||||
progress_message += ", "
|
||||
}
|
||||
progress_message += &subtitle.locale.to_string();
|
||||
let mut subtitle_title = subtitle.locale.to_human_readable();
|
||||
|
||||
if !not_cc {
|
||||
progress_message += " (CC)";
|
||||
subtitle_title += " (CC)"
|
||||
}
|
||||
if i != 0 {
|
||||
progress_message += &format!(" [Video: #{}]", i + 1);
|
||||
subtitle_title += &format!(" [Video: #{}]", i + 1)
|
||||
}
|
||||
|
||||
pb.set_message(progress_message);
|
||||
|
||||
let subtitle_path = self.download_subtitle(subtitle.clone(), len).await?;
|
||||
subtitles.push(FFmpegMeta {
|
||||
path: subtitle_path,
|
||||
language: subtitle.locale.clone(),
|
||||
title: subtitle_title,
|
||||
})
|
||||
}
|
||||
}
|
||||
videos.push(FFmpegMeta {
|
||||
path: video_path,
|
||||
language: format.video.1.clone(),
|
||||
|
|
@ -454,7 +483,7 @@ impl Downloader {
|
|||
let tempfile = tempfile(".mp4")?;
|
||||
let (mut file, path) = tempfile.into_parts();
|
||||
|
||||
download_segments(ctx, &mut file, Some(message), variant_data).await?;
|
||||
download_segments(ctx, &mut file, message, variant_data).await?;
|
||||
|
||||
Ok(path)
|
||||
}
|
||||
|
|
@ -468,7 +497,7 @@ impl Downloader {
|
|||
let tempfile = tempfile(".m4a")?;
|
||||
let (mut file, path) = tempfile.into_parts();
|
||||
|
||||
download_segments(ctx, &mut file, Some(message), variant_data).await?;
|
||||
download_segments(ctx, &mut file, message, variant_data).await?;
|
||||
|
||||
Ok(path)
|
||||
}
|
||||
|
|
@ -494,7 +523,7 @@ impl Downloader {
|
|||
pub async fn download_segments(
|
||||
ctx: &Context,
|
||||
writer: &mut impl Write,
|
||||
message: Option<String>,
|
||||
message: String,
|
||||
variant_data: &VariantData,
|
||||
) -> Result<()> {
|
||||
let segments = variant_data.segments().await?;
|
||||
|
|
@ -514,7 +543,7 @@ pub async fn download_segments(
|
|||
.unwrap()
|
||||
.progress_chars("##-"),
|
||||
)
|
||||
.with_message(message.map(|m| m + " ").unwrap_or_default())
|
||||
.with_message(message)
|
||||
.with_finish(ProgressFinish::Abandon);
|
||||
Some(progress)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ impl CliLogger {
|
|||
let finish_str = "✔";
|
||||
#[cfg(windows)]
|
||||
// windows does not support all unicode characters by default in their consoles, so
|
||||
// we're using this (square root?) symbol instead. microsoft.
|
||||
// we're using this (square root) symbol instead. microsoft.
|
||||
let finish_str = "√";
|
||||
|
||||
let pb = ProgressBar::new_spinner();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue