From f3565b2895a0a1fa76bf4aee7d7d93e824e9e3d7 Mon Sep 17 00:00:00 2001 From: Maksym Pavlenko Date: Sat, 7 Mar 2020 22:32:51 -0800 Subject: [PATCH] Improve feed customizations --- README.md | 2 +- pkg/config/config.go | 9 +++++++++ pkg/config/config_test.go | 6 ++++++ pkg/db/badger_test.go | 1 - pkg/feed/build.go | 26 +++++++++++++++++++------- pkg/model/feed.go | 2 -- 6 files changed, 35 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index c1ac92f2..9c88f264 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ any device in podcast client. - mp3 encoding - Update scheduler supports cron expressions - Episodes filtering (match by title). -- Feeds customizations (custom artwork). +- Feeds customizations (custom artwork, category, language, etc). - Supports episodes cleanup (keep last X episodes). - One-click deployment for AWS. - Runs on Windows, Mac OS, Linux, and Docker. diff --git a/pkg/config/config.go b/pkg/config/config.go index bbb57c47..d1a7435a 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -40,6 +40,15 @@ type Feed struct { Filters Filters `toml:"filters"` // Clean is a cleanup policy to use for this feed Clean Cleanup `toml:"clean"` + // Custom is a list of feed customizations + Custom Custom `toml:"custom"` +} + +type Custom struct { + CoverArt string `toml:"cover_art"` + Category string `toml:"category"` + Explicit bool `toml:"explicit"` + Language string `toml:"lang"` } type Tokens struct { diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 4cdb8ab0..50105403 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -34,6 +34,7 @@ dir = "/home/user/db/" quality = "low" filters = { title = "regex for title here" } clean = { keep_last = 10 } + custom = { cover_art = "http://img", category = "TV", explicit = true, lang = "en" } ` f, err := ioutil.TempFile("", "") @@ -66,6 +67,11 @@ dir = "/home/user/db/" assert.EqualValues(t, "low", feed.Quality) assert.EqualValues(t, "regex for title here", feed.Filters.Title) assert.EqualValues(t, 10, feed.Clean.KeepLast) + + assert.EqualValues(t, "http://img", feed.Custom.CoverArt) + assert.EqualValues(t, "TV", feed.Custom.Category) + assert.True(t, feed.Custom.Explicit) + assert.EqualValues(t, "en", feed.Custom.Language) } func TestApplyDefaults(t *testing.T) { diff --git a/pkg/db/badger_test.go b/pkg/db/badger_test.go index 661496f7..68a7511e 100644 --- a/pkg/db/badger_test.go +++ b/pkg/db/badger_test.go @@ -196,7 +196,6 @@ func getFeed() *model.Feed { Format: "video", Quality: "high", PageSize: 50, - Language: "en", Title: "Test", Description: "Test", PubDate: time.Now().UTC(), diff --git a/pkg/feed/build.go b/pkg/feed/build.go index 8763211f..9c8f057e 100644 --- a/pkg/feed/build.go +++ b/pkg/feed/build.go @@ -23,24 +23,36 @@ func Build(ctx context.Context, feed *model.Feed, cfg *config.Feed, provider url defaultCategory = "TV & Film" ) - now := time.Now().UTC() + var ( + now = time.Now().UTC() + ) p := itunes.New(feed.Title, feed.ItemURL, feed.Description, &feed.PubDate, &now) p.Generator = podsyncGenerator p.AddSubTitle(feed.Title) - p.AddCategory(defaultCategory, nil) - p.AddImage(feed.CoverArt) p.IAuthor = feed.Title p.AddSummary(feed.Description) - if feed.Explicit { + if cfg.Custom.CoverArt != "" { + p.AddImage(cfg.Custom.CoverArt) + } else { + p.AddImage(feed.CoverArt) + } + + if cfg.Custom.Category != "" { + p.AddCategory(cfg.Custom.Category, nil) + } else { + p.AddCategory(defaultCategory, nil) + } + + if cfg.Custom.Explicit { p.IExplicit = "yes" } else { p.IExplicit = "no" } - if feed.Language != "" { - p.Language = feed.Language + if cfg.Custom.Language != "" { + p.Language = cfg.Custom.Language } for i, episode := range feed.Episodes { @@ -87,7 +99,7 @@ func Build(ctx context.Context, feed *model.Feed, cfg *config.Feed, provider url item.Description = " " } - if feed.Explicit { + if cfg.Custom.Explicit { item.IExplicit = "yes" } else { item.IExplicit = "no" diff --git a/pkg/model/feed.go b/pkg/model/feed.go index a493b54e..d8a64a44 100644 --- a/pkg/model/feed.go +++ b/pkg/model/feed.go @@ -48,8 +48,6 @@ type Feed struct { Quality Quality `json:"quality"` PageSize int `json:"page_size"` CoverArt string `json:"cover_art"` - Explicit bool `json:"explicit"` - Language string `json:"language"` // ISO 639 Title string `json:"title"` Description string `json:"description"` PubDate time.Time `json:"pub_date"`