misc: rss and media changes (#27)

* refactor: tweak rss processing

* media: override trakt network with tvdb network if trakts is empty

* media: dont merge tvdb language with trakt language

* media: resolve issue with imdb ids
This commit is contained in:
l3uddz
2021-03-05 22:35:16 +00:00
committed by GitHub
parent c3ab8eda6e
commit 5091d78acf
8 changed files with 64 additions and 9 deletions

View File

@@ -4,7 +4,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"github.com/l3uddz/nabarr/media/trakt" "github.com/l3uddz/nabarr/media/trakt"
"github.com/l3uddz/nabarr/util"
"strconv" "strconv"
) )
@@ -64,7 +63,11 @@ func (c *Client) GetShowInfo(item *FeedItem) (*Item, error) {
Msg("Item was not found on tvdb") Msg("Item was not found on tvdb")
} else if ti != nil { } else if ti != nil {
mi.Tvdb = *ti mi.Tvdb = *ti
mi.Languages = util.StringSliceMergeUnique(mi.Languages, []string{ti.Language})
// merge with trakt data
if mi.Network == "" {
mi.Network = ti.Network
}
} }
return mi, nil return mi, nil

View File

@@ -4,7 +4,9 @@ import (
"encoding/xml" "encoding/xml"
"github.com/l3uddz/nabarr/media/omdb" "github.com/l3uddz/nabarr/media/omdb"
"github.com/l3uddz/nabarr/media/tvdb" "github.com/l3uddz/nabarr/media/tvdb"
"github.com/l3uddz/nabarr/util"
"github.com/pkg/errors" "github.com/pkg/errors"
"strings"
"time" "time"
) )
@@ -80,11 +82,11 @@ type FeedItem struct {
func (f *FeedItem) GetProviderData() (string, string) { func (f *FeedItem) GetProviderData() (string, string) {
switch { switch {
case f.TvdbId != "" && f.TvdbId != "0": case f.TvdbId != "" && !util.StringSliceContains([]string{"0", "1"}, f.TvdbId):
return "tvdb", f.TvdbId return "tvdb", f.TvdbId
case f.TmdbId != "" && f.TmdbId != "0": case f.TmdbId != "" && !util.StringSliceContains([]string{"0", "1"}, f.TmdbId):
return "tmdb", f.TmdbId return "tmdb", f.TmdbId
case f.ImdbId != "": case f.ImdbId != "" && strings.HasPrefix(f.ImdbId, "tt"):
return "imdb", f.ImdbId return "imdb", f.ImdbId
} }
return "", "" return "", ""

View File

@@ -46,6 +46,7 @@ func (c *Client) GetItem(tvdbId string) (*Item, error) {
return &Item{ return &Item{
Runtime: util.Atoi(b.Data.Runtime, 0), Runtime: util.Atoi(b.Data.Runtime, 0),
Language: b.Data.Language, Language: b.Data.Language,
Network: b.Data.Network,
Genre: b.Data.Genre, Genre: b.Data.Genre,
AirsDayOfWeek: b.Data.AirsDayOfWeek, AirsDayOfWeek: b.Data.AirsDayOfWeek,
SiteRating: b.Data.SiteRating, SiteRating: b.Data.SiteRating,

View File

@@ -35,6 +35,7 @@ type lookupResponse struct {
type Item struct { type Item struct {
Runtime int `json:"Runtime,omitempty"` Runtime int `json:"Runtime,omitempty"`
Language string `json:"Language,omitempty"` Language string `json:"Language,omitempty"`
Network string `json:"Network,omitempty"`
Genre []string `json:"Genre,omitempty"` Genre []string `json:"Genre,omitempty"`
AirsDayOfWeek string `json:"AirsDayOfWeek,omitempty"` AirsDayOfWeek string `json:"AirsDayOfWeek,omitempty"`
SiteRating float64 `json:"SiteRating,omitempty"` SiteRating float64 `json:"SiteRating,omitempty"`

View File

@@ -26,7 +26,7 @@ func (c *Client) AddJob(feed feedItem) error {
job := &rssJob{ job := &rssJob{
name: feed.Name, name: feed.Name,
log: l, log: l,
http: util.NewRetryableHttpClient(30*time.Second, nil, &l), http: util.NewRetryableHttpClient(60*time.Second, nil, &l),
url: feed.URL, url: feed.URL,
pvrs: make(map[string]pvr.PVR, 0), pvrs: make(map[string]pvr.PVR, 0),

View File

@@ -4,6 +4,7 @@ import (
"encoding/xml" "encoding/xml"
"fmt" "fmt"
"github.com/l3uddz/nabarr/media" "github.com/l3uddz/nabarr/media"
"github.com/l3uddz/nabarr/util"
"github.com/lucperkins/rek" "github.com/lucperkins/rek"
"sort" "sort"
"strings" "strings"
@@ -113,13 +114,13 @@ func (j *rssJob) getFeed() ([]media.FeedItem, error) {
// validate item // validate item
switch { switch {
case b.Channel.Items[p].TvdbId != "" && b.Channel.Items[p].TvdbId != "0": case b.Channel.Items[p].TvdbId != "" && !util.StringSliceContains([]string{"0", "1"}, b.Channel.Items[p].TvdbId):
// tvdb id is present, allow processing // tvdb id is present, allow processing
break break
case b.Channel.Items[p].ImdbId != "": case b.Channel.Items[p].ImdbId != "" && strings.HasPrefix(b.Channel.Items[p].ImdbId, "tt"):
// imdb id present, allow processing // imdb id present, allow processing
break break
case b.Channel.Items[p].TmdbId != "" && b.Channel.Items[p].TmdbId != "0": case b.Channel.Items[p].TmdbId != "" && !util.StringSliceContains([]string{"0", "1"}, b.Channel.Items[p].TmdbId):
// tmdb id present, allow processing // tmdb id present, allow processing
break break
default: default:

View File

@@ -11,6 +11,17 @@ func StringSliceContains(slice []string, val string) bool {
return false return false
} }
func StringSliceContainsAny(slice []string, vals []string) bool {
for _, s := range slice {
for _, v := range vals {
if strings.EqualFold(s, v) {
return true
}
}
}
return false
}
func StringSliceMergeUnique(existingSlice []string, mergeSlice []string) []string { func StringSliceMergeUnique(existingSlice []string, mergeSlice []string) []string {
// add existing // add existing
data := make([]string, 0) data := make([]string, 0)

View File

@@ -92,3 +92,39 @@ func TestStringSliceMergeUnique(t *testing.T) {
}) })
} }
} }
func TestStringSliceContainsAny(t *testing.T) {
type args struct {
slice []string
vals []string
}
tests := []struct {
name string
args args
want bool
}{
{
name: "expect true",
args: args{
slice: []string{"tes", "Test"},
vals: []string{"nope", "test"},
},
want: true,
},
{
name: "expect false",
args: args{
slice: []string{"tes", "Test"},
vals: []string{"testing"},
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := StringSliceContainsAny(tt.args.slice, tt.args.vals); got != tt.want {
t.Errorf("StringSliceContainsAny() = %v, want %v", got, tt.want)
}
})
}
}