Skip to content

Commit

Permalink
Use youtube-dl output template with extension parameter mxpv#50
Browse files Browse the repository at this point in the history
  • Loading branch information
huseyz committed Nov 25, 2019
1 parent 2c5e333 commit e1bb023
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
7 changes: 6 additions & 1 deletion cmd/podsync/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func (u *Updater) Update(ctx context.Context, feedConfig *config.Feed) error {
})

episodePath := filepath.Join(feedPath, u.episodeName(feedConfig, episode))
episodeOutputTemplate := filepath.Join(feedPath, u.episodeNameOutputTemplate(episode))
_, err := os.Stat(episodePath)
if err != nil && !os.IsNotExist(err) {
return errors.Wrap(err, "failed to check whether episode exists")
Expand All @@ -86,7 +87,7 @@ func (u *Updater) Update(ctx context.Context, feedConfig *config.Feed) error {
if os.IsNotExist(err) {
// There is no file on disk, download episode
logger.Infof("! downloading episode %s", episode.VideoURL)
if output, err := u.downloader.Download(ctx, feedConfig, episode.VideoURL, episodePath); err == nil {
if output, err := u.downloader.Download(ctx, feedConfig, episode.VideoURL, episodeOutputTemplate); err == nil {
downloaded++
} else {
// YouTube might block host with HTTP Error 429: Too Many Requests
Expand Down Expand Up @@ -257,6 +258,10 @@ func (u *Updater) fileSize(path string) (int64, error) {
return info.Size(), nil
}

func (u *Updater) episodeNameOutputTemplate(episode *model.Episode) string {
return fmt.Sprintf("%s.%s", episode.ID, "%(ext)s")
}

func (u *Updater) makeBuilder(ctx context.Context, cfg *config.Feed) (builder.Builder, error) {
var (
provider builder.Builder
Expand Down
10 changes: 5 additions & 5 deletions pkg/ytdl/ytdl.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func New(ctx context.Context) (*YoutubeDl, error) {
return ytdl, nil
}

func (dl YoutubeDl) Download(ctx context.Context, feedConfig *config.Feed, url string, destPath string) (string, error) {
func (dl YoutubeDl) Download(ctx context.Context, feedConfig *config.Feed, url string, outputTemplate string) (string, error) {
if feedConfig.Format == model.FormatAudio {
// Audio
if feedConfig.Quality == model.QualityHigh {
Expand All @@ -50,7 +50,7 @@ func (dl YoutubeDl) Download(ctx context.Context, feedConfig *config.Feed, url s
"--format",
"bestaudio",
"--output",
destPath,
outputTemplate,
url,
)
} else { //nolint
Expand All @@ -62,7 +62,7 @@ func (dl YoutubeDl) Download(ctx context.Context, feedConfig *config.Feed, url s
"--format",
"worstaudio",
"--output",
destPath,
outputTemplate,
url,
)
}
Expand All @@ -76,7 +76,7 @@ func (dl YoutubeDl) Download(ctx context.Context, feedConfig *config.Feed, url s
"--format",
"bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best",
"--output",
destPath,
outputTemplate,
url,
)
} else { //nolint
Expand All @@ -85,7 +85,7 @@ func (dl YoutubeDl) Download(ctx context.Context, feedConfig *config.Feed, url s
"--format",
"worstvideo[ext=mp4]+worstaudio[ext=m4a]/worst[ext=mp4]/worst",
"--output",
destPath,
outputTemplate,
url,
)
}
Expand Down

0 comments on commit e1bb023

Please sign in to comment.