feat: Add yt-dlp support for fetching video information
This commit is contained in:
parent
17368b8ae9
commit
18dd4b9250
3 changed files with 54 additions and 6 deletions
28
ytdlp/fetch.go
Normal file
28
ytdlp/fetch.go
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package ytdlp
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
ytd "github.com/lrstanley/go-ytdlp"
|
||||
)
|
||||
|
||||
// Fetch fetches info from a video on YouTube or other sites supported by yt-dlp
|
||||
func Fetch(ctx context.Context, url string) (*ytd.ExtractedInfo, error) {
|
||||
dl := ytd.New().DumpJSON().RemoteComponents("ejs:github")
|
||||
// TODO Add cookies if available
|
||||
|
||||
res, err := dl.Run(ctx, url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
infos, err := res.GetExtractedInfo()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(infos) != 1 {
|
||||
return nil, fmt.Errorf("%d infos", len(infos))
|
||||
}
|
||||
return infos[0], nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue