From 336e50159376a2cec69cb7a28cfc958ce3f1c201 Mon Sep 17 00:00:00 2001 From: Tom Parker-Shemilt Date: Mon, 17 Feb 2020 22:31:40 +0000 Subject: [PATCH] Implement basic title matching #92 #63 --- README.md | 1 + cmd/podsync/updater.go | 13 +++++++++++++ pkg/config/config.go | 7 +++++++ 3 files changed, 21 insertions(+) diff --git a/README.md b/README.md index f80e51f..4647aa4 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ vimeo = "{VIMEO_API_TOKEN}" # cover_art = "{IMAGE_URL}" # Optional URL address of an image file # 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" } # Optional Golang regexp format. If set, then only download episodes with matching titles. ``` Episodes files will be kept at: `/path/to/data/directory/ID1`, feed will be accessible from: `http://localhost/ID1.xml` diff --git a/cmd/podsync/updater.go b/cmd/podsync/updater.go index b97c9b8..9138e39 100644 --- a/cmd/podsync/updater.go +++ b/cmd/podsync/updater.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "os" "path/filepath" + "regexp" "strconv" "strings" "time" @@ -110,6 +111,18 @@ func (u *Updater) downloadEpisodes(ctx context.Context, feedConfig *config.Feed, return nil } + if feedConfig.Filters.Title != "" { + matched, err := regexp.MatchString(feedConfig.Filters.Title, episode.Title) + if err != nil { + log.Warnf("Pattern '%s' is not a valid filter for %s Title", feedConfig.Filters.Title, feedConfig.ID) + } else { + if !matched { + log.Infof("Skipping '%s' due to lack of match with '%s'", episode.Title, feedConfig.Filters.Title) + return nil + } + } + } + downloadList = append(downloadList, episode) return nil }); err != nil { diff --git a/pkg/config/config.go b/pkg/config/config.go index 2deaaee..7cdecd0 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -36,6 +36,8 @@ type Feed struct { Format model.Format `toml:"format"` // Custom image to use CoverArt string `toml:"cover_art"` + // Only download episodes that match this regexp (defaults to matching anything) + Filters Filters `toml:"filters"` } type Tokens struct { @@ -156,3 +158,8 @@ func (d *Duration) UnmarshalText(text []byte) error { d.Duration, err = time.ParseDuration(string(text)) return err } + +type Filters struct { + Title string `toml:"title"` + // More filters to be added here +}