Skip to content
This repository has been archived by the owner on Jul 4, 2024. It is now read-only.

Commit

Permalink
Respect debug output when showing subtitle download spinner
Browse files Browse the repository at this point in the history
  • Loading branch information
bytedream committed Jul 12, 2023
1 parent 49de7bb commit 5133538
Showing 1 changed file with 39 additions and 22 deletions.
61 changes: 39 additions & 22 deletions crunchy-cli-core/src/utils/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,43 +205,60 @@ 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
let progress_spinner = if log::max_level() == LevelFilter::Info {
let progress_spinner = ProgressBar::new_spinner()
.with_style(
ProgressStyle::with_template(
format!(
":: {:<1$} {{msg}} {{spinner}}",
"Downloading subtitles", fmt_space
)
.as_str(),
)
.as_str(),
.unwrap()
.tick_strings(&["—", "\\", "|", "/", ""]),
)
.unwrap()
.tick_strings(&["—", "\\", "|", "/", ""]),
)
.with_finish(ProgressFinish::Abandon);
pb.enable_steady_tick(Duration::from_millis(100));
.with_finish(ProgressFinish::Abandon);
progress_spinner.enable_steady_tick(Duration::from_millis(100));
Some(progress_spinner)
} else {
None
};

let len = get_video_length(&video_path)?;
for (subtitle, not_cc) in format.subtitles.iter() {
let mut progress_message = pb.message();
if !progress_message.is_empty() {
progress_message += ", "
if let Some(pb) = &progress_spinner {
let mut progress_message = pb.message();
if !progress_message.is_empty() {
progress_message += ", "
}
progress_message += &subtitle.locale.to_string();
if !not_cc {
progress_message += " (CC)";
}
if i != 0 {
progress_message += &format!(" [Video: #{}]", i + 1);
}
pb.set_message(progress_message)
}
progress_message += &subtitle.locale.to_string();
let mut subtitle_title = subtitle.locale.to_human_readable();

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?;
debug!(
"Downloaded {} subtitles{}{}",
subtitle.locale,
(!not_cc).then_some(" (cc)").unwrap_or_default(),
(i != 0)
.then_some(format!(" for video {}", i))
.unwrap_or_default()
);
subtitles.push(FFmpegMeta {
path: subtitle_path,
language: subtitle.locale.clone(),
Expand Down

0 comments on commit 5133538

Please sign in to comment.