31 lines
438 B
Go
31 lines
438 B
Go
package ytdl
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"os/exec"
|
|
)
|
|
|
|
func GetMetadata(url string) (Metadata, error) {
|
|
cmd := exec.Command(
|
|
"yt-dlp",
|
|
"-J",
|
|
"--cookies-from-browser", "firefox",
|
|
url,
|
|
)
|
|
|
|
var out bytes.Buffer
|
|
cmd.Stdout = &out
|
|
|
|
if err := cmd.Run(); err != nil {
|
|
return Metadata{}, err
|
|
}
|
|
|
|
var meta Metadata
|
|
if err := json.Unmarshal(out.Bytes(), &meta); err != nil {
|
|
return Metadata{}, err
|
|
}
|
|
|
|
return meta, nil
|
|
}
|