Skip to content

Commit

Permalink
Improve feed customizations
Browse files Browse the repository at this point in the history
  • Loading branch information
mxpv committed Mar 8, 2020
1 parent 7ca1d03 commit f3565b2
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions pkg/config/config.go
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions pkg/config/config_test.go
Expand Up @@ -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("", "")
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion pkg/db/badger_test.go
Expand Up @@ -196,7 +196,6 @@ func getFeed() *model.Feed {
Format: "video",
Quality: "high",
PageSize: 50,
Language: "en",
Title: "Test",
Description: "Test",
PubDate: time.Now().UTC(),
Expand Down
26 changes: 19 additions & 7 deletions pkg/feed/build.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 0 additions & 2 deletions pkg/model/feed.go
Expand Up @@ -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"`
Expand Down

0 comments on commit f3565b2

Please sign in to comment.