Skip to content

Commit

Permalink
Customize subcategories #161
Browse files Browse the repository at this point in the history
  • Loading branch information
mxpv committed Oct 4, 2020
1 parent fc952bf commit 0ce6e99
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ vimeo = [ # Multiple keys will be rotated.
update_period = "12h" # How often query for updates, examples: "60m", "4h", "2h45m"
quality = "high" # or "low"
format = "video" # or "audio"
# custom = { cover_art = "{IMAGE_URL}}", category = "TV", explicit = true, lang = "en" } # Optional feed customizations
# custom = { cover_art = "{IMAGE_URL}}", category = "TV", subcategories = ["Documentary", "Tech News"], explicit = true, lang = "en" } # Optional feed customizations
# max_height = "720" # Optional maximal height of video, example: 720, 1080, 1440, 2160, ...
# cron_schedule = "@every 12h" # Optional cron expression format. If set then overwrite 'update_period'. See details below
# filters = { title = "regex for title here", not_title = "regex for negative title match", description = "...", not_description = "..." } # Optional Golang regexp format. If set, then only download matching episodes.
Expand Down
15 changes: 8 additions & 7 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ type Filters struct {
}

type Custom struct {
CoverArt string `toml:"cover_art"`
Category string `toml:"category"`
Explicit bool `toml:"explicit"`
Language string `toml:"lang"`
Author string `toml:"author"`
Title string `toml:"title"`
Description string `toml:"description"`
CoverArt string `toml:"cover_art"`
Category string `toml:"category"`
Subcategories []string `toml:"subcategories"`
Explicit bool `toml:"explicit"`
Language string `toml:"lang"`
Author string `toml:"author"`
Title string `toml:"title"`
Description string `toml:"description"`
}

type Server struct {
Expand Down
4 changes: 3 additions & 1 deletion pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ self_update = true
quality = "low"
filters = { title = "regex for title here" }
clean = { keep_last = 10 }
custom = { cover_art = "http://img", category = "TV", explicit = true, lang = "en" }
custom = { cover_art = "http://img", category = "TV", subcategories = ["1", "2"], explicit = true, lang = "en" }
`
path := setup(t, file)
defer os.Remove(path)
Expand Down Expand Up @@ -76,6 +76,8 @@ self_update = true
assert.True(t, feed.Custom.Explicit)
assert.EqualValues(t, "en", feed.Custom.Language)

assert.EqualValues(t, feed.Custom.Subcategories, []string{"1", "2"})

assert.Nil(t, config.Database.Badger)

assert.True(t, config.Downloader.SelfUpdate)
Expand Down
4 changes: 2 additions & 2 deletions pkg/feed/xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ func Build(ctx context.Context, feed *model.Feed, cfg *config.Feed, provider url
}

if cfg.Custom.Category != "" {
p.AddCategory(cfg.Custom.Category, nil)
p.AddCategory(cfg.Custom.Category, cfg.Custom.Subcategories)
} else {
p.AddCategory(defaultCategory, nil)
p.AddCategory(defaultCategory, cfg.Custom.Subcategories)
}

if cfg.Custom.Explicit {
Expand Down
39 changes: 39 additions & 0 deletions pkg/feed/xml_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package feed

import (
"context"
"testing"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/mxpv/podsync/pkg/config"
"github.com/mxpv/podsync/pkg/model"
)

func TestBuildXML(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

urlMock := NewMockurlProvider(ctrl)

feed := model.Feed{}

cfg := config.Feed{
Custom: config.Custom{Description: "description", Category: "Technology", Subcategories: []string{"Gadgets", "Podcasting"}},
}

out, err := Build(context.Background(), &feed, &cfg, urlMock)
assert.NoError(t, err)

assert.EqualValues(t, "description", out.Description)
assert.EqualValues(t, "Technology", out.Category)

require.Len(t, out.ICategories, 1)
category := out.ICategories[0]
assert.EqualValues(t, "Technology", category.Text)
require.Len(t, category.ICategories, 2)
assert.EqualValues(t, "Gadgets", category.ICategories[0].Text)
assert.EqualValues(t, "Podcasting", category.ICategories[1].Text)
}

0 comments on commit 0ce6e99

Please sign in to comment.