pvr: add options and support for anime (#17)
* pvr: begin adding options * pvr: add ability to configure add behaviour via config * pvr: add skip_anime * pvr: do not continue processing item if lookup failed or add to pvr failed
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/l3uddz/nabarr"
|
||||
"github.com/l3uddz/nabarr/media"
|
||||
"github.com/l3uddz/nabarr/util"
|
||||
"github.com/lucperkins/rek"
|
||||
@@ -105,7 +106,13 @@ func (c *Client) lookupMediaItem(item *media.Item) (*lookupRequest, error) {
|
||||
return nil, fmt.Errorf("series lookup tvdbId: %v: %w", item.TvdbId, ErrItemNotFound)
|
||||
}
|
||||
|
||||
func (c *Client) AddMediaItem(item *media.Item) error {
|
||||
func (c *Client) AddMediaItem(item *media.Item, opts ...nabarr.PvrOption) error {
|
||||
// prepare options
|
||||
o, err := nabarr.BuildPvrOptions(opts...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("build options: %v: %w", item.TvdbId, err)
|
||||
}
|
||||
|
||||
// prepare request
|
||||
tvdbId, err := strconv.Atoi(item.TvdbId)
|
||||
if err != nil {
|
||||
@@ -119,15 +126,15 @@ func (c *Client) AddMediaItem(item *media.Item) error {
|
||||
QualityProfileId: c.qualityProfileId,
|
||||
Images: []string{},
|
||||
Tags: []string{},
|
||||
Monitored: true,
|
||||
Monitored: o.AddMonitored,
|
||||
RootFolderPath: c.rootFolder,
|
||||
AddOptions: addOptions{
|
||||
SearchForMissingEpisodes: true,
|
||||
SearchForMissingEpisodes: o.SearchMissing,
|
||||
IgnoreEpisodesWithFiles: false,
|
||||
IgnoreEpisodesWithoutFiles: false,
|
||||
},
|
||||
Seasons: []string{},
|
||||
SeriesType: "standard",
|
||||
SeriesType: util.StringOrDefault(o.LookupType, "standard"),
|
||||
SeasonFolder: true,
|
||||
TvdbId: tvdbId,
|
||||
}
|
||||
|
||||
@@ -3,8 +3,11 @@ package sonarr
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/l3uddz/nabarr"
|
||||
"github.com/l3uddz/nabarr/media"
|
||||
"github.com/l3uddz/nabarr/util"
|
||||
"github.com/lefelys/state"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (c *Client) QueueFeedItem(item *media.FeedItem) {
|
||||
@@ -134,6 +137,7 @@ func (c *Client) queueProcessor(tail state.ShutdownTail) {
|
||||
Str("feed_tvdb_id", feedItem.TvdbId).
|
||||
Str("feed_name", feedItem.Feed).
|
||||
Msg("Failed finding item via pvr lookup")
|
||||
continue
|
||||
}
|
||||
|
||||
if s.Id > 0 {
|
||||
@@ -156,6 +160,23 @@ func (c *Client) queueProcessor(tail state.ShutdownTail) {
|
||||
continue
|
||||
}
|
||||
|
||||
// set appropriate series type
|
||||
switch {
|
||||
case util.StringSliceContains(mediaItem.Genres, "anime"), util.StringSliceContains(mediaItem.Tvdb.Genre, "anime"):
|
||||
s.Type = "anime"
|
||||
}
|
||||
|
||||
// check if item should be skipped (skip options)
|
||||
if c.skipAnime && strings.EqualFold(s.Type, "anime") {
|
||||
c.log.Debug().
|
||||
Str("trakt_title", mediaItem.Title).
|
||||
Str("trakt_tvdb_id", mediaItem.TvdbId).
|
||||
Int("trakt_year", mediaItem.Year).
|
||||
Str("feed_name", feedItem.Feed).
|
||||
Msg("Skipping item (skip_anime enabled)")
|
||||
continue
|
||||
}
|
||||
|
||||
// add item to pvr
|
||||
c.log.Debug().
|
||||
Str("feed_title", mediaItem.FeedTitle).
|
||||
@@ -172,7 +193,6 @@ func (c *Client) queueProcessor(tail state.ShutdownTail) {
|
||||
|
||||
if c.testMode {
|
||||
c.log.Info().
|
||||
Err(err).
|
||||
Str("trakt_title", mediaItem.Title).
|
||||
Str("trakt_tvdb_id", mediaItem.TvdbId).
|
||||
Int("trakt_year", mediaItem.Year).
|
||||
@@ -181,7 +201,13 @@ func (c *Client) queueProcessor(tail state.ShutdownTail) {
|
||||
continue
|
||||
}
|
||||
|
||||
if err := c.AddMediaItem(mediaItem); err != nil {
|
||||
opts := []nabarr.PvrOption{
|
||||
nabarr.WithSeriesType(s.Type),
|
||||
nabarr.WithAddMonitored(c.addMonitored),
|
||||
nabarr.WithSearchMissing(c.searchMissing),
|
||||
}
|
||||
|
||||
if err := c.AddMediaItem(mediaItem, opts...); err != nil {
|
||||
c.log.Error().
|
||||
Err(err).
|
||||
Str("feed_title", mediaItem.FeedTitle).
|
||||
@@ -190,6 +216,7 @@ func (c *Client) queueProcessor(tail state.ShutdownTail) {
|
||||
Int("trakt_year", mediaItem.Year).
|
||||
Str("feed_name", feedItem.Feed).
|
||||
Msg("Failed adding item to pvr")
|
||||
continue
|
||||
}
|
||||
|
||||
// add item to perm cache (item was added to pvr)
|
||||
@@ -202,7 +229,6 @@ func (c *Client) queueProcessor(tail state.ShutdownTail) {
|
||||
}
|
||||
|
||||
c.log.Info().
|
||||
Err(err).
|
||||
Str("trakt_title", mediaItem.Title).
|
||||
Str("trakt_tvdb_id", mediaItem.TvdbId).
|
||||
Int("trakt_year", mediaItem.Year).
|
||||
|
||||
@@ -20,6 +20,11 @@ type Client struct {
|
||||
rootFolder string
|
||||
qualityProfileId int
|
||||
|
||||
// options
|
||||
searchMissing bool
|
||||
addMonitored bool
|
||||
skipAnime bool
|
||||
|
||||
apiURL string
|
||||
apiHeaders map[string]string
|
||||
apiTimeout time.Duration
|
||||
@@ -67,6 +72,10 @@ func New(c nabarr.PvrConfig, mode string, m *media.Client, cc *cache.Client) (*C
|
||||
|
||||
rootFolder: c.RootFolder,
|
||||
|
||||
searchMissing: util.BoolOrDefault(c.Options.SearchMissing, true),
|
||||
addMonitored: util.BoolOrDefault(c.Options.AddMonitored, true),
|
||||
skipAnime: util.BoolOrDefault(c.Options.SkipAnime, true),
|
||||
|
||||
cache: cc,
|
||||
cacheTempDuration: c.CacheDuration,
|
||||
cacheFiltersHash: util.AsSHA256(c.Filters),
|
||||
|
||||
@@ -15,6 +15,7 @@ type lookupRequest struct {
|
||||
TitleSlug string `json:"titleSlug"`
|
||||
Year int `json:"year,omitempty"`
|
||||
TvdbId int `json:"tvdbId"`
|
||||
Type string `json:"seriesType"`
|
||||
}
|
||||
|
||||
type addRequest struct {
|
||||
|
||||
Reference in New Issue
Block a user