diff --git a/cmd/podsync/config_test.go b/cmd/podsync/config_test.go index 9a79a97..c4b13a6 100644 --- a/cmd/podsync/config_test.go +++ b/cmd/podsync/config_test.go @@ -37,7 +37,9 @@ timeout = 15 update_period = "5h" format = "audio" quality = "low" - filters = { title = "regex for title here", min_duration = 0, max_duration = 86400} + # duration filters are in seconds + # max_age is in days + filters = { title = "regex for title here", min_duration = 0, max_duration = 86400, max_age = 365} playlist_sort = "desc" clean = { keep_last = 10 } [feeds.XYZ.custom] @@ -80,6 +82,7 @@ timeout = 15 assert.EqualValues(t, "regex for title here", feed.Filters.Title) assert.EqualValues(t, 0, feed.Filters.MinDuration) assert.EqualValues(t, 86400, feed.Filters.MaxDuration) + assert.EqualValues(t, 365, feed.Filters.MaxAge) assert.EqualValues(t, 10, feed.Clean.KeepLast) assert.EqualValues(t, model.SortingDesc, feed.PlaylistSort) diff --git a/config.toml.example b/config.toml.example index 8ee6b42..6dd6afc 100644 --- a/config.toml.example +++ b/config.toml.example @@ -75,7 +75,8 @@ vimeo = [ # Multiple keys will be rotated. # Optional Golang regexp format. # If set, then only download matching episodes. # Duration filters are in seconds. - filters = { title = "regex for title here", not_title = "regex for negative title match", description = "...", not_description = "...", min_duration = 0, max_duration = 86400 } + # max_age filter is in days. + filters = { title = "regex for title here", not_title = "regex for negative title match", description = "...", not_description = "...", min_duration = 0, max_duration = 86400, max_age = 365 } # Optional extra arguments passed to youtube-dl when downloading videos from this feed. # This example would embed available English closed captions in the videos. diff --git a/pkg/feed/config.go b/pkg/feed/config.go index dd75551..d45f0f7 100644 --- a/pkg/feed/config.go +++ b/pkg/feed/config.go @@ -58,6 +58,7 @@ type Filters struct { NotDescription string `toml:"not_description"` MinDuration int64 `toml:"min_duration"` MaxDuration int64 `toml:"max_duration"` + MaxAge int `toml:"max_age"` // More filters to be added here } diff --git a/services/update/matcher.go b/services/update/matcher.go index b432fcb..8470dca 100644 --- a/services/update/matcher.go +++ b/services/update/matcher.go @@ -2,6 +2,7 @@ package update import ( "regexp" + "time" "github.com/mxpv/podsync/pkg/feed" "github.com/mxpv/podsync/pkg/model" @@ -51,5 +52,13 @@ func matchFilters(episode *model.Episode, filters *feed.Filters) bool { return false } + if filters.MaxAge > 0 { + dateDiff := int(time.Since(episode.PubDate).Hours()) / 24 + if dateDiff > filters.MaxAge { + logger.WithField("filter", "max_age").Infof("skipping due to max_age filter (%dd > %dd)", dateDiff, filters.MaxAge) + return false + } + } + return true }