ytdl-web/ytdl/meta.go

37 lines
548 B
Go
Raw Normal View History

2023-04-14 16:07:57 -04:00
package ytdl
import (
"bytes"
"encoding/json"
"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
)
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",
"--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 {
fmt.Printf("%+v\n", err)
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 {
fmt.Printf("%+v\n", err)
return Metadata{}, err
2023-04-14 16:07:57 -04:00
}
return meta, nil
}