From 541f0e27477848e92baf1c6b3f0a512d2d202f29 Mon Sep 17 00:00:00 2001 From: bytedream Date: Tue, 23 Apr 2024 16:00:42 +0200 Subject: [PATCH] Fix wrong audio and subtitle video reference number (#384) --- crunchy-cli-core/src/utils/download.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/crunchy-cli-core/src/utils/download.rs b/crunchy-cli-core/src/utils/download.rs index a17875d..6882a42 100644 --- a/crunchy-cli-core/src/utils/download.rs +++ b/crunchy-cli-core/src/utils/download.rs @@ -128,6 +128,7 @@ struct FFmpegAudioMeta { path: TempPath, locale: Locale, start_time: Option, + video_idx: usize, } struct FFmpegSubtitleMeta { @@ -135,6 +136,7 @@ struct FFmpegSubtitleMeta { locale: Locale, cc: bool, start_time: Option, + video_idx: usize, } pub struct DownloadFormat { @@ -433,7 +435,7 @@ impl Downloader { } // downloads all audios - for format in &self.formats { + for (i, format) in self.formats.iter().enumerate() { for (j, (stream_data, locale)) in format.audios.iter().enumerate() { let path = self .download_audio( @@ -445,6 +447,7 @@ impl Downloader { path, locale: locale.clone(), start_time: audio_offsets.get(&j).cloned(), + video_idx: i, }) } } @@ -507,6 +510,7 @@ impl Downloader { locale: subtitle.locale.clone(), cc: !not_cc, start_time: subtitle_offsets.get(&j).cloned(), + video_idx: i, }) } } @@ -632,7 +636,11 @@ impl Downloader { if videos.len() == 1 { meta.locale.to_human_readable() } else { - format!("{} [Video: #{}]", meta.locale.to_human_readable(), i + 1,) + format!( + "{} [Video: #{}]", + meta.locale.to_human_readable(), + meta.video_idx + 1 + ) } ), ]); @@ -679,7 +687,7 @@ impl Downloader { title += " (CC)" } if videos.len() > 1 { - title += &format!(" [Video: #{}]", i + 1) + title += &format!(" [Video: #{}]", meta.video_idx + 1) } title }),