2023-04-14 16:07:57 -04:00
|
|
|
package ytdl
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/json"
|
|
|
|
"os/exec"
|
|
|
|
)
|
|
|
|
|
2023-04-15 12:38:33 -04:00
|
|
|
func GetMetadata(url string) (Metadata, error) {
|
2023-04-14 16:07:57 -04:00
|
|
|
cmd := exec.Command(
|
|
|
|
"yt-dlp",
|
|
|
|
"-J",
|
2023-04-15 12:38:33 -04:00
|
|
|
"--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 {
|
2023-04-15 12:38:33 -04:00
|
|
|
return Metadata{}, err
|
2023-04-14 16:07:57 -04:00
|
|
|
}
|
|
|
|
|
2023-04-15 12:38:33 -04:00
|
|
|
var meta Metadata
|
2023-04-14 16:07:57 -04:00
|
|
|
if err := json.Unmarshal(out.Bytes(), &meta); err != nil {
|
2023-04-15 12:38:33 -04:00
|
|
|
return Metadata{}, err
|
2023-04-14 16:07:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return meta, nil
|
|
|
|
}
|