@@ -49,17 +49,45 @@ func New(ctx context.Context) (*YoutubeDl, error) {
49
49
50
50
log .Infof ("using youtube-dl %s" , version )
51
51
52
- // Make sure ffmpeg exists
53
- output , err := exec .CommandContext (ctx , "ffmpeg" , "-version" ).CombinedOutput ()
54
- if err != nil {
55
- return nil , errors .Wrap (err , "could not find ffmpeg" )
52
+ if err := ytdl .ensureDependencies (ctx ); err != nil {
53
+ return nil , err
56
54
}
57
55
58
- log .Infof ("using ffmpeg %s" , output )
59
-
60
56
return ytdl , nil
61
57
}
62
58
59
+ func (dl YoutubeDl ) ensureDependencies (ctx context.Context ) error {
60
+ found := false
61
+
62
+ if path , err := exec .LookPath ("ffmpeg" ); err == nil {
63
+ found = true
64
+
65
+ output , err := exec .CommandContext (ctx , path , "-version" ).CombinedOutput ()
66
+ if err != nil {
67
+ return errors .Wrap (err , "could not get ffmpeg version" )
68
+ }
69
+
70
+ log .Infof ("found ffmpeg: %s" , output )
71
+ }
72
+
73
+ if path , err := exec .LookPath ("avconv" ); err == nil {
74
+ found = true
75
+
76
+ output , err := exec .CommandContext (ctx , path , "-version" ).CombinedOutput ()
77
+ if err != nil {
78
+ return errors .Wrap (err , "could not get avconv version" )
79
+ }
80
+
81
+ log .Infof ("found avconv: %s" , output )
82
+ }
83
+
84
+ if ! found {
85
+ return errors .New ("either ffmpeg or avconv required to run Podsync" )
86
+ }
87
+
88
+ return nil
89
+ }
90
+
63
91
func (dl YoutubeDl ) Download (ctx context.Context , feedConfig * config.Feed , episode * model.Episode ) (io.ReadCloser , error ) {
64
92
tmpDir , err := ioutil .TempDir ("" , "podsync-" )
65
93
if err != nil {
0 commit comments