From a98e31f959892fed57a0510356a0c6a47a5c8672 Mon Sep 17 00:00:00 2001 From: bytedream Date: Tue, 14 May 2024 22:36:59 +0200 Subject: [PATCH] Only include one CC subtitle --- crunchy-cli-core/src/archive/command.rs | 31 +++++++++++-------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/crunchy-cli-core/src/archive/command.rs b/crunchy-cli-core/src/archive/command.rs index 44a30de..113447f 100644 --- a/crunchy-cli-core/src/archive/command.rs +++ b/crunchy-cli-core/src/archive/command.rs @@ -501,24 +501,21 @@ async fn get_format( .subtitle .iter() .flat_map(|s| { - let subtitles = stream - .subtitles - .get(s) - .cloned() - // the subtitle is probably cc if the audio is not japanese or only one - // subtitle exists for this stream - .map(|l| { - ( - l, - single_format.audio != Locale::ja_JP && stream.subtitles.len() == 1, - ) - }); - let cc = stream.captions.get(s).cloned().map(|l| (l, true)); - + let mut subtitles = vec![]; + if let Some(caption) = stream.captions.get(s) { + subtitles.push((caption.clone(), true)) + } + if let Some(subtitle) = stream.subtitles.get(s) { + // the subtitle is probably cc if the audio is not japanese or only one subtitle + // exists for this stream + let cc = single_format.audio != Locale::ja_JP && stream.subtitles.len() == 1; + // only include the subtitles if no cc subtitle is already present or if it's + // not cc + if subtitles.is_empty() || !cc { + subtitles.push((subtitle.clone(), cc)) + } + } subtitles - .into_iter() - .chain(cc.into_iter()) - .collect::>() }) .collect();