fix(pvr): only support v3 arrs (#30)
* fix(pvr): only support v3 apis * fix(pvr): support v3 sonarr add series
This commit is contained in:
@@ -41,7 +41,7 @@ func (c *Client) getSystemStatus() (*systemStatus, error) {
|
||||
|
||||
func (c *Client) getQualityProfileId(profileName string) (int, error) {
|
||||
// send request
|
||||
resp, err := rek.Get(util.JoinURL(c.apiURL, "profile"), rek.Client(c.http), rek.Headers(c.apiHeaders))
|
||||
resp, err := rek.Get(util.JoinURL(c.apiURL, "qualityprofile"), rek.Client(c.http), rek.Headers(c.apiHeaders))
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("request quality profiles: %w", err)
|
||||
}
|
||||
@@ -68,6 +68,35 @@ func (c *Client) getQualityProfileId(profileName string) (int, error) {
|
||||
return 0, errors.New("quality profile not found")
|
||||
}
|
||||
|
||||
func (c *Client) getLanguageProfileId(profileName string) (int, error) {
|
||||
// send request
|
||||
resp, err := rek.Get(util.JoinURL(c.apiURL, "languageprofile"), rek.Client(c.http), rek.Headers(c.apiHeaders))
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("request language profiles: %w", err)
|
||||
}
|
||||
defer resp.Body().Close()
|
||||
|
||||
// validate response
|
||||
if resp.StatusCode() != 200 {
|
||||
return 0, fmt.Errorf("validate language profiles response: %s", resp.Status())
|
||||
}
|
||||
|
||||
// decode response
|
||||
b := new([]languageProfile)
|
||||
if err := json.NewDecoder(resp.Body()).Decode(b); err != nil {
|
||||
return 0, fmt.Errorf("decode language profiles response: %w", err)
|
||||
}
|
||||
|
||||
// find quality profile
|
||||
for _, profile := range *b {
|
||||
if strings.EqualFold(profile.Name, profileName) {
|
||||
return profile.Id, nil
|
||||
}
|
||||
}
|
||||
|
||||
return 0, errors.New("language language not found")
|
||||
}
|
||||
|
||||
func (c *Client) lookupMediaItem(item *media.Item) (*lookupRequest, error) {
|
||||
// retrieve and validate media provider data
|
||||
mdp, mdi := item.GetProviderData()
|
||||
@@ -124,14 +153,15 @@ func (c *Client) AddMediaItem(item *media.Item, opts ...nabarr.PvrOption) error
|
||||
}
|
||||
|
||||
req := addRequest{
|
||||
Title: item.Title,
|
||||
TitleSlug: item.Slug,
|
||||
Year: item.Year,
|
||||
QualityProfileId: c.qualityProfileId,
|
||||
Images: []string{},
|
||||
Tags: []string{},
|
||||
Monitored: o.AddMonitored,
|
||||
RootFolderPath: c.rootFolder,
|
||||
Title: item.Title,
|
||||
TitleSlug: item.Slug,
|
||||
Year: item.Year,
|
||||
QualityProfileId: c.qualityProfileId,
|
||||
LanguageProfileId: c.languageProfileId,
|
||||
Images: []string{},
|
||||
Tags: []string{},
|
||||
Monitored: o.AddMonitored,
|
||||
RootFolderPath: c.rootFolder,
|
||||
AddOptions: addOptions{
|
||||
SearchForMissingEpisodes: o.SearchMissing,
|
||||
IgnoreEpisodesWithFiles: false,
|
||||
|
||||
@@ -192,7 +192,7 @@ func (c *Client) queueProcessor(tail state.ShutdownTail) {
|
||||
mediaItem.Slug = s.TitleSlug
|
||||
}
|
||||
|
||||
if c.testMode {
|
||||
if c.testMode && !c.testModeAdd {
|
||||
c.log.Info().
|
||||
Str("trakt_title", mediaItem.Title).
|
||||
Str("trakt_tvdb_id", mediaItem.TvdbId).
|
||||
|
||||
@@ -14,12 +14,14 @@ import (
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
pvrType string
|
||||
name string
|
||||
testMode bool
|
||||
pvrType string
|
||||
name string
|
||||
testMode bool
|
||||
testModeAdd bool
|
||||
|
||||
rootFolder string
|
||||
qualityProfileId int
|
||||
rootFolder string
|
||||
qualityProfileId int
|
||||
languageProfileId int
|
||||
|
||||
// options
|
||||
searchMissing bool
|
||||
@@ -57,7 +59,7 @@ func New(c nabarr.PvrConfig, mode string, m *media.Client, cc *cache.Client) (*C
|
||||
if strings.Contains(strings.ToLower(c.URL), "/api") {
|
||||
apiURL = c.URL
|
||||
} else {
|
||||
apiURL = util.JoinURL(c.URL, "api")
|
||||
apiURL = util.JoinURL(c.URL, "api", "v3")
|
||||
}
|
||||
|
||||
// set api headers
|
||||
@@ -67,9 +69,10 @@ func New(c nabarr.PvrConfig, mode string, m *media.Client, cc *cache.Client) (*C
|
||||
|
||||
// create client
|
||||
cl := &Client{
|
||||
pvrType: "sonarr",
|
||||
name: strings.ToLower(c.Name),
|
||||
testMode: strings.EqualFold(mode, "test"),
|
||||
pvrType: "sonarr",
|
||||
name: strings.ToLower(c.Name),
|
||||
testMode: util.StringSliceContains([]string{"test", "test-add"}, mode),
|
||||
testModeAdd: strings.EqualFold(mode, "test-add"),
|
||||
|
||||
rootFolder: c.RootFolder,
|
||||
|
||||
@@ -109,6 +112,13 @@ func New(c nabarr.PvrConfig, mode string, m *media.Client, cc *cache.Client) (*C
|
||||
cl.qualityProfileId = qid
|
||||
}
|
||||
|
||||
// get language profile
|
||||
if lid, err := cl.getLanguageProfileId(c.LanguageProfile); err != nil {
|
||||
return nil, fmt.Errorf("get language profile: %v: %w", c.LanguageProfile, err)
|
||||
} else {
|
||||
cl.languageProfileId = lid
|
||||
}
|
||||
|
||||
cl.log.Info().
|
||||
Str("pvr_version", ss.Version).
|
||||
Msg("Initialised")
|
||||
|
||||
@@ -9,6 +9,11 @@ type qualityProfile struct {
|
||||
Id int
|
||||
}
|
||||
|
||||
type languageProfile struct {
|
||||
Name string
|
||||
Id int
|
||||
}
|
||||
|
||||
type lookupRequest struct {
|
||||
Id int `json:"id,omitempty"`
|
||||
Title string `json:"title"`
|
||||
@@ -19,19 +24,20 @@ type lookupRequest struct {
|
||||
}
|
||||
|
||||
type addRequest struct {
|
||||
Title string `json:"title"`
|
||||
TitleSlug string `json:"titleSlug"`
|
||||
Year int `json:"year"`
|
||||
QualityProfileId int `json:"qualityProfileId"`
|
||||
Images []string `json:"images"`
|
||||
Tags []string `json:"tags"`
|
||||
Monitored bool `json:"monitored"`
|
||||
RootFolderPath string `json:"rootFolderPath"`
|
||||
AddOptions addOptions `json:"addOptions"`
|
||||
Seasons []string `json:"seasons"`
|
||||
SeriesType string `json:"seriesType"`
|
||||
SeasonFolder bool `json:"seasonFolder"`
|
||||
TvdbId int `json:"tvdbId"`
|
||||
Title string `json:"title"`
|
||||
TitleSlug string `json:"titleSlug"`
|
||||
Year int `json:"year"`
|
||||
QualityProfileId int `json:"qualityProfileId"`
|
||||
LanguageProfileId int `json:"languageProfileId"`
|
||||
Images []string `json:"images"`
|
||||
Tags []string `json:"tags"`
|
||||
Monitored bool `json:"monitored"`
|
||||
RootFolderPath string `json:"rootFolderPath"`
|
||||
AddOptions addOptions `json:"addOptions"`
|
||||
Seasons []string `json:"seasons"`
|
||||
SeriesType string `json:"seriesType"`
|
||||
SeasonFolder bool `json:"seasonFolder"`
|
||||
TvdbId int `json:"tvdbId"`
|
||||
}
|
||||
|
||||
type addOptions struct {
|
||||
|
||||
Reference in New Issue
Block a user