diff --git a/config.toml.example b/config.toml.example index 9e3ac6e..98cea59 100644 --- a/config.toml.example +++ b/config.toml.example @@ -50,8 +50,8 @@ vimeo = [ # Multiple keys will be rotated. # How often query for updates, examples: "60m", "4h", "2h45m" update_period = "12h" - quality = "high" # or "low" - format = "video" # or: "audio", "custom" + quality = "high" # "high" or "low" + format = "video" # "audio", "video" or "custom" # When format = "custom" # YouTubeDL format parameter and result file extension custom_format = { youtube_dl_format = "bestaudio[ext=m4a]", extension = "m4a" } diff --git a/pkg/feed/xml.go b/pkg/feed/xml.go index 0d96e8a..3b11868 100644 --- a/pkg/feed/xml.go +++ b/pkg/feed/xml.go @@ -133,6 +133,10 @@ func Build(_ctx context.Context, feed *model.Feed, cfg *Config, hostname string) if feed.Format == model.FormatAudio { enclosureType = itunes.MP3 } + if feed.Format == model.FormatCustom { + enclosureType = EnclosureFromExtension(cfg) + } + var ( episodeName = EpisodeName(cfg, episode) @@ -164,9 +168,32 @@ func EpisodeName(feedConfig *Config, episode *model.Episode) string { ext := "mp4" if feedConfig.Format == model.FormatAudio { ext = "mp3" - } else if feedConfig.Format == model.FormatCustom { + } + if feedConfig.Format == model.FormatCustom { ext = feedConfig.CustomFormat.Extension } return fmt.Sprintf("%s.%s", episode.ID, ext) } + +func EnclosureFromExtension(feedConfig *Config) itunes.EnclosureType { + ext := feedConfig.CustomFormat.Extension + // Use switch on the day variable. + switch { + case ext == "m4a": + return itunes.M4A + case ext == "m4v": + return itunes.M4V + case ext == "mp4": + return itunes.MP4 + case ext == "mp3": + return itunes.MP3 + case ext == "mov": + return itunes.MOV + case ext == "pdf": + return itunes.PDF + case ext == "epub": + return itunes.EPUB + } + return -1 +} diff --git a/pkg/model/feed.go b/pkg/model/feed.go index fb6cc40..ac68af3 100644 --- a/pkg/model/feed.go +++ b/pkg/model/feed.go @@ -21,6 +21,21 @@ const ( FormatCustom = Format("custom") ) +// Format to convert episode when downloading episodes +type Enclosure struct { + // ID of episode + ID string `json:"id"` + Title string `json:"title"` + Description string `json:"description"` + Thumbnail string `json:"thumbnail"` + Duration int64 `json:"duration"` + VideoURL string `json:"video_url"` + PubDate time.Time `json:"pub_date"` + Size int64 `json:"size"` + Order string `json:"order"` + Status EpisodeStatus `json:"status"` // Disk status +} + // Playlist sorting style type Sorting string diff --git a/pkg/ytdl/ytdl.go b/pkg/ytdl/ytdl.go index 7dfc178..1d33a92 100644 --- a/pkg/ytdl/ytdl.go +++ b/pkg/ytdl/ytdl.go @@ -197,7 +197,8 @@ func (dl *YoutubeDl) Download(ctx context.Context, feedConfig *feed.Config, epis ext := "mp4" if feedConfig.Format == model.FormatAudio { ext = "mp3" - } else if feedConfig.Format == model.FormatCustom { + } + if feedConfig.Format == model.FormatCustom { ext = feedConfig.CustomFormat.Extension }