Change stderr in debug option from LevelError to LevelDebug
This commit is contained in:
parent
a749a80238
commit
7e5c4856b4
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"ansible.python.interpreterPath": "/bin/python"
|
||||
}
|
|
@ -8,7 +8,7 @@ import (
|
|||
"go.fifitido.net/ytdl-web/ytdl/metadata"
|
||||
)
|
||||
|
||||
func Exec(url string, options ...Option) error {
|
||||
func Exec(binary, url string, options ...Option) error {
|
||||
opts := Options{
|
||||
args: []string{url},
|
||||
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 {
|
||||
cmd.Stdin = opts.stdin
|
||||
|
|
|
@ -46,7 +46,7 @@ func WithDumpJson(meta *metadata.Metadata) Option {
|
|||
|
||||
func WithLoadJson(metadata *metadata.Metadata) Option {
|
||||
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)
|
||||
if err != nil {
|
||||
|
@ -95,7 +95,7 @@ func WithStreamOutput(output io.Writer) Option {
|
|||
func WithDebug() Option {
|
||||
return func(opts *Options) error {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
12
ytdl/ytdl.go
12
ytdl/ytdl.go
|
@ -58,13 +58,19 @@ func (y *ytdlImpl) baseOptions(url string) []Option {
|
|||
|
||||
// GetMetadata implements Ytdl
|
||||
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(
|
||||
y.baseOptions(url),
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -83,7 +89,7 @@ func (y *ytdlImpl) Download(w io.Writer, url, format string) error {
|
|||
WithStreamOutput(w),
|
||||
)
|
||||
|
||||
if err := Exec(url, options...); err != nil {
|
||||
if err := Exec(y.cfg.Ytdlp.BinaryPath, url, options...); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue