Skip to content

Commit

Permalink
Implement basic title matching #92 #63
Browse files Browse the repository at this point in the history
  • Loading branch information
palfrey authored Feb 17, 2020
1 parent 23fb5ba commit 336e501
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
13 changes: 13 additions & 0 deletions cmd/podsync/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

0 comments on commit 336e501

Please sign in to comment.