Skip to content

Commit 191dd21

Browse files
authored
feat: add --force-keyframe-at-cuts when removing sponsorblock sections (#763)
1 parent 64125b0 commit 191dd21

1 file changed

Lines changed: 56 additions & 22 deletions

File tree

src-tauri/src/runners/ytdlp_runner.rs

Lines changed: 56 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::runners::ytdlp_args::{build_format_args, build_location_args, build_o
77
use crate::runners::ytdlp_process::{
88
configure_command, kill_platform_process, platform_process_from_child, PlatformProcess,
99
};
10-
use crate::state::config_models::{AuthSettings, Config, SubtitleSettings};
10+
use crate::state::config_models::{AuthSettings, Config, SponsorBlockSettings, SubtitleSettings};
1111
use crate::state::preferences_models::Preferences;
1212
use crate::stronghold::stronghold_state::{AuthSecrets, StrongholdState};
1313
use crate::{SharedConfig, SharedPreferences};
@@ -155,25 +155,7 @@ impl<'a> YtdlpRunner<'a> {
155155
&self.cfg.sponsor_block,
156156
overrides.and_then(|value| value.sponsor_block.as_ref()),
157157
);
158-
if let Some(api_url) = &sponsor_block.api_url {
159-
self
160-
.args
161-
.extend_from_slice(&["--sponsorblock-api".into(), api_url.clone()]);
162-
}
163-
164-
if !sponsor_block.remove_parts.is_empty() {
165-
self.args.extend_from_slice(&[
166-
"--sponsorblock-remove".into(),
167-
sponsor_block.remove_parts.join(","),
168-
]);
169-
}
170-
171-
if !sponsor_block.mark_parts.is_empty() {
172-
self.args.extend_from_slice(&[
173-
"--sponsorblock-mark".into(),
174-
sponsor_block.mark_parts.join(","),
175-
]);
176-
}
158+
self.args.extend(build_sponsorblock_args(&sponsor_block));
177159

178160
self
179161
}
@@ -452,6 +434,28 @@ fn build_subtitle_args(settings: &SubtitleSettings) -> Option<Vec<String>> {
452434
Some(args)
453435
}
454436

437+
fn build_sponsorblock_args(settings: &SponsorBlockSettings) -> Vec<String> {
438+
let mut args = Vec::new();
439+
440+
if let Some(api_url) = &settings.api_url {
441+
args.extend_from_slice(&["--sponsorblock-api".into(), api_url.clone()]);
442+
}
443+
444+
if !settings.remove_parts.is_empty() {
445+
args.extend_from_slice(&[
446+
"--sponsorblock-remove".into(),
447+
settings.remove_parts.join(","),
448+
"--force-keyframes-at-cuts".into(),
449+
]);
450+
}
451+
452+
if !settings.mark_parts.is_empty() {
453+
args.extend_from_slice(&["--sponsorblock-mark".into(), settings.mark_parts.join(",")]);
454+
}
455+
456+
args
457+
}
458+
455459
fn sanitize_subtitle_formats(formats: &[String]) -> Vec<String> {
456460
const DEFAULT_FORMATS: [&str; 5] = ["srt", "vtt", "ass", "ttml", "json3"];
457461

@@ -548,8 +552,8 @@ fn has_subtitle_language_pattern_syntax(language: &str) -> bool {
548552

549553
#[cfg(test)]
550554
mod tests {
551-
use super::build_subtitle_args;
552-
use crate::state::config_models::SubtitleSettings;
555+
use super::{build_sponsorblock_args, build_subtitle_args};
556+
use crate::state::config_models::{SponsorBlockSettings, SubtitleSettings};
553557

554558
#[test]
555559
fn subtitles_disabled_returns_none() {
@@ -653,4 +657,34 @@ mod tests {
653657
let args = build_subtitle_args(&settings).expect("args");
654658
assert_eq!(args[7], "en.*,-live_chat");
655659
}
660+
661+
#[test]
662+
fn sponsorblock_remove_adds_force_keyframes_at_cuts() {
663+
let settings = SponsorBlockSettings {
664+
remove_parts: vec!["sponsor".into(), "intro".into()],
665+
..Default::default()
666+
};
667+
668+
assert_eq!(
669+
build_sponsorblock_args(&settings),
670+
vec![
671+
"--sponsorblock-remove",
672+
"sponsor,intro",
673+
"--force-keyframes-at-cuts",
674+
]
675+
);
676+
}
677+
678+
#[test]
679+
fn sponsorblock_mark_does_not_add_force_keyframes_at_cuts() {
680+
let settings = SponsorBlockSettings {
681+
mark_parts: vec!["sponsor".into()],
682+
..Default::default()
683+
};
684+
685+
assert_eq!(
686+
build_sponsorblock_args(&settings),
687+
vec!["--sponsorblock-mark", "sponsor"]
688+
);
689+
}
656690
}

0 commit comments

Comments
 (0)