Skip to content

Commit 9f02ea0

Browse files
committed
handle yt options at init
1 parent afc227f commit 9f02ea0

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/downloader/youtube.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,25 @@ type Youtube struct {
4747
DownloadDir string
4848
HttpClient *util.HttpClient
4949
Cfg cfg.Youtube
50+
gouTubeOpts goutubedl.Options
5051
}
5152

5253
func NewYoutube(cfg cfg.Youtube, discovery, downloadDir string, httpClient *util.HttpClient) *Youtube { // init downloader cfg for youtube
54+
// check for custom ytdlp options
55+
if cfg.YtdlpPath != "" {
56+
goutubedl.Path = cfg.YtdlpPath
57+
}
58+
59+
var opts goutubedl.Options
60+
if _, err := os.Stat(cfg.CookiesPath); err == nil {
61+
opts.Cookies = cfg.CookiesPath
62+
}
63+
5364
return &Youtube{
5465
DownloadDir: downloadDir,
5566
Cfg: cfg,
56-
HttpClient: httpClient}
67+
HttpClient: httpClient,
68+
gouTubeOpts: opts}
5769
}
5870

5971
func (c *Youtube) GetConf() (MonitorConfig, error) {
@@ -144,16 +156,8 @@ func getTopic(cfg cfg.Youtube, videos Videos, track models.Track) string { // ge
144156
}
145157

146158
func getVideo(ctx context.Context, c Youtube, videoID string) (*goutubedl.DownloadResult, error) { // gets video stream using yt-dlp
147-
if c.Cfg.YtdlpPath != "" {
148-
goutubedl.Path = c.Cfg.YtdlpPath
149-
}
150-
151-
var opts goutubedl.Options
152-
if _, err := os.Stat(c.Cfg.CookiesPath); err == nil {
153-
opts.Cookies = c.Cfg.CookiesPath
154-
}
155159

156-
result, err := goutubedl.New(ctx, videoID, opts)
160+
result, err := goutubedl.New(ctx, videoID, c.gouTubeOpts)
157161
if err != nil {
158162
return nil, fmt.Errorf("could not create URL for video download (ID: %s): %s", videoID, err.Error())
159163
}

0 commit comments

Comments
 (0)