Add yt-dlp path config value

This commit is contained in:
Evan Fiordeliso 2023-04-15 15:45:27 -04:00
parent 6fed527515
commit 0b990c082b
4 changed files with 10 additions and 2 deletions

View File

@ -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() {

View File

@ -1,3 +1,4 @@
port: 8080
listen: 0.0.0.0
base_path: ""
ytdlp_path: yt-dlp

View File

@ -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,

View File

@ -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",