feat: respect pvr exclusions (#37)
This commit is contained in:
@@ -8,10 +8,11 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/lucperkins/rek"
|
||||
|
||||
"github.com/l3uddz/nabarr"
|
||||
"github.com/l3uddz/nabarr/media"
|
||||
"github.com/l3uddz/nabarr/util"
|
||||
"github.com/lucperkins/rek"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -140,6 +141,35 @@ func (c *Client) lookupMediaItem(item *media.Item) (*lookupRequest, error) {
|
||||
return nil, fmt.Errorf("series lookup %sId: %v: %w", mdp, mdi, ErrItemNotFound)
|
||||
}
|
||||
|
||||
func (c *Client) getExclusions() (map[int]exclusion, error) {
|
||||
// send request
|
||||
resp, err := rek.Get(util.JoinURL(c.apiURL, "importlistexclusion"), rek.Client(c.http), rek.Headers(c.apiHeaders))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("request exclusions: %w", err)
|
||||
}
|
||||
defer resp.Body().Close()
|
||||
|
||||
// validate response
|
||||
if resp.StatusCode() != 200 {
|
||||
return nil, fmt.Errorf("validate exclusions response: %s", resp.Status())
|
||||
}
|
||||
|
||||
// decode response
|
||||
b := new([]exclusion)
|
||||
if err := json.NewDecoder(resp.Body()).Decode(b); err != nil {
|
||||
return nil, fmt.Errorf("decode exclusions response: %w", err)
|
||||
}
|
||||
|
||||
// generate exclusion map
|
||||
exclusions := make(map[int]exclusion)
|
||||
for n := range *b {
|
||||
e := (*b)[n]
|
||||
exclusions[e.TvdbId] = e
|
||||
}
|
||||
|
||||
return exclusions, nil
|
||||
}
|
||||
|
||||
func (c *Client) AddMediaItem(item *media.Item, opts ...nabarr.PvrOption) error {
|
||||
// prepare options
|
||||
o, err := nabarr.BuildPvrOptions(opts...)
|
||||
|
||||
@@ -4,9 +4,10 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/antonmedv/expr"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/l3uddz/nabarr"
|
||||
"github.com/l3uddz/nabarr/media"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func (c *Client) compileExpressions(filters nabarr.PvrFilters) error {
|
||||
|
||||
@@ -5,10 +5,11 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/lefelys/state"
|
||||
|
||||
"github.com/l3uddz/nabarr"
|
||||
"github.com/l3uddz/nabarr/media"
|
||||
"github.com/l3uddz/nabarr/util"
|
||||
"github.com/lefelys/state"
|
||||
)
|
||||
|
||||
func (c *Client) QueueFeedItem(item *media.FeedItem) {
|
||||
@@ -162,6 +163,26 @@ func (c *Client) queueProcessor(tail state.ShutdownTail) {
|
||||
continue
|
||||
}
|
||||
|
||||
// lookup pvr exclusions
|
||||
exclusions, err := c.getExclusions()
|
||||
if err != nil {
|
||||
c.log.Error().
|
||||
Err(err).
|
||||
Msg("Failed retrieving pvr exclusions")
|
||||
continue
|
||||
}
|
||||
|
||||
if _, ok := exclusions[s.TvdbId]; ok {
|
||||
// item was in pvr exclusions
|
||||
c.log.Debug().
|
||||
Str("pvr_title", s.Title).
|
||||
Int("pvr_year", s.Year).
|
||||
Int("pvr_tvdb_id", s.TvdbId).
|
||||
Str("feed_name", feedItem.Feed).
|
||||
Msg("Item found in pvr exclusions")
|
||||
continue
|
||||
}
|
||||
|
||||
// set appropriate series type
|
||||
switch {
|
||||
case util.StringSliceContains(mediaItem.Genres, "anime"), util.StringSliceContains(mediaItem.Tvdb.Genre, "anime"):
|
||||
|
||||
@@ -6,12 +6,13 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
|
||||
"github.com/l3uddz/nabarr"
|
||||
"github.com/l3uddz/nabarr/cache"
|
||||
"github.com/l3uddz/nabarr/logger"
|
||||
"github.com/l3uddz/nabarr/media"
|
||||
"github.com/l3uddz/nabarr/util"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
@@ -45,7 +46,7 @@ type Client struct {
|
||||
}
|
||||
|
||||
func New(c nabarr.PvrConfig, mode string, m *media.Client, cc *cache.Client) (*Client, error) {
|
||||
l := logger.New(c.Verbosity).With().
|
||||
l := logger.Child(logger.WithLevel(c.Verbosity)).With().
|
||||
Str("pvr_name", c.Name).
|
||||
Str("pvr_type", c.Type).
|
||||
Logger()
|
||||
|
||||
@@ -9,6 +9,12 @@ type qualityProfile struct {
|
||||
Id int
|
||||
}
|
||||
|
||||
type exclusion struct {
|
||||
TvdbId int `json:"tvdbId"`
|
||||
Title string `json:"title"`
|
||||
Id int `json:"id"`
|
||||
}
|
||||
|
||||
type languageProfile struct {
|
||||
Name string
|
||||
Id int
|
||||
|
||||
Reference in New Issue
Block a user