Change stderr in debug option from LevelError to LevelDebug

This commit is contained in:
Evan Fiordeliso 2023-05-23 19:13:48 -04:00
parent a749a80238
commit 7e5c4856b4
4 changed files with 16 additions and 7 deletions

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"ansible.python.interpreterPath": "/bin/python"
}

View File

@ -8,7 +8,7 @@ import (
"go.fifitido.net/ytdl-web/ytdl/metadata" "go.fifitido.net/ytdl-web/ytdl/metadata"
) )
func Exec(url string, options ...Option) error { func Exec(binary, url string, options ...Option) error {
opts := Options{ opts := Options{
args: []string{url}, args: []string{url},
stdin: nil, stdin: nil,
@ -22,7 +22,7 @@ func Exec(url string, options ...Option) error {
} }
} }
cmd := exec.Command("youtube-dl", opts.args...) cmd := exec.Command(binary, opts.args...)
if opts.stdin != nil { if opts.stdin != nil {
cmd.Stdin = opts.stdin cmd.Stdin = opts.stdin

View File

@ -46,7 +46,7 @@ func WithDumpJson(meta *metadata.Metadata) Option {
func WithLoadJson(metadata *metadata.Metadata) Option { func WithLoadJson(metadata *metadata.Metadata) Option {
return func(opts *Options) error { return func(opts *Options) error {
opts.args = append(opts.args, "--load-single-json", "-") opts.args = append(opts.args, "--load-info-json", "-")
json, err := json.Marshal(metadata) json, err := json.Marshal(metadata)
if err != nil { if err != nil {
@ -95,7 +95,7 @@ func WithStreamOutput(output io.Writer) Option {
func WithDebug() Option { func WithDebug() Option {
return func(opts *Options) error { return func(opts *Options) error {
opts.stdout = utils.LoggerWriter(slog.With("module", "ytdl"), slog.LevelDebug) opts.stdout = utils.LoggerWriter(slog.With("module", "ytdl"), slog.LevelDebug)
opts.stderr = utils.LoggerWriter(slog.With("module", "ytdl"), slog.LevelError) opts.stderr = utils.LoggerWriter(slog.With("module", "ytdl"), slog.LevelDebug)
return nil return nil
} }
} }

View File

@ -58,13 +58,19 @@ func (y *ytdlImpl) baseOptions(url string) []Option {
// GetMetadata implements Ytdl // GetMetadata implements Ytdl
func (y *ytdlImpl) GetMetadata(url string) (*metadata.Metadata, error) { func (y *ytdlImpl) GetMetadata(url string) (*metadata.Metadata, error) {
meta := &metadata.Metadata{} meta, err := y.cache.Get(url)
if err == nil {
return meta, nil
}
meta = &metadata.Metadata{}
options := append( options := append(
y.baseOptions(url), y.baseOptions(url),
WithDumpJson(meta), WithDumpJson(meta),
) )
if err := Exec(url, options...); err != nil { if err := Exec(y.cfg.Ytdlp.BinaryPath, url, options...); err != nil {
y.logger.Error("failed to get metadata", slog.String("url", url), slog.String("error", err.Error()))
return nil, err return nil, err
} }
@ -83,7 +89,7 @@ func (y *ytdlImpl) Download(w io.Writer, url, format string) error {
WithStreamOutput(w), WithStreamOutput(w),
) )
if err := Exec(url, options...); err != nil { if err := Exec(y.cfg.Ytdlp.BinaryPath, url, options...); err != nil {
return err return err
} }