1
0
mirror of https://github.com/mxpv/podsync.git synced 2024-05-11 05:55:04 +00:00

Add max_age filter to skip old episodes

Filter max_age allows you to skip download of episodes older than n days.
This commit is contained in:
Michal Middleton
2023-03-01 20:31:01 -06:00
parent f4829b0467
commit 24166c46ac
4 changed files with 16 additions and 2 deletions

View File

@@ -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)

View File

@@ -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.

View File

@@ -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
}

View File

@@ -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
}