Implement basic title matching #92 #63

This commit is contained in:
Tom Parker-Shemilt
2020-02-17 14:31:40 -08:00
committed by GitHub
parent 23fb5ba31a
commit 336e501593
3 changed files with 21 additions and 0 deletions
+1
View File
@@ -57,6 +57,7 @@ vimeo = "{VIMEO_API_TOKEN}"
# cover_art = "{IMAGE_URL}" # Optional URL address of an image file
# max_height = "720" # Optional maximal height of video, example: 720, 1080, 1440, 2160, ...
# cron_schedule = "@every 12h" # Optional cron expression format. If set then overwrite 'update_period'. See details below
# filters = { title = "regex for title here" } # Optional Golang regexp format. If set, then only download episodes with matching titles.
```
Episodes files will be kept at: `/path/to/data/directory/ID1`, feed will be accessible from: `http://localhost/ID1.xml`
+13
View File
@@ -6,6 +6,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
"time"
@@ -110,6 +111,18 @@ func (u *Updater) downloadEpisodes(ctx context.Context, feedConfig *config.Feed,
return nil
}
if feedConfig.Filters.Title != "" {
matched, err := regexp.MatchString(feedConfig.Filters.Title, episode.Title)
if err != nil {
log.Warnf("Pattern '%s' is not a valid filter for %s Title", feedConfig.Filters.Title, feedConfig.ID)
} else {
if !matched {
log.Infof("Skipping '%s' due to lack of match with '%s'", episode.Title, feedConfig.Filters.Title)
return nil
}
}
}
downloadList = append(downloadList, episode)
return nil
}); err != nil {
+7
View File
@@ -36,6 +36,8 @@ type Feed struct {
Format model.Format `toml:"format"`
// Custom image to use
CoverArt string `toml:"cover_art"`
// Only download episodes that match this regexp (defaults to matching anything)
Filters Filters `toml:"filters"`
}
type Tokens struct {
@@ -156,3 +158,8 @@ func (d *Duration) UnmarshalText(text []byte) error {
d.Duration, err = time.ParseDuration(string(text))
return err
}
type Filters struct {
Title string `toml:"title"`
// More filters to be added here
}