From 84c70f2bee6525b49b87e34bc5cf1209f4a7a105 Mon Sep 17 00:00:00 2001 From: bytedream Date: Wed, 26 Jul 2023 20:51:34 +0200 Subject: [PATCH] Add workaround for incorrect hardsub labeling (#231) --- Cargo.lock | 17 +++++++---------- crunchy-cli-core/Cargo.lock | 17 +++++++---------- crunchy-cli-core/Cargo.toml | 2 +- crunchy-cli-core/src/utils/video.rs | 23 ++++++++++++++++++++++- 4 files changed, 37 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 362e019..56ec987 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -412,9 +412,9 @@ dependencies = [ [[package]] name = "crunchyroll-rs" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1fc76ad1ab97992a987dd2a5fadfa4e90fc69d337704f42b7eeb30f7fda1eb1" +checksum = "a0b33d2464e990dec5d3e6265cc892a88ab89971cfd177b7d7c7d0e9f8cde817" dependencies = [ "aes", "async-trait", @@ -434,14 +434,14 @@ dependencies = [ "serde_urlencoded", "smart-default", "tokio", - "webpki-roots 0.24.0", + "webpki-roots 0.25.0", ] [[package]] name = "crunchyroll-rs-internal" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f9581dc7276f1c327dcaa91fa6d3b3f09c46018dc5a0d7815be3f8027780a07" +checksum = "cab3e4af975066a3dc3dd0bb50b1a29c4a3cdee5365e8b6559d21aa15d9ace6a" dependencies = [ "darling", "quote", @@ -2088,12 +2088,9 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.24.0" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b291546d5d9d1eab74f069c77749f2cb8504a12caa20f0f2de93ddbf6f411888" -dependencies = [ - "rustls-webpki", -] +checksum = "1a4ac452058d835c2b7ff6d74f0ad9f40e172bb1ce661b1444f397eeb1d19e6d" [[package]] name = "winapi" diff --git a/crunchy-cli-core/Cargo.lock b/crunchy-cli-core/Cargo.lock index f3acc59..a5f9b1d 100644 --- a/crunchy-cli-core/Cargo.lock +++ b/crunchy-cli-core/Cargo.lock @@ -381,9 +381,9 @@ dependencies = [ [[package]] name = "crunchyroll-rs" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1fc76ad1ab97992a987dd2a5fadfa4e90fc69d337704f42b7eeb30f7fda1eb1" +checksum = "a0b33d2464e990dec5d3e6265cc892a88ab89971cfd177b7d7c7d0e9f8cde817" dependencies = [ "aes", "async-trait", @@ -403,14 +403,14 @@ dependencies = [ "serde_urlencoded", "smart-default", "tokio", - "webpki-roots 0.24.0", + "webpki-roots 0.25.0", ] [[package]] name = "crunchyroll-rs-internal" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f9581dc7276f1c327dcaa91fa6d3b3f09c46018dc5a0d7815be3f8027780a07" +checksum = "cab3e4af975066a3dc3dd0bb50b1a29c4a3cdee5365e8b6559d21aa15d9ace6a" dependencies = [ "darling", "quote", @@ -2051,12 +2051,9 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.24.0" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b291546d5d9d1eab74f069c77749f2cb8504a12caa20f0f2de93ddbf6f411888" -dependencies = [ - "rustls-webpki", -] +checksum = "1a4ac452058d835c2b7ff6d74f0ad9f40e172bb1ce661b1444f397eeb1d19e6d" [[package]] name = "winapi" diff --git a/crunchy-cli-core/Cargo.toml b/crunchy-cli-core/Cargo.toml index 4a6a229..f7a3f43 100644 --- a/crunchy-cli-core/Cargo.toml +++ b/crunchy-cli-core/Cargo.toml @@ -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" diff --git a/crunchy-cli-core/src/utils/video.rs b/crunchy-cli-core/src/utils/video.rs index f2fabd4..5b3eaeb 100644 --- a/crunchy-cli-core/src/utils/video.rs +++ b/crunchy-cli-core/src/utils/video.rs @@ -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> { - 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());