From 054993dff75c5f5a0a4432b359f4db4f05316b0d Mon Sep 17 00:00:00 2001 From: delaosa Date: Sun, 5 Apr 2020 20:10:24 +0200 Subject: [PATCH] fix YoutubeDL output template --- pkg/ytdl/ytdl.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pkg/ytdl/ytdl.go b/pkg/ytdl/ytdl.go index 409ade0..d40039b 100644 --- a/pkg/ytdl/ytdl.go +++ b/pkg/ytdl/ytdl.go @@ -55,11 +55,8 @@ func (dl YoutubeDl) Download(ctx context.Context, feedConfig *config.Feed, episo return nil, errors.Wrap(err, "failed to get temp dir for download") } - ext := "mp4" - if feedConfig.Format == model.FormatAudio { - ext = "mp3" - } - filePath := filepath.Join(tmpDir, fmt.Sprintf("%s.%s", episode.ID, ext)) + // filePath with YoutubeDl template format + filePath := filepath.Join(tmpDir, fmt.Sprintf("%s.%s", episode.ID, "%(ext)s")) args := buildArgs(feedConfig, episode, filePath) output, err := dl.exec(ctx, args...) @@ -74,6 +71,12 @@ func (dl YoutubeDl) Download(ctx context.Context, feedConfig *config.Feed, episo return nil, errors.New(output) } + ext := "mp4" + if feedConfig.Format == model.FormatAudio { + ext = "mp3" + } + // filePath now with the final extension + filePath = filepath.Join(tmpDir, fmt.Sprintf("%s.%s", episode.ID, ext)) f, err := os.Open(filePath) if err != nil { return nil, errors.Wrap(err, "failed to open downloaded file")