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

Commit

Permalink
Take closed_captions api field for subtitles into account (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
bytedream committed Jan 28, 2024
1 parent 3b9fc52 commit 7cf7a8e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
12 changes: 9 additions & 3 deletions crunchy-cli-core/src/archive/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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::<Vec<(Subtitle, bool)>>()
})
.collect();

Expand Down
7 changes: 6 additions & 1 deletion crunchy-cli-core/src/download/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down

0 comments on commit 7cf7a8e

Please sign in to comment.