2023-04-14 16:07:57 -04:00
|
|
|
package ytdl
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/json"
|
2023-04-24 08:14:36 -04:00
|
|
|
"fmt"
|
2023-04-14 16:07:57 -04:00
|
|
|
"os/exec"
|
2023-04-15 15:45:27 -04:00
|
|
|
|
|
|
|
"github.com/spf13/viper"
|
2023-04-14 16:07:57 -04:00
|
|
|
)
|
|
|
|
|
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(
|
2023-04-15 15:45:27 -04:00
|
|
|
viper.GetString("ytdlp_path"),
|
2023-04-14 16:07:57 -04:00
|
|
|
"-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-24 08:14:36 -04:00
|
|
|
|
|
|
|
fmt.Printf("%+v\n", err)
|
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-24 08:14:36 -04:00
|
|
|
fmt.Printf("%+v\n", err)
|
2023-04-15 12:38:33 -04:00
|
|
|
return Metadata{}, err
|
2023-04-14 16:07:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return meta, nil
|
|
|
|
}
|