1
0
mirror of https://github.com/mxpv/podsync.git synced 2024-05-11 05:55:04 +00:00

Detect ffmpeg or avconv for youtube-dl #122

This commit is contained in:
Maksym Pavlenko
2020-04-16 15:36:03 -07:00
parent 67478ac9f4
commit 4afc4774d3

View File

@ -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 {