ytdl-web/ytdl/meta.go

31 lines
438 B
Go
Raw Normal View History

2023-04-14 16:07:57 -04:00
package ytdl
import (
"bytes"
"encoding/json"
"os/exec"
)
func GetMetadata(url string) (Metadata, error) {
2023-04-14 16:07:57 -04:00
cmd := exec.Command(
"yt-dlp",
"-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
}