Skip to content

Commit

Permalink
Detect ffmpeg or avconv for youtube-dl #122
Browse files Browse the repository at this point in the history
  • Loading branch information
mxpv committed Apr 16, 2020
1 parent 67478ac commit 4afc477
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions pkg/ytdl/ytdl.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,45 @@ func New(ctx context.Context) (*YoutubeDl, error) {

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

// Make sure ffmpeg exists
output, err := exec.CommandContext(ctx, "ffmpeg", "-version").CombinedOutput()
if err != nil {
return nil, errors.Wrap(err, "could not find ffmpeg")
if err := ytdl.ensureDependencies(ctx); err != nil {
return nil, err
}

log.Infof("using ffmpeg %s", output)

return ytdl, nil
}

func (dl YoutubeDl) ensureDependencies(ctx context.Context) error {
found := false

if path, err := exec.LookPath("ffmpeg"); err == nil {
found = true

output, err := exec.CommandContext(ctx, path, "-version").CombinedOutput()
if err != nil {
return errors.Wrap(err, "could not get ffmpeg version")
}

log.Infof("found ffmpeg: %s", output)
}

if path, err := exec.LookPath("avconv"); err == nil {
found = true

output, err := exec.CommandContext(ctx, path, "-version").CombinedOutput()
if err != nil {
return errors.Wrap(err, "could not get avconv version")
}

log.Infof("found avconv: %s", output)
}

if !found {
return errors.New("either ffmpeg or avconv required to run Podsync")
}

return nil
}

func (dl YoutubeDl) Download(ctx context.Context, feedConfig *config.Feed, episode *model.Episode) (io.ReadCloser, error) {
tmpDir, err := ioutil.TempDir("", "podsync-")
if err != nil {
Expand Down

0 comments on commit 4afc477

Please sign in to comment.