media: support rss movie items with tmdb ids (#22)
This commit is contained in:
@@ -69,19 +69,15 @@ func (c *Client) getQualityProfileId(profileName string) (int, error) {
|
||||
}
|
||||
|
||||
func (c *Client) lookupMediaItem(item *media.Item) (*lookupRequest, error) {
|
||||
// determine metadata id to use
|
||||
mdType := "imdb"
|
||||
mdId := item.ImdbId
|
||||
|
||||
if item.TmdbId != "" && item.TmdbId != "0" {
|
||||
// radarr prefers tmdb
|
||||
mdType = "tmdb"
|
||||
mdId = item.TmdbId
|
||||
// retrieve and validate media provider data
|
||||
mdp, mdi := item.GetProviderData()
|
||||
if mdp == "" || mdi == "" {
|
||||
return nil, fmt.Errorf("no media provider details found")
|
||||
}
|
||||
|
||||
// prepare request
|
||||
reqUrl, err := util.URLWithQuery(util.JoinURL(c.apiURL, "movie", "lookup"),
|
||||
url.Values{"term": []string{fmt.Sprintf("%s:%s", mdType, mdId)}})
|
||||
url.Values{"term": []string{fmt.Sprintf("%s:%s", mdp, mdi)}})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("generate movie lookup request url: %w", err)
|
||||
}
|
||||
@@ -106,19 +102,19 @@ func (c *Client) lookupMediaItem(item *media.Item) (*lookupRequest, error) {
|
||||
|
||||
// find movie
|
||||
for _, s := range *b {
|
||||
switch mdType {
|
||||
switch mdp {
|
||||
case "tmdb":
|
||||
if strconv.Itoa(s.TmdbId) == item.TmdbId {
|
||||
if strconv.Itoa(s.TmdbId) == mdi {
|
||||
return &s, nil
|
||||
}
|
||||
default:
|
||||
if s.ImdbId == item.ImdbId {
|
||||
if s.ImdbId == mdi {
|
||||
return &s, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("movie lookup %sId: %v: %w", mdType, mdId, ErrItemNotFound)
|
||||
return nil, fmt.Errorf("movie lookup %sId: %v: %w", mdp, mdi, ErrItemNotFound)
|
||||
}
|
||||
|
||||
func (c *Client) AddMediaItem(item *media.Item, opts ...nabarr.PvrOption) error {
|
||||
|
||||
@@ -32,17 +32,18 @@ func (c *Client) queueProcessor(tail state.ShutdownTail) {
|
||||
return
|
||||
}
|
||||
|
||||
// validate item has required id(s)
|
||||
if feedItem.ImdbId == "" {
|
||||
// retrieve and validate media provider data
|
||||
mdp, mdi := feedItem.GetProviderData()
|
||||
if mdp == "" || mdi == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
// check cache / add item to cache
|
||||
pvrCacheBucket := fmt.Sprintf("pvr_%s_%s", c.Type(), c.name)
|
||||
cacheKey := fmt.Sprintf("imdb_%s", feedItem.ImdbId)
|
||||
cacheBucket := fmt.Sprintf("pvr_%s_%s", c.Type(), c.name)
|
||||
cacheKey := fmt.Sprintf("%s_%s", mdp, mdi)
|
||||
if !c.testMode {
|
||||
// not running in test mode, so use cache
|
||||
if cacheValue, err := c.cache.Get(pvrCacheBucket, cacheKey); err == nil {
|
||||
if cacheValue, err := c.cache.Get(cacheBucket, cacheKey); err == nil {
|
||||
// item already exists in the cache
|
||||
switch string(cacheValue) {
|
||||
case c.name:
|
||||
@@ -55,7 +56,7 @@ func (c *Client) queueProcessor(tail state.ShutdownTail) {
|
||||
}
|
||||
|
||||
// insert temp cache entry
|
||||
if err := c.cache.Put(pvrCacheBucket, cacheKey, []byte(c.cacheFiltersHash), c.cacheTempDuration); err != nil {
|
||||
if err := c.cache.Put(cacheBucket, cacheKey, []byte(c.cacheFiltersHash), c.cacheTempDuration); err != nil {
|
||||
c.log.Error().
|
||||
Err(err).
|
||||
Msg("Failed storing item in temp cache")
|
||||
@@ -69,7 +70,7 @@ func (c *Client) queueProcessor(tail state.ShutdownTail) {
|
||||
c.log.Debug().
|
||||
Err(err).
|
||||
Str("feed_title", feedItem.Title).
|
||||
Str("feed_imdb_id", feedItem.ImdbId).
|
||||
Str(fmt.Sprintf("feed_%s_id", mdp), mdi).
|
||||
Str("feed_name", feedItem.Feed).
|
||||
Msg("Item was not found on trakt")
|
||||
continue
|
||||
@@ -78,7 +79,7 @@ func (c *Client) queueProcessor(tail state.ShutdownTail) {
|
||||
c.log.Error().
|
||||
Err(err).
|
||||
Str("feed_title", feedItem.Title).
|
||||
Str("feed_imdb_id", feedItem.ImdbId).
|
||||
Str(fmt.Sprintf("feed_%s_id", mdp), mdi).
|
||||
Str("feed_name", feedItem.Feed).
|
||||
Msg("Failed finding item on trakt")
|
||||
continue
|
||||
@@ -90,11 +91,11 @@ func (c *Client) queueProcessor(tail state.ShutdownTail) {
|
||||
Msg("Item found on trakt")
|
||||
}
|
||||
|
||||
// validate tmdbId was found
|
||||
// validate tmdbId was found (radarr works best with these)
|
||||
if mediaItem.TmdbId == "" || mediaItem.TmdbId == "0" {
|
||||
c.log.Warn().
|
||||
Str("feed_title", mediaItem.FeedTitle).
|
||||
Str("feed_imdb_id", feedItem.ImdbId).
|
||||
Str(fmt.Sprintf("feed_%s_id", mdp), mdi).
|
||||
Str("feed_name", feedItem.Feed).
|
||||
Msg("Item had no tmdbId on trakt")
|
||||
continue
|
||||
@@ -133,7 +134,7 @@ func (c *Client) queueProcessor(tail state.ShutdownTail) {
|
||||
c.log.Warn().
|
||||
Err(err).
|
||||
Str("feed_title", mediaItem.FeedTitle).
|
||||
Str("feed_imdb_id", feedItem.ImdbId).
|
||||
Str(fmt.Sprintf("feed_%s_id", mdp), mdi).
|
||||
Str("feed_name", feedItem.Feed).
|
||||
Msg("Item was not found via pvr lookup")
|
||||
continue
|
||||
@@ -142,7 +143,7 @@ func (c *Client) queueProcessor(tail state.ShutdownTail) {
|
||||
c.log.Error().
|
||||
Err(err).
|
||||
Str("feed_title", mediaItem.FeedTitle).
|
||||
Str("feed_imdb_id", feedItem.ImdbId).
|
||||
Str(fmt.Sprintf("feed_%s_id", mdp), mdi).
|
||||
Str("feed_name", feedItem.Feed).
|
||||
Msg("Failed finding item via pvr lookup")
|
||||
continue
|
||||
@@ -160,7 +161,7 @@ func (c *Client) queueProcessor(tail state.ShutdownTail) {
|
||||
|
||||
// add item to perm cache (items already in pvr)
|
||||
if !c.testMode {
|
||||
if err := c.cache.Put(pvrCacheBucket, cacheKey, []byte(c.name), 0); err != nil {
|
||||
if err := c.cache.Put(cacheBucket, cacheKey, []byte(c.name), 0); err != nil {
|
||||
c.log.Error().
|
||||
Err(err).
|
||||
Msg("Failed storing item in perm cache")
|
||||
@@ -215,7 +216,7 @@ func (c *Client) queueProcessor(tail state.ShutdownTail) {
|
||||
|
||||
// add item to perm cache (item was added to pvr)
|
||||
if !c.testMode {
|
||||
if err := c.cache.Put(pvrCacheBucket, cacheKey, []byte(c.name), 0); err != nil {
|
||||
if err := c.cache.Put(cacheBucket, cacheKey, []byte(c.name), 0); err != nil {
|
||||
c.log.Error().
|
||||
Err(err).
|
||||
Msg("Failed storing item in perm cache")
|
||||
|
||||
Reference in New Issue
Block a user