mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Add workaround for incorrect hardsub labeling (#231)
This commit is contained in:
parent
4c396a9e4a
commit
84c70f2bee
4 changed files with 37 additions and 22 deletions
|
|
@ -1,11 +1,32 @@
|
|||
use anyhow::Result;
|
||||
use crunchyroll_rs::media::{Resolution, Stream, VariantData};
|
||||
use crunchyroll_rs::Locale;
|
||||
|
||||
pub async fn variant_data_from_stream(
|
||||
stream: &Stream,
|
||||
resolution: &Resolution,
|
||||
) -> Result<Option<(VariantData, VariantData)>> {
|
||||
let mut streaming_data = stream.dash_streaming_data(None).await?;
|
||||
// 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 = stream.streaming_hardsub_locales();
|
||||
let hardsub_locale = 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))
|
||||
} else {
|
||||
// fallback to `None`. this should trigger an error message in `stream.dash_streaming_data`
|
||||
// that the requested stream is not available
|
||||
None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let mut streaming_data = stream.dash_streaming_data(hardsub_locale).await?;
|
||||
streaming_data
|
||||
.0
|
||||
.sort_by(|a, b| a.bandwidth.cmp(&b.bandwidth).reverse());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue