Fix video containing hardsub if not requested (#415)

This commit is contained in:
bytedream 2024-05-14 21:22:23 +02:00
parent 48bb7a5ef6
commit 817963af4f
2 changed files with 18 additions and 26 deletions

View file

@ -384,12 +384,20 @@ async fn get_format(
let subtitle = if contains_hardsub { let subtitle = if contains_hardsub {
None None
} else if let Some(subtitle_locale) = &download.subtitle { } else if let Some(subtitle_locale) = &download.subtitle {
if download.audio == Locale::ja_JP {
stream stream
.subtitles .subtitles
.get(subtitle_locale) .get(subtitle_locale)
.cloned()
// use closed captions as fallback if no actual subtitles are found // use closed captions as fallback if no actual subtitles are found
.or_else(|| stream.captions.get(subtitle_locale).cloned()) .or_else(|| stream.captions.get(subtitle_locale))
.cloned()
} else {
stream
.captions
.get(subtitle_locale)
.or_else(|| stream.subtitles.get(subtitle_locale))
.cloned()
}
} else { } else {
None None
}; };

View file

@ -5,28 +5,12 @@ use crunchyroll_rs::Locale;
pub async fn stream_data_from_stream( pub async fn stream_data_from_stream(
stream: &Stream, stream: &Stream,
resolution: &Resolution, resolution: &Resolution,
subtitle: Option<Locale>, hardsub_subtitle: Option<Locale>,
) -> Result<Option<(StreamData, StreamData, bool)>> { ) -> Result<Option<(StreamData, StreamData, bool)>> {
// sometimes Crunchyroll marks episodes without real subtitles that they have subtitles and let (hardsub_locale, mut contains_hardsub) = if hardsub_subtitle.is_some() {
// reports that only hardsub episode are existing. the following lines are trying to prevent (hardsub_subtitle, true)
// potential errors which might get caused by this incorrect reporting
// (https://github.com/crunchy-labs/crunchy-cli/issues/231)
let mut hardsub_locales: Vec<Locale> = 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 { } else {
// fallback to `None`. this should trigger an error message in `stream.dash_streaming_data`
// that the requested stream is not available
(None, false) (None, false)
}
} else {
let hardsubs_requested = subtitle.is_some();
(subtitle, hardsubs_requested)
}; };
let (mut videos, mut audios) = match stream.stream_data(hardsub_locale).await { let (mut videos, mut audios) = match stream.stream_data(hardsub_locale).await {