Skip to content

Commit 24166c4

Browse files
author
Michal Middleton
committed
Add max_age filter to skip old episodes
Filter max_age allows you to skip download of episodes older than n days.
1 parent f4829b0 commit 24166c4

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

cmd/podsync/config_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ timeout = 15
3737
update_period = "5h"
3838
format = "audio"
3939
quality = "low"
40-
filters = { title = "regex for title here", min_duration = 0, max_duration = 86400}
40+
# duration filters are in seconds
41+
# max_age is in days
42+
filters = { title = "regex for title here", min_duration = 0, max_duration = 86400, max_age = 365}
4143
playlist_sort = "desc"
4244
clean = { keep_last = 10 }
4345
[feeds.XYZ.custom]
@@ -80,6 +82,7 @@ timeout = 15
8082
assert.EqualValues(t, "regex for title here", feed.Filters.Title)
8183
assert.EqualValues(t, 0, feed.Filters.MinDuration)
8284
assert.EqualValues(t, 86400, feed.Filters.MaxDuration)
85+
assert.EqualValues(t, 365, feed.Filters.MaxAge)
8386
assert.EqualValues(t, 10, feed.Clean.KeepLast)
8487
assert.EqualValues(t, model.SortingDesc, feed.PlaylistSort)
8588

config.toml.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ vimeo = [ # Multiple keys will be rotated.
7575
# Optional Golang regexp format.
7676
# If set, then only download matching episodes.
7777
# Duration filters are in seconds.
78-
filters = { title = "regex for title here", not_title = "regex for negative title match", description = "...", not_description = "...", min_duration = 0, max_duration = 86400 }
78+
# max_age filter is in days.
79+
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 }
7980

8081
# Optional extra arguments passed to youtube-dl when downloading videos from this feed.
8182
# This example would embed available English closed captions in the videos.

pkg/feed/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ type Filters struct {
5858
NotDescription string `toml:"not_description"`
5959
MinDuration int64 `toml:"min_duration"`
6060
MaxDuration int64 `toml:"max_duration"`
61+
MaxAge int `toml:"max_age"`
6162
// More filters to be added here
6263
}
6364

services/update/matcher.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package update
22

33
import (
44
"regexp"
5+
"time"
56

67
"github.com/mxpv/podsync/pkg/feed"
78
"github.com/mxpv/podsync/pkg/model"
@@ -51,5 +52,13 @@ func matchFilters(episode *model.Episode, filters *feed.Filters) bool {
5152
return false
5253
}
5354

55+
if filters.MaxAge > 0 {
56+
dateDiff := int(time.Since(episode.PubDate).Hours()) / 24
57+
if dateDiff > filters.MaxAge {
58+
logger.WithField("filter", "max_age").Infof("skipping due to max_age filter (%dd > %dd)", dateDiff, filters.MaxAge)
59+
return false
60+
}
61+
}
62+
5463
return true
5564
}

0 commit comments

Comments
 (0)