Skip to content

Commit

Permalink
Minor code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mxpv committed Nov 28, 2019
1 parent 3ba98e8 commit fe02f83
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 7 additions & 3 deletions cmd/podsync/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

type Downloader interface {
Download(ctx context.Context, feedConfig *config.Feed, url string, feedPath string, episode *model.Episode) (string, error)
Download(ctx context.Context, feedConfig *config.Feed, episode *model.Episode, feedPath string) (string, error)
}

type Updater struct {
Expand Down Expand Up @@ -86,7 +86,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, feedPath, episode); err == nil {
if output, err := u.downloader.Download(ctx, feedConfig, episode, feedPath); err == nil {
downloaded++
} else {
// YouTube might block host with HTTP Error 429: Too Many Requests
Expand Down Expand Up @@ -212,7 +212,11 @@ func (u *Updater) buildPodcast(feed *model.Feed, cfg *config.Feed, sizes map[str
return &p, nil
}

func (u *Updater) makeEnclosure(feed *model.Feed, episode *model.Episode, cfg *config.Feed) (string, itunes.EnclosureType, int64) {
func (u *Updater) makeEnclosure(
feed *model.Feed,
episode *model.Episode,
cfg *config.Feed,
) (string, itunes.EnclosureType, int64) {
ext := "mp4"
contentType := itunes.MP4
if feed.Format == model.FormatAudio {
Expand Down
10 changes: 7 additions & 3 deletions pkg/ytdl/ytdl.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ func New(ctx context.Context) (*YoutubeDl, error) {
return ytdl, nil
}

func (dl YoutubeDl) Download(ctx context.Context, feedConfig *config.Feed, url string, feedPath string, episode *model.Episode) (string, error) {
outputTemplate := youtubeDlOutputTemplate(feedPath, episode)
func (dl YoutubeDl) Download(ctx context.Context, feedConfig *config.Feed, episode *model.Episode, feedPath string) (string, error) {
var (
outputTemplate = makeOutputTemplate(feedPath, episode)
url = episode.VideoURL
)

if feedConfig.Format == model.FormatAudio {
// Audio
if feedConfig.Quality == model.QualityHigh {
Expand Down Expand Up @@ -109,7 +113,7 @@ func (YoutubeDl) exec(ctx context.Context, args ...string) (string, error) {
return string(output), nil
}

func youtubeDlOutputTemplate(feedPath string, episode *model.Episode) string {
func makeOutputTemplate(feedPath string, episode *model.Episode) string {
filename := fmt.Sprintf("%s.%s", episode.ID, "%(ext)s")
return filepath.Join(feedPath, filename)
}

0 comments on commit fe02f83

Please sign in to comment.