Skip to content

Commit

Permalink
Merge pull request #457 from Th0masL/add_duration_filters
Browse files Browse the repository at this point in the history
Add min and max duration filters
  • Loading branch information
mxpv authored Nov 30, 2022
2 parents 5b7ddeb + 4ebdc47 commit 8e761bc
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ venv/

.DS_Store
/podsync
podsync.log

db
config.toml
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ any device in podcast client.
- Supports feeds configuration: video/audio, high/low quality, max video height, etc.
- mp3 encoding
- Update scheduler supports cron expressions
- Episodes filtering (match by title).
- Episodes filtering (match by title, duration).
- Feeds customizations (custom artwork, category, language, etc).
- OPML export.
- Supports episodes cleanup (keep last X episodes).
Expand Down
4 changes: 3 additions & 1 deletion cmd/podsync/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ timeout = 15
update_period = "5h"
format = "audio"
quality = "low"
filters = { title = "regex for title here" }
filters = { title = "regex for title here", min_duration = 0, max_duration = 86400}
playlist_sort = "desc"
clean = { keep_last = 10 }
[feeds.XYZ.custom]
Expand Down Expand Up @@ -78,6 +78,8 @@ timeout = 15
assert.EqualValues(t, "audio", feed.Format)
assert.EqualValues(t, "low", feed.Quality)
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, 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 @@ -74,7 +74,8 @@ vimeo = [ # Multiple keys will be rotated.

# Optional Golang regexp format.
# If set, then only download matching episodes.
filters = { title = "regex for title here", not_title = "regex for negative title match", description = "...", not_description = "..." }
# 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 }

# 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
4 changes: 3 additions & 1 deletion pkg/feed/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Config struct {
Format model.Format `toml:"format"`
// Custom format properties
CustomFormat CustomFormat `toml:"custom_format"`
// Only download episodes that match this regexp (defaults to matching anything)
// Only download episodes that match the filters (defaults to matching anything)
Filters Filters `toml:"filters"`
// Clean is a cleanup policy to use for this feed
Clean Cleanup `toml:"clean"`
Expand All @@ -56,6 +56,8 @@ type Filters struct {
NotTitle string `toml:"not_title"`
Description string `toml:"description"`
NotDescription string `toml:"not_description"`
MinDuration int64 `toml:"min_duration"`
MaxDuration int64 `toml:"max_duration"`
// More filters to be added here
}

Expand Down
12 changes: 11 additions & 1 deletion services/update/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func matchRegexpFilter(pattern, str string, negative bool, logger log.FieldLogge
logger.Warnf("pattern %q is not a valid")
} else {
if matched == negative {
logger.Infof("skipping due to mismatch")
logger.Infof("skipping due to regexp mismatch")
return false
}
}
Expand All @@ -41,5 +41,15 @@ func matchFilters(episode *model.Episode, filters *feed.Filters) bool {
return false
}

if filters.MaxDuration > 0 && episode.Duration > filters.MaxDuration {
logger.WithField("filter", "max_duration").Infof("skipping due to duration filter (%ds)", episode.Duration)
return false
}

if filters.MinDuration > 0 && episode.Duration < filters.MinDuration {
logger.WithField("filter", "min_duration").Infof("skipping due to duration filter (%ds)", episode.Duration)
return false
}

return true
}

0 comments on commit 8e761bc

Please sign in to comment.