mirror of
https://github.com/mxpv/podsync.git
synced 2024-05-11 05:55:04 +00:00
Minor code refactoring
This commit is contained in:
@@ -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 {
|
||||
@@ -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
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user