From 0b990c082b91a47b110fbfdbba6b1c2b9afd0974 Mon Sep 17 00:00:00 2001 From: Evan Fiordeliso Date: Sat, 15 Apr 2023 15:45:27 -0400 Subject: [PATCH] Add yt-dlp path config value --- cmd/root.go | 3 +++ config.example.yml | 1 + ytdl/meta.go | 4 +++- ytdl/stream.go | 4 +++- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index ea9df5b..fe25333 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -50,16 +50,19 @@ func init() { rootCmd.PersistentFlags().IntP("port", "p", 8080, "port to listen on (default is 8080)") rootCmd.PersistentFlags().StringP("listen", "l", "127.0.0.1", "address to listen on (default is 127.0.0.1)") rootCmd.PersistentFlags().StringP("base-path", "b", "", "the base path, used when behind reverse proxy (default is \"\")") + rootCmd.PersistentFlags().StringP("ytdlp-path", "y", "yt-dlp", "the path to the yt-dlp binary, used when it is not in $PATH (default is yt-dlp)") // trunk-ignore-begin(golangci-lint/errcheck): Ignoring errors viper.BindPFlag("port", rootCmd.PersistentFlags().Lookup("port")) viper.BindPFlag("listen", rootCmd.PersistentFlags().Lookup("listen")) viper.BindPFlag("base_path", rootCmd.PersistentFlags().Lookup("base-path")) + viper.BindPFlag("ytdlp_path", rootCmd.PersistentFlags().Lookup("ytdlp-path")) // trunk-ignore-end(golangci-lint/errcheck) viper.SetDefault("port", 8080) viper.SetDefault("listen", "127.0.0.1") viper.SetDefault("base_path", "") + viper.SetDefault("ytdlp_path", "yt-dlp") } func initConfig() { diff --git a/config.example.yml b/config.example.yml index 06d0914..2b669c4 100644 --- a/config.example.yml +++ b/config.example.yml @@ -1,3 +1,4 @@ port: 8080 listen: 0.0.0.0 base_path: "" +ytdlp_path: yt-dlp diff --git a/ytdl/meta.go b/ytdl/meta.go index 44e0e42..aeec6f3 100644 --- a/ytdl/meta.go +++ b/ytdl/meta.go @@ -4,11 +4,13 @@ import ( "bytes" "encoding/json" "os/exec" + + "github.com/spf13/viper" ) func GetMetadata(url string) (Metadata, error) { cmd := exec.Command( - "yt-dlp", + viper.GetString("ytdlp_path"), "-J", "--cookies-from-browser", "firefox", url, diff --git a/ytdl/stream.go b/ytdl/stream.go index 01fa008..6589bad 100644 --- a/ytdl/stream.go +++ b/ytdl/stream.go @@ -3,11 +3,13 @@ package ytdl import ( "io" "os/exec" + + "github.com/spf13/viper" ) func Stream(wr io.Writer, url string, format Format) error { cmd := exec.Command( - "yt-dlp", + viper.GetString("ytdlp_path"), "-o", "-", "-f", format.FormatID, "--merge-output-format", "mkv",