@@ -21,8 +21,8 @@ import (
2121)
2222
2323const (
24- DownloadTimeout = 10 * time .Minute
25- UpdatePeriod = 24 * time .Hour
24+ DefaultDownloadTimeout = 10 * time .Minute
25+ UpdatePeriod = 24 * time .Hour
2626)
2727
2828var (
@@ -31,19 +31,28 @@ var (
3131
3232type YoutubeDl struct {
3333 path string
34+ timeout time.Duration
3435 updateLock sync.Mutex // Don't call youtube-dl while self updating
3536}
3637
37- func New (ctx context.Context , update bool ) (* YoutubeDl , error ) {
38+ func New (ctx context.Context , cfg config. Downloader ) (* YoutubeDl , error ) {
3839 path , err := exec .LookPath ("youtube-dl" )
3940 if err != nil {
4041 return nil , errors .Wrap (err , "youtube-dl binary not found" )
4142 }
4243
4344 log .Debugf ("found youtube-dl binary at %q" , path )
4445
46+ timeout := DefaultDownloadTimeout
47+ if cfg .Timeout > 0 {
48+ timeout = time .Duration (cfg .Timeout ) * time .Minute
49+ }
50+
51+ log .Debugf ("download timeout: %d min(s)" , int (timeout .Minutes ()))
52+
4553 ytdl := & YoutubeDl {
46- path : path ,
54+ path : path ,
55+ timeout : timeout ,
4756 }
4857
4958 // Make sure youtube-dl exists
@@ -58,7 +67,7 @@ func New(ctx context.Context, update bool) (*YoutubeDl, error) {
5867 return nil , err
5968 }
6069
61- if update {
70+ if cfg . SelfUpdate {
6271 // Do initial blocking update at launch
6372 if err := ytdl .Update (ctx ); err != nil {
6473 log .WithError (err ).Error ("failed to update youtube-dl" )
@@ -177,7 +186,7 @@ func (dl *YoutubeDl) Download(ctx context.Context, feedConfig *config.Feed, epis
177186}
178187
179188func (dl * YoutubeDl ) exec (ctx context.Context , args ... string ) (string , error ) {
180- ctx , cancel := context .WithTimeout (ctx , DownloadTimeout )
189+ ctx , cancel := context .WithTimeout (ctx , dl . timeout )
181190 defer cancel ()
182191
183192 cmd := exec .CommandContext (ctx , dl .path , args ... )
0 commit comments