@@ -47,13 +47,25 @@ type Youtube struct {
4747 DownloadDir string
4848 HttpClient * util.HttpClient
4949 Cfg cfg.Youtube
50+ gouTubeOpts goutubedl.Options
5051}
5152
5253func 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
5971func (c * Youtube ) GetConf () (MonitorConfig , error ) {
@@ -144,16 +156,8 @@ func getTopic(cfg cfg.Youtube, videos Videos, track models.Track) string { // ge
144156}
145157
146158func 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