From 7cf7a8e71c476c56806da00a8f41a92db0e44350 Mon Sep 17 00:00:00 2001 From: bytedream Date: Sun, 28 Jan 2024 02:04:42 +0100 Subject: [PATCH] Take closed_captions api field for subtitles into account (#297) --- crunchy-cli-core/src/archive/command.rs | 12 +++++++++--- crunchy-cli-core/src/download/command.rs | 7 ++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/crunchy-cli-core/src/archive/command.rs b/crunchy-cli-core/src/archive/command.rs index 331374a..065b3da 100644 --- a/crunchy-cli-core/src/archive/command.rs +++ b/crunchy-cli-core/src/archive/command.rs @@ -301,8 +301,8 @@ async fn get_format( let subtitles: Vec<(Subtitle, bool)> = archive .subtitle .iter() - .filter_map(|s| { - stream + .flat_map(|s| { + let subtitles = stream .subtitles .get(s) .cloned() @@ -313,7 +313,13 @@ async fn get_format( l, single_format.audio == Locale::ja_JP || stream.subtitles.len() > 1, ) - }) + }); + let cc = stream.closed_captions.get(s).cloned().map(|l| (l, false)); + + subtitles + .into_iter() + .chain(cc.into_iter()) + .collect::>() }) .collect(); diff --git a/crunchy-cli-core/src/download/command.rs b/crunchy-cli-core/src/download/command.rs index f72923f..d1565c7 100644 --- a/crunchy-cli-core/src/download/command.rs +++ b/crunchy-cli-core/src/download/command.rs @@ -317,7 +317,12 @@ async fn get_format( let subtitle = if contains_hardsub { None } else if let Some(subtitle_locale) = &download.subtitle { - stream.subtitles.get(subtitle_locale).cloned() + stream + .subtitles + .get(subtitle_locale) + .cloned() + // use closed captions as fallback if no actual subtitles are found + .or_else(|| stream.closed_captions.get(subtitle_locale).cloned()) } else { None };