Skip to content

Commit

Permalink
Add max_age filter to skip old episodes
Browse files Browse the repository at this point in the history
Filter max_age allows you to skip download of episodes older than n days.
  • Loading branch information
Michal Middleton committed Mar 8, 2023
1 parent f4829b0 commit 24166c4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
5 changes: 4 additions & 1 deletion cmd/podsync/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions pkg/feed/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
9 changes: 9 additions & 0 deletions services/update/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package update

import (
"regexp"
"time"

"github.com/mxpv/podsync/pkg/feed"
"github.com/mxpv/podsync/pkg/model"
Expand Down Expand Up @@ -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
}

0 comments on commit 24166c4

Please sign in to comment.