From 36900183b54edb4455e1be1efabf4dfba72710f3 Mon Sep 17 00:00:00 2001 From: Maksym Pavlenko Date: Sun, 2 Jan 2022 16:57:54 +0200 Subject: [PATCH] Allow custom youtube-dl path --- pkg/ytdl/ytdl.go | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/pkg/ytdl/ytdl.go b/pkg/ytdl/ytdl.go index 7b9529b..f035461 100644 --- a/pkg/ytdl/ytdl.go +++ b/pkg/ytdl/ytdl.go @@ -35,6 +35,8 @@ type Config struct { SelfUpdate bool `toml:"self_update"` // Timeout in minutes for youtube-dl process to finish download Timeout int `toml:"timeout"` + // CustomBinary is a custom path to youtube-dl, this allows using various youtube-dl forks. + CustomBinary string `toml:"custom_binary"` } type YoutubeDl struct { @@ -44,12 +46,25 @@ type YoutubeDl struct { } func New(ctx context.Context, cfg Config) (*YoutubeDl, error) { - path, err := exec.LookPath("youtube-dl") - if err != nil { - return nil, errors.Wrap(err, "youtube-dl binary not found") - } + var ( + path string + err error + ) - log.Debugf("found youtube-dl binary at %q", path) + if cfg.CustomBinary != "" { + path = cfg.CustomBinary + + // Don't update custom youtube-dl binaries. + log.Warnf("using custom youtube-dl binary, turning self updates off") + cfg.SelfUpdate = false + } else { + path, err = exec.LookPath("youtube-dl") + if err != nil { + return nil, errors.Wrap(err, "youtube-dl binary not found") + } + + log.Debugf("found youtube-dl binary at %q", path) + } timeout := DefaultDownloadTimeout if cfg.Timeout > 0 {