ytdl-web/ytdl/meta.go

33 lines
486 B
Go
Raw Permalink Normal View History

2023-04-14 16:07:57 -04:00
package ytdl
import (
"bytes"
"encoding/json"
"os/exec"
2023-04-15 15:45:27 -04:00
"github.com/spf13/viper"
2023-04-14 16:07:57 -04:00
)
func GetMetadata(url string) (Metadata, error) {
2023-04-14 16:07:57 -04:00
cmd := exec.Command(
2023-04-15 15:45:27 -04:00
viper.GetString("ytdlp_path"),
2023-04-14 16:07:57 -04:00
"-J",
"--cookies-from-browser", "firefox",
2023-04-14 16:07:57 -04:00
url,
)
var out bytes.Buffer
cmd.Stdout = &out
if err := cmd.Run(); err != nil {
return Metadata{}, err
2023-04-14 16:07:57 -04:00
}
var meta Metadata
2023-04-14 16:07:57 -04:00
if err := json.Unmarshal(out.Bytes(), &meta); err != nil {
return Metadata{}, err
2023-04-14 16:07:57 -04:00
}
return meta, nil
}