ytdl-web/ytdl/meta.go

30 lines
395 B
Go

package ytdl
import (
"bytes"
"encoding/json"
"os/exec"
)
func GetMetadata(url string) (Metdata, error) {
cmd := exec.Command(
"yt-dlp",
"-J",
url,
)
var out bytes.Buffer
cmd.Stdout = &out
if err := cmd.Run(); err != nil {
return Metdata{}, nil
}
var meta Metdata
if err := json.Unmarshal(out.Bytes(), &meta); err != nil {
return Metdata{}, err
}
return meta, nil
}