Skip to content

Commit 33a4ef9

Browse files
committed
fixes
1 parent f2cd508 commit 33a4ef9

2 files changed

Lines changed: 56 additions & 8 deletions

File tree

internal/exec/exec.go

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,29 @@ func appendFFmpegLiveOutputStreamArgs(args []string, audioOnly bool) []string {
5858
)
5959
}
6060

61+
func appendYtDlpVideoConfigArgs(args []string, configArgs string) []string {
62+
skipValue := false
63+
for _, arg := range strings.Split(configArgs, ",") {
64+
trimmedArg := strings.TrimSpace(arg)
65+
if skipValue {
66+
skipValue = false
67+
continue
68+
}
69+
if trimmedArg == "-o" || trimmedArg == "--output" || trimmedArg == "-P" || trimmedArg == "--paths" {
70+
skipValue = true
71+
continue
72+
}
73+
if strings.HasPrefix(trimmedArg, "--output=") || strings.HasPrefix(trimmedArg, "--paths=") ||
74+
(len(trimmedArg) > 2 && (strings.HasPrefix(trimmedArg, "-o") || strings.HasPrefix(trimmedArg, "-P"))) {
75+
continue
76+
}
77+
if trimmedArg != "" {
78+
args = append(args, trimmedArg)
79+
}
80+
}
81+
return args
82+
}
83+
6184
func twitchVideoDownloadArgs(quality, url, outputPath, configArgs string) []string {
6285
args := []string{
6386
"-f", quality,
@@ -72,14 +95,9 @@ func twitchVideoDownloadArgs(quality, url, outputPath, configArgs string) []stri
7295
}
7396

7497
// User arguments are intentionally last so an explicit downloader preference
75-
// in the configuration can override the default.
76-
for _, arg := range strings.Split(configArgs, ",") {
77-
if strings.TrimSpace(arg) != "" {
78-
args = append(args, arg)
79-
}
80-
}
81-
82-
return args
98+
// in the configuration can override the default. Output options are excluded
99+
// so the application-owned temporary path remains authoritative.
100+
return appendYtDlpVideoConfigArgs(args, configArgs)
83101
}
84102

85103
// DownloadTwitchVideo downloads a Twitch video.

internal/exec/exec_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,36 @@ func TestTwitchVideoDownloadArgsPreferFFmpegForHLS(t *testing.T) {
9191
}
9292
}
9393

94+
func TestAppendYtDlpVideoConfigArgsExcludesOutputOptions(t *testing.T) {
95+
t.Parallel()
96+
97+
initial := []string{"-o", "/data/temp/video.%(ext)s"}
98+
configArgs := strings.Join([]string{
99+
" --retries ", " 10 ", " ",
100+
"-o", "/tmp/short-separated",
101+
"--output", "/tmp/long-separated",
102+
"-o=/tmp/short-equals",
103+
"-o/tmp/short-attached",
104+
"--output=/tmp/long-equals",
105+
"-P", "/tmp/path-short-separated",
106+
"--paths", "/tmp/path-long-separated",
107+
"-P=/tmp/path-short-equals",
108+
"-P/tmp/path-short-attached",
109+
"--paths=/tmp/path-long-equals",
110+
" --fragment-retries", "20 ",
111+
}, ",")
112+
113+
got := appendYtDlpVideoConfigArgs(initial, configArgs)
114+
want := []string{
115+
"-o", "/data/temp/video.%(ext)s",
116+
"--retries", "10",
117+
"--fragment-retries", "20",
118+
}
119+
if !reflect.DeepEqual(got, want) {
120+
t.Fatalf("appendYtDlpVideoConfigArgs() = %v, want %v", got, want)
121+
}
122+
}
123+
94124
func TestPostProcessVideoFFmpegArgsIncludesTitleMetadata(t *testing.T) {
95125
t.Parallel()
96126

0 commit comments

Comments
 (0)