Skip to content

Ability to identify in the classifier movies and TV shows from lists in sonarr, radarr, jellyfin and TMDB discover #352

Open
@rraymondgh

Description

  • I have checked the existing issues to avoid duplicates
  • I have redacted any info hashes and content metadata from any logs or screenshots attached to this issue

Is your feature request related to a problem?

In order to use the flexibility of the classifier, the flexibility to define custom rules and workflows is invaluable. This could be further enhanced by having a plugin system that sources external lists of TMDB ids for use in classifier rules.

For example

    - if_else:
        condition:
          and:
            - "result.contentType == contentType.tv_show"
            - "result.contentSource == 'tmdb' "
            - "result.contentId in extensions.sonarr "
        if_action:
          add_tag: sonarr

would be far more flexible if extensions.sonarr list was sourced from sonarr

Describe the solution you'd like

plugin defined in classifier.yml

for example:

plugins:
  - url: http://192.168.1.202:8989/api/v3/movie?apikey=abc123
    extension: radarr
  - url: http://192.168.1.202:7878/api/v3/series?apikey=def789
    extension: sonarr

source values in classifier go code

internal/classifier/source.go

@@ -7,6 +7,7 @@ type Source struct {
        Flags           Flags           `json:"flags"`
        Keywords        keywordGroups   `json:"keywords"`
        Extensions      extensionGroups `json:"extensions"`
+       Plugins         pluginGroups    `json:"plugins,omitempty"`
 }
 
 func (s Source) merge(other Source) (Source, error) {
@@ -20,6 +21,7 @@ func (s Source) merge(other Source) (Source, error) {
                Keywords:        s.Keywords.merge(other.Keywords),
                Extensions:      s.Extensions.merge(other.Extensions),
                Workflows:       s.Workflows.merge(other.Workflows),
+               Plugins:         s.Plugins.merge(other.Plugins),
        }, nil
 }
 
@@ -81,3 +83,19 @@ func (s workflowSources) merge(other workflowSources) workflowSources {
        }
        return result
 }
+
+type pluginGroups []struct {
+       Url       string `json:"url"`
+       Extension string `json:"extension"`
+}
+
+func (s pluginGroups) merge(other pluginGroups) pluginGroups {
+       var result pluginGroups
+       for _, v := range s {
+               result = append(result, v)
+       }
+       for _, v := range other {
+               result = append(result, v)
+       }
+       return result
+}

internal/classifier/source_provider.go

 func newSourceProvider(config Config, tmdbConfig tmdb.Config) sourceProvider {
@@ -42,6 +43,14 @@ func (m mergeSourceProvider) source() (Source, error) {
                        source = merged
                }
        }
+       for _, plugin := range source.Plugins {
+               err, data := extensionPlugin{url: plugin.Url}.source()
+               if err != nil {
+                       return source, err
+               }
+               source.Extensions[plugin.Extension] = data
+       }
+
        return source, nil
 }

internal/classifier/extension_plugins.go

package classifier

import (
	"strconv"

	"github.com/go-resty/resty/v2"
)

type servarrContent []struct {
	TmdbId int `json:"tmdbId"`
}

func (l servarrContent) TmdbIds() []string {
	var list []string
	for _, item := range l {
		if item.TmdbId > 0 {
			list = append(list, strconv.Itoa(item.TmdbId))
		}
	}

	return list
}

type extensionPlugin struct {
	url string
}

func (p extensionPlugin) source() (error, []string) {
	client := resty.New()
	var r servarrContent
	_, err := client.R().
		SetResult(&r).
		Get(p.url)
	if err != nil {
		return err, nil
	}

	return nil, r.TmdbIds()
}

Describe alternatives you've considered

No change to bitmagnet, have completely separate utility that generates classifier.yml. This works but is not integrated

Additional context

Feed back wanted - happy to change and submit a PR. Already have a working solution within my build. Concept could potentially work for any plugin list. However concept code in this issue at moment is limited to TMDB Ids sourced from radarr or sonarr.

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions