Skip to content

Commit

Permalink
Add workaround for incorrect hardsub labeling (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
bytedream committed Jul 26, 2023
1 parent 4c396a9 commit 84c70f2
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 22 deletions.
17 changes: 7 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 7 additions & 10 deletions crunchy-cli-core/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crunchy-cli-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ anyhow = "1.0"
async-trait = "0.1"
clap = { version = "4.3", features = ["derive", "string"] }
chrono = "0.4"
crunchyroll-rs = { version = "0.5.0", features = ["dash-stream"] }
crunchyroll-rs = { version = "0.5.1", features = ["dash-stream"] }
ctrlc = "3.4"
dialoguer = { version = "0.10", default-features = false }
dirs = "5.0"
Expand Down
23 changes: 22 additions & 1 deletion crunchy-cli-core/src/utils/video.rs
Original file line number Diff line number Diff line change
@@ -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());
Expand Down

0 comments on commit 84c70f2

Please sign in to comment.