Skip to content

Commit 4afc477

Browse files
committed
Detect ffmpeg or avconv for youtube-dl #122
1 parent 67478ac commit 4afc477

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

pkg/ytdl/ytdl.go

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,45 @@ func New(ctx context.Context) (*YoutubeDl, error) {
4949

5050
log.Infof("using youtube-dl %s", version)
5151

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
5654
}
5755

58-
log.Infof("using ffmpeg %s", output)
59-
6056
return ytdl, nil
6157
}
6258

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+
6391
func (dl YoutubeDl) Download(ctx context.Context, feedConfig *config.Feed, episode *model.Episode) (io.ReadCloser, error) {
6492
tmpDir, err := ioutil.TempDir("", "podsync-")
6593
if err != nil {

0 commit comments

Comments
 (0)