rss: use filters hash relative to its own pvrs

This commit is contained in:
James Bayliss
2021-02-16 19:09:01 +00:00
parent 495c5a5c1a
commit 4476094add
7 changed files with 19 additions and 22 deletions

View File

@@ -10,7 +10,6 @@ import (
"github.com/l3uddz/nabarr/cmd/nabarr/pvr" "github.com/l3uddz/nabarr/cmd/nabarr/pvr"
"github.com/l3uddz/nabarr/media" "github.com/l3uddz/nabarr/media"
"github.com/l3uddz/nabarr/rss" "github.com/l3uddz/nabarr/rss"
"github.com/l3uddz/nabarr/util"
"github.com/lefelys/state" "github.com/lefelys/state"
"github.com/natefinch/lumberjack" "github.com/natefinch/lumberjack"
"github.com/rs/zerolog" "github.com/rs/zerolog"
@@ -156,9 +155,8 @@ func main() {
// pvrs // pvrs
log.Trace().Msg("Initialising 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 { for _, p := range cfg.Pvrs {
if ctx.Command() == "run" || (ctx.Command() == "test" && strings.EqualFold(cli.Test.Pvr, p.Name)) { if ctx.Command() == "run" || (ctx.Command() == "test" && strings.EqualFold(cli.Test.Pvr, p.Name)) {
// init pvr // init pvr
@@ -175,9 +173,6 @@ func main() {
// add pvr to map // add pvr to map
pvrs[p.Name] = po pvrs[p.Name] = po
// add cacheFiltersHash
cacheFiltersHash += util.AsSHA256(p.Filters)
} }
} }
@@ -185,7 +180,7 @@ func main() {
if ctx.Command() == "run" { if ctx.Command() == "run" {
// rss // rss
log.Trace().Msg("Initialising 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 { for _, feed := range cfg.Rss.Feeds {
if err := r.AddJob(feed); err != nil { if err := r.AddJob(feed); err != nil {
log.Fatal(). log.Fatal().

View File

@@ -13,6 +13,7 @@ import (
type PVR interface { type PVR interface {
Type() string Type() string
GetFiltersHash() string
AddMediaItem(*media.Item) error AddMediaItem(*media.Item) error
ShouldIgnore(*media.Item) (bool, string, error) ShouldIgnore(*media.Item) (bool, string, error)
Start() state.State Start() state.State

View File

@@ -108,3 +108,7 @@ func New(c nabarr.PvrConfig, mode string, m *media.Client, cc *cache.Client) (*C
func (c *Client) Type() string { func (c *Client) Type() string {
return c.pvrType return c.pvrType
} }
func (c *Client) GetFiltersHash() string {
return c.cacheFiltersHash
}

View File

@@ -30,7 +30,7 @@ func (c *Client) AddJob(feed feedItem) error {
cron: c.cron, cron: c.cron,
cache: c.cache, cache: c.cache,
cacheDuration: feed.CacheDuration, cacheDuration: feed.CacheDuration,
cacheFiltersHash: c.cacheFiltersHash, cacheFiltersHash: "",
} }
// add pvrs // add pvrs
@@ -40,6 +40,7 @@ func (c *Client) AddJob(feed feedItem) error {
return fmt.Errorf("pvr object does not exist: %v", p) return fmt.Errorf("pvr object does not exist: %v", p)
} }
job.pvrs[p] = po job.pvrs[p] = po
job.cacheFiltersHash += po.GetFiltersHash()
} }
// schedule job // schedule job

View File

@@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"github.com/l3uddz/nabarr/media" "github.com/l3uddz/nabarr/media"
"github.com/lucperkins/rek" "github.com/lucperkins/rek"
"sort"
"strings" "strings"
"time" "time"
) )
@@ -72,11 +71,6 @@ func (j *rssJob) getFeed() ([]media.FeedItem, error) {
return items, nil 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 // process feed items
for p, i := range b.Channel.Items { for p, i := range b.Channel.Items {
// ignore items // ignore items

View File

@@ -13,19 +13,17 @@ import (
type Client struct { type Client struct {
cron *cron.Cron cron *cron.Cron
cache *cache.Client cache *cache.Client
cacheFiltersHash string
pvrs map[string]pvr.PVR pvrs map[string]pvr.PVR
log zerolog.Logger 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{ return &Client{
cron: cron.New(cron.WithChain( cron: cron.New(cron.WithChain(
cron.Recover(cron.DefaultLogger), cron.Recover(cron.DefaultLogger),
)), )),
cache: cc, cache: cc,
cacheFiltersHash: cfh,
pvrs: pvrs, pvrs: pvrs,
log: logger.New(c.Verbosity).With().Logger(), log: logger.New(c.Verbosity).With().Logger(),

View File

@@ -108,3 +108,7 @@ func New(c nabarr.PvrConfig, mode string, m *media.Client, cc *cache.Client) (*C
func (c *Client) Type() string { func (c *Client) Type() string {
return c.pvrType return c.pvrType
} }
func (c *Client) GetFiltersHash() string {
return c.cacheFiltersHash
}