From 817963af4fbf0eef1fde26a02f0771e343ce35d9 Mon Sep 17 00:00:00 2001 From: bytedream Date: Tue, 14 May 2024 21:22:23 +0200 Subject: [PATCH] Fix video containing hardsub if not requested (#415) --- crunchy-cli-core/src/download/command.rs | 20 ++++++++++++++------ crunchy-cli-core/src/utils/video.rs | 24 ++++-------------------- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/crunchy-cli-core/src/download/command.rs b/crunchy-cli-core/src/download/command.rs index bb0c1fd..a9c3acf 100644 --- a/crunchy-cli-core/src/download/command.rs +++ b/crunchy-cli-core/src/download/command.rs @@ -384,12 +384,20 @@ async fn get_format( let subtitle = if contains_hardsub { None } else if let Some(subtitle_locale) = &download.subtitle { - stream - .subtitles - .get(subtitle_locale) - .cloned() - // use closed captions as fallback if no actual subtitles are found - .or_else(|| stream.captions.get(subtitle_locale).cloned()) + if download.audio == Locale::ja_JP { + stream + .subtitles + .get(subtitle_locale) + // use closed captions as fallback if no actual subtitles are found + .or_else(|| stream.captions.get(subtitle_locale)) + .cloned() + } else { + stream + .captions + .get(subtitle_locale) + .or_else(|| stream.subtitles.get(subtitle_locale)) + .cloned() + } } else { None }; diff --git a/crunchy-cli-core/src/utils/video.rs b/crunchy-cli-core/src/utils/video.rs index 07f6e76..8b25791 100644 --- a/crunchy-cli-core/src/utils/video.rs +++ b/crunchy-cli-core/src/utils/video.rs @@ -5,28 +5,12 @@ use crunchyroll_rs::Locale; pub async fn stream_data_from_stream( stream: &Stream, resolution: &Resolution, - subtitle: Option, + hardsub_subtitle: Option, ) -> Result> { - // sometimes Crunchyroll marks episodes without real subtitles that they have subtitles and - // reports that only hardsub episode are existing. the following lines are trying to prevent - // potential errors which might get caused by this incorrect reporting - // (https://github.com/crunchy-labs/crunchy-cli/issues/231) - let mut hardsub_locales: Vec = stream.hard_subs.keys().cloned().collect(); - let (hardsub_locale, mut contains_hardsub) = if !hardsub_locales - .contains(&Locale::Custom("".to_string())) - && !hardsub_locales.contains(&Locale::Custom(":".to_string())) - { - // if only one hardsub locale exists, assume that this stream doesn't really contains hardsubs - if hardsub_locales.len() == 1 { - (Some(hardsub_locales.remove(0)), false) - } else { - // fallback to `None`. this should trigger an error message in `stream.dash_streaming_data` - // that the requested stream is not available - (None, false) - } + let (hardsub_locale, mut contains_hardsub) = if hardsub_subtitle.is_some() { + (hardsub_subtitle, true) } else { - let hardsubs_requested = subtitle.is_some(); - (subtitle, hardsubs_requested) + (None, false) }; let (mut videos, mut audios) = match stream.stream_data(hardsub_locale).await {