From 4476094add8c007d90db33728bfb81efc646a1c9 Mon Sep 17 00:00:00 2001 From: James Bayliss Date: Tue, 16 Feb 2021 19:09:01 +0000 Subject: [PATCH] rss: use filters hash relative to its own pvrs --- cmd/nabarr/main.go | 9 ++------- cmd/nabarr/pvr/pvr.go | 1 + radarr/radarr.go | 4 ++++ rss/job.go | 3 ++- rss/process.go | 6 ------ rss/rss.go | 14 ++++++-------- sonarr/sonarr.go | 4 ++++ 7 files changed, 19 insertions(+), 22 deletions(-) diff --git a/cmd/nabarr/main.go b/cmd/nabarr/main.go index 6f0be1c..c39a9d3 100644 --- a/cmd/nabarr/main.go +++ b/cmd/nabarr/main.go @@ -10,7 +10,6 @@ import ( "github.com/l3uddz/nabarr/cmd/nabarr/pvr" "github.com/l3uddz/nabarr/media" "github.com/l3uddz/nabarr/rss" - "github.com/l3uddz/nabarr/util" "github.com/lefelys/state" "github.com/natefinch/lumberjack" "github.com/rs/zerolog" @@ -156,9 +155,8 @@ func main() { // pvrs log.Trace().Msg("Initialising pvrs") - cacheFiltersHash := "" - pvrs := make(map[string]pvr.PVR, 0) + pvrs := make(map[string]pvr.PVR, 0) for _, p := range cfg.Pvrs { if ctx.Command() == "run" || (ctx.Command() == "test" && strings.EqualFold(cli.Test.Pvr, p.Name)) { // init pvr @@ -175,9 +173,6 @@ func main() { // add pvr to map pvrs[p.Name] = po - - // add cacheFiltersHash - cacheFiltersHash += util.AsSHA256(p.Filters) } } @@ -185,7 +180,7 @@ func main() { if ctx.Command() == "run" { // rss log.Trace().Msg("Initialising rss") - r := rss.New(cfg.Rss, c, cacheFiltersHash, pvrs) + r := rss.New(cfg.Rss, c, pvrs) for _, feed := range cfg.Rss.Feeds { if err := r.AddJob(feed); err != nil { log.Fatal(). diff --git a/cmd/nabarr/pvr/pvr.go b/cmd/nabarr/pvr/pvr.go index e7a7ae2..523abd9 100644 --- a/cmd/nabarr/pvr/pvr.go +++ b/cmd/nabarr/pvr/pvr.go @@ -13,6 +13,7 @@ import ( type PVR interface { Type() string + GetFiltersHash() string AddMediaItem(*media.Item) error ShouldIgnore(*media.Item) (bool, string, error) Start() state.State diff --git a/radarr/radarr.go b/radarr/radarr.go index 4a94d18..2f5f11a 100644 --- a/radarr/radarr.go +++ b/radarr/radarr.go @@ -108,3 +108,7 @@ func New(c nabarr.PvrConfig, mode string, m *media.Client, cc *cache.Client) (*C func (c *Client) Type() string { return c.pvrType } + +func (c *Client) GetFiltersHash() string { + return c.cacheFiltersHash +} diff --git a/rss/job.go b/rss/job.go index db5139c..f6f01ac 100644 --- a/rss/job.go +++ b/rss/job.go @@ -30,7 +30,7 @@ func (c *Client) AddJob(feed feedItem) error { cron: c.cron, cache: c.cache, cacheDuration: feed.CacheDuration, - cacheFiltersHash: c.cacheFiltersHash, + cacheFiltersHash: "", } // add pvrs @@ -40,6 +40,7 @@ func (c *Client) AddJob(feed feedItem) error { return fmt.Errorf("pvr object does not exist: %v", p) } job.pvrs[p] = po + job.cacheFiltersHash += po.GetFiltersHash() } // schedule job diff --git a/rss/process.go b/rss/process.go index 9ca2828..175e1d5 100644 --- a/rss/process.go +++ b/rss/process.go @@ -5,7 +5,6 @@ import ( "fmt" "github.com/l3uddz/nabarr/media" "github.com/lucperkins/rek" - "sort" "strings" "time" ) @@ -72,11 +71,6 @@ func (j *rssJob) getFeed() ([]media.FeedItem, error) { return items, nil } - // sort response items - sort.SliceStable(b.Channel.Items, func(i, j int) bool { - return b.Channel.Items[i].PubDate.After(b.Channel.Items[j].PubDate.Time) - }) - // process feed items for p, i := range b.Channel.Items { // ignore items diff --git a/rss/rss.go b/rss/rss.go index c90357d..e199bc1 100644 --- a/rss/rss.go +++ b/rss/rss.go @@ -11,22 +11,20 @@ import ( ) type Client struct { - cron *cron.Cron - cache *cache.Client - cacheFiltersHash string - pvrs map[string]pvr.PVR + cron *cron.Cron + cache *cache.Client + pvrs map[string]pvr.PVR log zerolog.Logger } -func New(c Config, cc *cache.Client, cfh string, pvrs map[string]pvr.PVR) *Client { +func New(c Config, cc *cache.Client, pvrs map[string]pvr.PVR) *Client { return &Client{ cron: cron.New(cron.WithChain( cron.Recover(cron.DefaultLogger), )), - cache: cc, - cacheFiltersHash: cfh, - pvrs: pvrs, + cache: cc, + pvrs: pvrs, log: logger.New(c.Verbosity).With().Logger(), } diff --git a/sonarr/sonarr.go b/sonarr/sonarr.go index 378e5ec..4a8fc34 100644 --- a/sonarr/sonarr.go +++ b/sonarr/sonarr.go @@ -108,3 +108,7 @@ func New(c nabarr.PvrConfig, mode string, m *media.Client, cc *cache.Client) (*C func (c *Client) Type() string { return c.pvrType } + +func (c *Client) GetFiltersHash() string { + return c.cacheFiltersHash +}