ytdl-web/ytdl/meta.go

37 lines
548 B
Go

package ytdl
import (
"bytes"
"encoding/json"
"fmt"
"os/exec"
"github.com/spf13/viper"
)
func GetMetadata(url string) (Metadata, error) {
cmd := exec.Command(
viper.GetString("ytdlp_path"),
"-J",
"--cookies-from-browser", "firefox",
url,
)
var out bytes.Buffer
cmd.Stdout = &out
if err := cmd.Run(); err != nil {
fmt.Printf("%+v\n", err)
return Metadata{}, err
}
var meta Metadata
if err := json.Unmarshal(out.Bytes(), &meta); err != nil {
fmt.Printf("%+v\n", err)
return Metadata{}, err
}
return meta, nil
}