feat: respect pvr exclusions (#37)

This commit is contained in:
l3uddz
2022-04-14 16:18:06 +01:00
committed by GitHub
parent 2468d5b251
commit 79507adb4a
32 changed files with 321 additions and 99 deletions

View File

@@ -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 (
@@ -118,6 +119,35 @@ func (c *Client) lookupMediaItem(item *media.Item) (*lookupRequest, error) {
return nil, fmt.Errorf("movie 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, "exclusions"), 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.TmdbId] = e
}
return exclusions, nil
}
func (c *Client) AddMediaItem(item *media.Item, opts ...nabarr.PvrOption) error {
// prepare options
o, err := nabarr.BuildPvrOptions(opts...)

View File

@@ -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 {

View File

@@ -4,9 +4,10 @@ import (
"errors"
"fmt"
"github.com/lefelys/state"
"github.com/l3uddz/nabarr"
"github.com/l3uddz/nabarr/media"
"github.com/lefelys/state"
)
func (c *Client) QueueFeedItem(item *media.FeedItem) {
@@ -171,6 +172,27 @@ 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.TmdbId]; ok {
// item was in pvr exclusions
c.log.Debug().
Str("pvr_title", s.Title).
Int("pvr_year", s.Year).
Str("pvr_imdb_id", s.ImdbId).
Int("pvr_tmdb_id", s.TmdbId).
Str("feed_name", feedItem.Feed).
Msg("Item found in pvr exclusions")
continue
}
// add item to pvr
c.log.Debug().
Str("feed_title", mediaItem.FeedTitle).

View File

@@ -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 {
@@ -43,7 +44,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()

View File

@@ -9,6 +9,13 @@ type qualityProfile struct {
Id int
}
type exclusion struct {
TmdbId int `json:"tmdbId"`
MovieTitle string `json:"movieTitle"`
MovieYear int `json:"movieYear"`
Id int `json:"id"`
}
type lookupRequest struct {
Id int `json:"id,omitempty"`
Title string `json:"title"`