feat: Add yt-dlp support for fetching video information

This commit is contained in:
Dan Jones 2026-02-28 20:07:44 -06:00
commit 18dd4b9250
3 changed files with 54 additions and 6 deletions

28
ytdlp/fetch.go Normal file
View 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
}