mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 04:02:00 -06:00
Fix video containing hardsub if not requested (#415)
This commit is contained in:
parent
48bb7a5ef6
commit
817963af4f
2 changed files with 18 additions and 26 deletions
|
|
@ -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 {
|
||||||
stream
|
if download.audio == Locale::ja_JP {
|
||||||
.subtitles
|
stream
|
||||||
.get(subtitle_locale)
|
.subtitles
|
||||||
.cloned()
|
.get(subtitle_locale)
|
||||||
// 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
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
|
||||||
// fallback to `None`. this should trigger an error message in `stream.dash_streaming_data`
|
|
||||||
// that the requested stream is not available
|
|
||||||
(None, false)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
let hardsubs_requested = subtitle.is_some();
|
(None, false)
|
||||||
(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 {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue