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 {
|
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 {
|
type Updater struct {
|
||||||
@@ -86,7 +86,7 @@ func (u *Updater) Update(ctx context.Context, feedConfig *config.Feed) error {
|
|||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
// There is no file on disk, download episode
|
// There is no file on disk, download episode
|
||||||
logger.Infof("! downloading episode %s", episode.VideoURL)
|
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++
|
downloaded++
|
||||||
} else {
|
} else {
|
||||||
// YouTube might block host with HTTP Error 429: Too Many Requests
|
// 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
|
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"
|
ext := "mp4"
|
||||||
contentType := itunes.MP4
|
contentType := itunes.MP4
|
||||||
if feed.Format == model.FormatAudio {
|
if feed.Format == model.FormatAudio {
|
||||||
|
|||||||
@@ -40,8 +40,12 @@ func New(ctx context.Context) (*YoutubeDl, error) {
|
|||||||
return ytdl, nil
|
return ytdl, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dl YoutubeDl) Download(ctx context.Context, feedConfig *config.Feed, url string, feedPath string, episode *model.Episode) (string, error) {
|
func (dl YoutubeDl) Download(ctx context.Context, feedConfig *config.Feed, episode *model.Episode, feedPath string) (string, error) {
|
||||||
outputTemplate := youtubeDlOutputTemplate(feedPath, episode)
|
var (
|
||||||
|
outputTemplate = makeOutputTemplate(feedPath, episode)
|
||||||
|
url = episode.VideoURL
|
||||||
|
)
|
||||||
|
|
||||||
if feedConfig.Format == model.FormatAudio {
|
if feedConfig.Format == model.FormatAudio {
|
||||||
// Audio
|
// Audio
|
||||||
if feedConfig.Quality == model.QualityHigh {
|
if feedConfig.Quality == model.QualityHigh {
|
||||||
@@ -109,7 +113,7 @@ func (YoutubeDl) exec(ctx context.Context, args ...string) (string, error) {
|
|||||||
return string(output), nil
|
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")
|
filename := fmt.Sprintf("%s.%s", episode.ID, "%(ext)s")
|
||||||
return filepath.Join(feedPath, filename)
|
return filepath.Join(feedPath, filename)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user