2022-05-08 16:57:25 -07:00
|
|
|
package update
|
|
|
|
|
|
|
|
import (
|
|
|
|
"regexp"
|
|
|
|
|
|
|
|
"github.com/mxpv/podsync/pkg/feed"
|
|
|
|
"github.com/mxpv/podsync/pkg/model"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
func matchRegexpFilter(pattern, str string, negative bool, logger log.FieldLogger) bool {
|
|
|
|
if pattern != "" {
|
|
|
|
matched, err := regexp.MatchString(pattern, str)
|
|
|
|
if err != nil {
|
|
|
|
logger.Warnf("pattern %q is not a valid")
|
|
|
|
} else {
|
|
|
|
if matched == negative {
|
2022-11-19 21:51:14 +02:00
|
|
|
logger.Infof("skipping due to regexp mismatch")
|
2022-05-08 16:57:25 -07:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func matchFilters(episode *model.Episode, filters *feed.Filters) bool {
|
|
|
|
logger := log.WithFields(log.Fields{"episode_id": episode.ID})
|
|
|
|
if !matchRegexpFilter(filters.Title, episode.Title, false, logger.WithField("filter", "title")) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if !matchRegexpFilter(filters.NotTitle, episode.Title, true, logger.WithField("filter", "not_title")) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if !matchRegexpFilter(filters.Description, episode.Description, false, logger.WithField("filter", "description")) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if !matchRegexpFilter(filters.NotDescription, episode.Description, true, logger.WithField("filter", "not_description")) {
|
|
|
|
return false
|
|
|
|
}
|
2022-11-19 22:36:57 +02:00
|
|
|
|
2022-11-23 20:04:07 +02:00
|
|
|
if filters.MaxDuration > 0 && episode.Duration > filters.MaxDuration {
|
|
|
|
logger.WithField("filter", "max_duration").Infof("skipping due to duration filter (%ds)", episode.Duration)
|
2022-11-19 21:51:14 +02:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-11-23 20:04:07 +02:00
|
|
|
if filters.MinDuration > 0 && episode.Duration < filters.MinDuration {
|
|
|
|
logger.WithField("filter", "min_duration").Infof("skipping due to duration filter (%ds)", episode.Duration)
|
2022-11-19 21:51:14 +02:00
|
|
|
return false
|
|
|
|
}
|
2022-05-08 16:57:25 -07:00
|
|
|
|
|
|
|
return true
|
|
|
|
}
|