Skip to content

Commit a878c05

Browse files
committed
Allow additional youtube-dl arguments
This allows inserting arbitrary extra arguments into the youtube-dl command-line within each podcast feed entry. This allows, for example, requesting that youtube-dl embed subtitles and captions into the video file, or configuring additional postprocessor arguments. No effort has been made to make sure no incompatible arguments are provided, with the expectation that the end-user will understand what's possible, and that this is an option expressly for advanced users. This would fix #162,and theoretically also #136!
1 parent 00c7bce commit a878c05

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ vimeo = [ # Multiple keys will be rotated.
8080
# filters = { title = "regex for title here", not_title = "regex for negative title match", description = "...", not_description = "..." } # Optional Golang regexp format. If set, then only download matching episodes.
8181
# opml = true|false # Optional inclusion of the feed in the OPML file (default value: false)
8282
# clean = { keep_last = 10 } # Keep last 10 episodes (order desc by PubDate)
83+
# youtube_dl_args = [ "--write-sub", "--embed-subs", "--sub-lang", "en,en-US,en-GB" ] # Optional extra arguments passed to youtube-dl when downloading videos from this feed. This example would embed available English closed captions in the videos. Note that setting '--audio-format' for audio format feeds, or '--format' or '--output' for any format may cause unexpected behaviour. You should only use this if you know what you are doing, and have read up on youtube-dl's options!
8384

8485
[database]
8586
badger = { truncate = true, file_io = true } # See https://github.com/dgraph-io/badger#memory-usage

pkg/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ type Feed struct {
4040
Clean Cleanup `toml:"clean"`
4141
// Custom is a list of feed customizations
4242
Custom Custom `toml:"custom"`
43+
// List of additional youtube-dl arguments passed at download time
44+
YouTubeDLArgs []string `toml:"youtube_dl_args"`
4345
// Included in OPML file
4446
OPML bool `toml:"opml"`
4547
}

pkg/ytdl/ytdl.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ func buildArgs(feedConfig *config.Feed, episode *model.Episode, outputFilePath s
214214
args = append(args, "--extract-audio", "--audio-format", "mp3", "--format", format)
215215
}
216216

217+
// Insert additional per-feed youtube-dl arguments
218+
args = append(args, feedConfig.YouTubeDLArgs...)
219+
217220
args = append(args, "--output", outputFilePath, episode.VideoURL)
218221
return args
219222
}

pkg/ytdl/ytdl_test.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func TestBuildArgs(t *testing.T) {
1717
maxHeight int
1818
output string
1919
videoURL string
20+
ytdlArgs []string
2021
expect []string
2122
}{
2223
{
@@ -91,14 +92,24 @@ func TestBuildArgs(t *testing.T) {
9192
videoURL: "http://url1",
9293
expect: []string{"--format", "bestvideo[height<=1024][ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best", "--output", "/tmp/2", "http://url1"},
9394
},
95+
{
96+
name: "Video high quality with custom youtube-dl arguments",
97+
format: model.FormatVideo,
98+
quality: model.QualityHigh,
99+
output: "/tmp/2",
100+
videoURL: "http://url1",
101+
ytdlArgs: []string{"--write-sub", "--embed-subs", "--sub-lang", "en,en-US,en-GB"},
102+
expect: []string{"--format", "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best", "--write-sub", "--embed-subs", "--sub-lang", "en,en-US,en-GB", "--output", "/tmp/2", "http://url1"},
103+
},
94104
}
95105

96106
for _, tst := range tests {
97107
t.Run(tst.name, func(t *testing.T) {
98108
result := buildArgs(&config.Feed{
99-
Format: tst.format,
100-
Quality: tst.quality,
101-
MaxHeight: tst.maxHeight,
109+
Format: tst.format,
110+
Quality: tst.quality,
111+
MaxHeight: tst.maxHeight,
112+
YouTubeDLArgs: tst.ytdlArgs,
102113
}, &model.Episode{
103114
VideoURL: tst.videoURL,
104115
}, tst.output)

0 commit comments

Comments
 (0)