2023-04-14 16:07:57 -04:00
|
|
|
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 {
|
2023-04-14 17:32:20 -04:00
|
|
|
return Metdata{}, err
|
2023-04-14 16:07:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
var meta Metdata
|
|
|
|
if err := json.Unmarshal(out.Bytes(), &meta); err != nil {
|
|
|
|
return Metdata{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return meta, nil
|
|
|
|
}
|