34 lines
513 B
Go
34 lines
513 B
Go
|
package ytdlp
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"context"
|
||
|
"encoding/json"
|
||
|
"os/exec"
|
||
|
)
|
||
|
|
||
|
func (c *Client) Info(ctx context.Context, url string) (*Info, error) {
|
||
|
args := []string{
|
||
|
"-q", "-J", url,
|
||
|
}
|
||
|
|
||
|
cmd := exec.CommandContext(ctx, c.binary, args...)
|
||
|
var stdout bytes.Buffer
|
||
|
var stderr bytes.Buffer
|
||
|
cmd.Stdout = &stdout
|
||
|
cmd.Stderr = &stderr
|
||
|
|
||
|
err := cmd.Run()
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
var info Info
|
||
|
err = json.Unmarshal(stdout.Bytes(), &info)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
return &info, nil
|
||
|
}
|