From 4d1df833426f1382cf0351ffc250e11c150ce147 Mon Sep 17 00:00:00 2001
From: bytedream
Date: Sat, 4 May 2024 23:45:30 +0200
Subject: [PATCH 01/26] Fix build badge
---
README.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 1735a6e..45b8ea7 100644
--- a/README.md
+++ b/README.md
@@ -22,8 +22,8 @@
-
-
+
+
From ab63dcd2e010cccd4b5a99c48d6576fa6c22d664 Mon Sep 17 00:00:00 2001
From: bytedream
Date: Mon, 6 May 2024 20:29:22 +0200
Subject: [PATCH 02/26] Update dependencies and version
---
Cargo.lock | 30 +++++++++++++++---------------
Cargo.toml | 2 +-
crunchy-cli-core/Cargo.toml | 4 ++--
3 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index b9dce7b..44a47cd 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -92,9 +92,9 @@ dependencies = [
[[package]]
name = "anyhow"
-version = "1.0.82"
+version = "1.0.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519"
+checksum = "25bdb32cbbdce2b519a9cd7df3a678443100e265d5e25ca763b7572a5104f5f3"
[[package]]
name = "async-speed-limit"
@@ -188,9 +188,9 @@ checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9"
[[package]]
name = "cc"
-version = "1.0.96"
+version = "1.0.97"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "065a29261d53ba54260972629f9ca6bffa69bac13cd1fed61420f7fa68b9f8bd"
+checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4"
[[package]]
name = "cfg-if"
@@ -343,7 +343,7 @@ checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"
[[package]]
name = "crunchy-cli"
-version = "3.6.0"
+version = "3.6.1"
dependencies = [
"chrono",
"clap",
@@ -356,7 +356,7 @@ dependencies = [
[[package]]
name = "crunchy-cli-core"
-version = "3.6.0"
+version = "3.6.1"
dependencies = [
"anyhow",
"async-speed-limit",
@@ -712,9 +712,9 @@ dependencies = [
[[package]]
name = "getrandom"
-version = "0.2.14"
+version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c"
+checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
dependencies = [
"cfg-if",
"js-sys",
@@ -1511,9 +1511,9 @@ checksum = "b833d8d034ea094b1ea68aa6d5c740e0d04bad9d16568d08ba6f76823a114316"
[[package]]
name = "rsubs-lib"
-version = "0.2.0"
+version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0df7559a05635a4132b737c736ee286af83f3969cb98d9028d17d333e6b41cc5"
+checksum = "9dcca2a9560fca05de8f95bc3767e46673d4b4c1f2c7a11092e10efd95bbdf62"
dependencies = [
"regex",
"serde",
@@ -1646,11 +1646,11 @@ dependencies = [
[[package]]
name = "security-framework"
-version = "2.10.0"
+version = "2.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "770452e37cad93e0a50d5abc3990d2bc351c36d0328f86cefec2f2fb206eaef6"
+checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0"
dependencies = [
- "bitflags 1.3.2",
+ "bitflags 2.5.0",
"core-foundation",
"core-foundation-sys",
"libc",
@@ -1659,9 +1659,9 @@ dependencies = [
[[package]]
name = "security-framework-sys"
-version = "2.10.0"
+version = "2.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "41f3cc463c0ef97e11c3461a9d3787412d30e8e7eb907c79180c4a57bf7c04ef"
+checksum = "317936bbbd05227752583946b9e66d7ce3b489f84e11a94a510b4437fef407d7"
dependencies = [
"core-foundation-sys",
"libc",
diff --git a/Cargo.toml b/Cargo.toml
index fe7b301..26f71f3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "crunchy-cli"
authors = ["Crunchy Labs Maintainers"]
-version = "3.6.0"
+version = "3.6.1"
edition = "2021"
license = "MIT"
diff --git a/crunchy-cli-core/Cargo.toml b/crunchy-cli-core/Cargo.toml
index 896b68f..8e1ba3a 100644
--- a/crunchy-cli-core/Cargo.toml
+++ b/crunchy-cli-core/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "crunchy-cli-core"
authors = ["Crunchy Labs Maintainers"]
-version = "3.6.0"
+version = "3.6.1"
edition = "2021"
license = "MIT"
@@ -30,7 +30,7 @@ log = { version = "0.4", features = ["std"] }
num_cpus = "1.16"
regex = "1.10"
reqwest = { version = "0.12", features = ["socks", "stream"] }
-rsubs-lib = "0.2"
+rsubs-lib = ">=0.2.1"
rusty-chromaprint = "0.2"
serde = "1.0"
serde_json = "1.0"
From 53a710a3732047a1e08d475f6f112b440b8bde8e Mon Sep 17 00:00:00 2001
From: Simon <47527944+Frooastside@users.noreply.github.com>
Date: Tue, 7 May 2024 16:13:10 +0200
Subject: [PATCH 03/26] Fix audio syncing using wrong internal index (#407)
---
crunchy-cli-core/src/utils/download.rs | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/crunchy-cli-core/src/utils/download.rs b/crunchy-cli-core/src/utils/download.rs
index 565ed7d..8a8ad57 100644
--- a/crunchy-cli-core/src/utils/download.rs
+++ b/crunchy-cli-core/src/utils/download.rs
@@ -321,8 +321,6 @@ impl Downloader {
if let Some(offsets) = offsets {
let mut root_format_idx = 0;
let mut root_format_length = 0;
- let mut audio_count: usize = 0;
- let mut subtitle_count: usize = 0;
for (i, format) in self.formats.iter().enumerate() {
let offset = offsets.get(&i).copied().unwrap_or_default();
let format_len = format
@@ -340,15 +338,13 @@ impl Downloader {
for _ in &format.audios {
if let Some(offset) = &offsets.get(&i) {
- audio_offsets.insert(audio_count, **offset);
+ audio_offsets.insert(i, **offset);
}
- audio_count += 1
}
for _ in &format.subtitles {
if let Some(offset) = &offsets.get(&i) {
- subtitle_offsets.insert(subtitle_count, **offset);
+ subtitle_offsets.insert(i, **offset);
}
- subtitle_count += 1
}
}
From 48bb7a5ef669d3d89ccecfbf02929adeea99a6bd Mon Sep 17 00:00:00 2001
From: bytedream
Date: Tue, 14 May 2024 16:11:55 +0200
Subject: [PATCH 04/26] Fix crashes when converting subtitles (#408)
---
Cargo.lock | 6 ++--
crunchy-cli-core/Cargo.toml | 3 +-
crunchy-cli-core/src/utils/download.rs | 39 ++++++++++++++++----------
3 files changed, 30 insertions(+), 18 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index 44a47cd..cd1f282 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -386,6 +386,7 @@ dependencies = [
"shlex",
"sys-locale",
"tempfile",
+ "time",
"tokio",
"tokio-util",
"tower-service",
@@ -1511,12 +1512,13 @@ checksum = "b833d8d034ea094b1ea68aa6d5c740e0d04bad9d16568d08ba6f76823a114316"
[[package]]
name = "rsubs-lib"
-version = "0.2.1"
+version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9dcca2a9560fca05de8f95bc3767e46673d4b4c1f2c7a11092e10efd95bbdf62"
+checksum = "f43e1a7f184bc76407dbaa67bd2aeea8a15430d7e1e498070963336d03ebedee"
dependencies = [
"regex",
"serde",
+ "time",
]
[[package]]
diff --git a/crunchy-cli-core/Cargo.toml b/crunchy-cli-core/Cargo.toml
index 8e1ba3a..49f7a5e 100644
--- a/crunchy-cli-core/Cargo.toml
+++ b/crunchy-cli-core/Cargo.toml
@@ -30,7 +30,7 @@ log = { version = "0.4", features = ["std"] }
num_cpus = "1.16"
regex = "1.10"
reqwest = { version = "0.12", features = ["socks", "stream"] }
-rsubs-lib = ">=0.2.1"
+rsubs-lib = "0.3"
rusty-chromaprint = "0.2"
serde = "1.0"
serde_json = "1.0"
@@ -38,6 +38,7 @@ serde_plain = "1.0"
shlex = "1.3"
sys-locale = "0.3"
tempfile = "3.10"
+time = "0.3"
tokio = { version = "1.37", features = ["io-util", "macros", "net", "rt-multi-thread", "time"] }
tokio-util = "0.7"
tower-service = "0.3"
diff --git a/crunchy-cli-core/src/utils/download.rs b/crunchy-cli-core/src/utils/download.rs
index 8a8ad57..43d165b 100644
--- a/crunchy-cli-core/src/utils/download.rs
+++ b/crunchy-cli-core/src/utils/download.rs
@@ -13,17 +13,19 @@ use indicatif::{ProgressBar, ProgressDrawTarget, ProgressFinish, ProgressStyle};
use log::{debug, warn, LevelFilter};
use regex::Regex;
use reqwest::Client;
-use rsubs_lib::{ssa, vtt};
+use rsubs_lib::{SSA, VTT};
use std::borrow::Borrow;
use std::cmp::Ordering;
use std::collections::{BTreeMap, HashMap};
use std::io::Write;
+use std::ops::Add;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::sync::Arc;
use std::time::Duration;
use std::{env, fs};
use tempfile::TempPath;
+use time::Time;
use tokio::io::{AsyncBufReadExt, AsyncReadExt, BufReader};
use tokio::select;
use tokio::sync::mpsc::unbounded_channel;
@@ -929,36 +931,43 @@ impl Downloader {
) -> Result {
let buf = subtitle.data().await?;
let mut ass = match subtitle.format.as_str() {
- "ass" => ssa::parse(String::from_utf8_lossy(&buf).to_string()),
- "vtt" => vtt::parse(String::from_utf8_lossy(&buf).to_string()).to_ass(),
+ "ass" => SSA::parse(String::from_utf8_lossy(&buf))?,
+ "vtt" => VTT::parse(String::from_utf8_lossy(&buf))?.to_ssa(),
_ => bail!("unknown subtitle format: {}", subtitle.format),
};
// subtitles aren't always correct sorted and video players may have issues with that. to
// prevent issues, the subtitles are sorted
- ass.events
- .sort_by(|a, b| a.line_start.total_ms().cmp(&b.line_start.total_ms()));
+ // (https://github.com/crunchy-labs/crunchy-cli/issues/208)
+ ass.events.sort_by(|a, b| a.start.cmp(&b.start));
// it might be the case that the start and/or end time are greater than the actual video
// length. this might also result in issues with video players, thus the times are stripped
- // to be maxim
+ // to be at most as long as `max_length`
+ // (https://github.com/crunchy-labs/crunchy-cli/issues/32)
for i in (0..ass.events.len()).rev() {
- if ass.events[i].line_end.total_ms() > max_length.num_milliseconds() as u32 {
- if ass.events[i].line_start.total_ms() > max_length.num_milliseconds() as u32 {
- ass.events[i]
- .line_start
- .set_ms(max_length.num_milliseconds() as u32);
+ let max_len = Time::from_hms(0, 0, 0)
+ .unwrap()
+ .add(Duration::from_millis(max_length.num_milliseconds() as u64));
+
+ if ass.events[i].start > max_len {
+ if ass.events[i].end > max_len {
+ ass.events[i].start = max_len
}
- ass.events[i]
- .line_end
- .set_ms(max_length.num_milliseconds() as u32);
+ ass.events[i].end = max_len
} else {
break;
}
}
+ // without this additional info, subtitle look very messy in some video player
+ // (https://github.com/crunchy-labs/crunchy-cli/issues/66)
+ ass.info
+ .additional_fields
+ .insert("ScaledBorderAndShadows".to_string(), "yes".to_string());
+
let tempfile = tempfile(".ass")?;
let path = tempfile.into_temp_path();
- ass.to_file(path.to_string_lossy().to_string().as_str())?;
+ fs::write(&path, ass.to_string())?;
Ok(path)
}
From 817963af4fbf0eef1fde26a02f0771e343ce35d9 Mon Sep 17 00:00:00 2001
From: bytedream
Date: Tue, 14 May 2024 21:22:23 +0200
Subject: [PATCH 05/26] Fix video containing hardsub if not requested (#415)
---
crunchy-cli-core/src/download/command.rs | 20 ++++++++++++++------
crunchy-cli-core/src/utils/video.rs | 24 ++++--------------------
2 files changed, 18 insertions(+), 26 deletions(-)
diff --git a/crunchy-cli-core/src/download/command.rs b/crunchy-cli-core/src/download/command.rs
index bb0c1fd..a9c3acf 100644
--- a/crunchy-cli-core/src/download/command.rs
+++ b/crunchy-cli-core/src/download/command.rs
@@ -384,12 +384,20 @@ async fn get_format(
let subtitle = if contains_hardsub {
None
} else if let Some(subtitle_locale) = &download.subtitle {
- stream
- .subtitles
- .get(subtitle_locale)
- .cloned()
- // use closed captions as fallback if no actual subtitles are found
- .or_else(|| stream.captions.get(subtitle_locale).cloned())
+ if download.audio == Locale::ja_JP {
+ stream
+ .subtitles
+ .get(subtitle_locale)
+ // use closed captions as fallback if no actual subtitles are found
+ .or_else(|| stream.captions.get(subtitle_locale))
+ .cloned()
+ } else {
+ stream
+ .captions
+ .get(subtitle_locale)
+ .or_else(|| stream.subtitles.get(subtitle_locale))
+ .cloned()
+ }
} else {
None
};
diff --git a/crunchy-cli-core/src/utils/video.rs b/crunchy-cli-core/src/utils/video.rs
index 07f6e76..8b25791 100644
--- a/crunchy-cli-core/src/utils/video.rs
+++ b/crunchy-cli-core/src/utils/video.rs
@@ -5,28 +5,12 @@ use crunchyroll_rs::Locale;
pub async fn stream_data_from_stream(
stream: &Stream,
resolution: &Resolution,
- subtitle: Option,
+ hardsub_subtitle: Option,
) -> Result