Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prowlarr Search and Sonarr Release methods #163

Merged
merged 5 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion debuglog/roundtripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (f *fakeCloser) logRequest() (int, int) {
sent = sent[:f.MaxBody] + " <data truncated>"
}

switch ctype := f.Header.Get("content-type"); {
switch ctype := f.Header.Get("Content-Type"); {
case !strings.Contains(ctype, "json"):
// We only log JSON. Need something else? Ask!
rcvd = "<data not logged, content-type: " + ctype + ">"
Expand Down
2 changes: 1 addition & 1 deletion http.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (c *Config) SetHeaders(req *http.Request) {
}

req.Header.Set("User-Agent", "go-starr: https://"+reflect.TypeOf(Config{}).PkgPath()) //nolint:exhaustivestruct
req.Header.Set("X-API-Key", c.APIKey)
req.Header.Set("X-Api-Key", c.APIKey)
}

// SetAPIPath makes sure the path starts with /api.
Expand Down
2 changes: 1 addition & 1 deletion interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (c *Config) Login(ctx context.Context) error {

closeResp(resp)

if u, _ := url.Parse(c.URL); strings.Contains(codeErr.Get("location"), "loginFailed") ||
if u, _ := url.Parse(c.URL); strings.Contains(codeErr.Get("Location"), "loginFailed") ||
len(c.Client.Jar.Cookies(u)) == 0 {
return fmt.Errorf("%w: authenticating as user '%s' failed", ErrRequestError, c.Username)
}
Expand Down
2 changes: 1 addition & 1 deletion lidarr/blocklist.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type BlockListRecord struct {
ArtistID int64 `json:"artistId"`
Date time.Time `json:"date"`
SourceTitle string `json:"sourceTitle"`
Protocol string `json:"protocol"`
Protocol starr.Protocol `json:"protocol"`
Indexer string `json:"indexer"`
Message string `json:"message"`
}
Expand Down
4 changes: 2 additions & 2 deletions lidarr/downloadclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type DownloadClientInput struct {
ConfigContract string `json:"configContract"`
Implementation string `json:"implementation"`
Name string `json:"name"`
Protocol string `json:"protocol"`
Protocol starr.Protocol `json:"protocol"`
Tags []int `json:"tags"`
Fields []*starr.FieldInput `json:"fields"`
}
Expand All @@ -41,7 +41,7 @@ type DownloadClientOutput struct {
ImplementationName string `json:"implementationName"`
InfoLink string `json:"infoLink"`
Name string `json:"name"`
Protocol string `json:"protocol"`
Protocol starr.Protocol `json:"protocol"`
Tags []int `json:"tags"`
Fields []*starr.FieldOutput `json:"fields"`
}
Expand Down
38 changes: 19 additions & 19 deletions lidarr/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,25 @@ type HistoryRecord struct {
DownloadID string `json:"downloadId"`
EventType string `json:"eventType"`
Data struct {
Age string `json:"age"`
AgeHours string `json:"ageHours"`
AgeMinutes string `json:"ageMinutes"`
DownloadClient string `json:"downloadClient"`
DownloadForced string `json:"downloadForced"`
DownloadURL string `json:"downloadUrl"`
DroppedPath string `json:"droppedPath"`
GUID string `json:"guid"`
ImportedPath string `json:"importedPath"`
Indexer string `json:"indexer"`
Message string `json:"message"`
NzbInfoURL string `json:"nzbInfoUrl"`
Protocol string `json:"protocol"`
PublishedDate time.Time `json:"publishedDate"`
Reason string `json:"reason"`
ReleaseGroup string `json:"releaseGroup"`
Size string `json:"size"`
StatusMessages string `json:"statusMessages"`
TorrentInfoHash string `json:"torrentInfoHash"`
Age string `json:"age"`
AgeHours string `json:"ageHours"`
AgeMinutes string `json:"ageMinutes"`
DownloadClient string `json:"downloadClient"`
DownloadForced string `json:"downloadForced"`
DownloadURL string `json:"downloadUrl"`
DroppedPath string `json:"droppedPath"`
GUID string `json:"guid"`
ImportedPath string `json:"importedPath"`
Indexer string `json:"indexer"`
Message string `json:"message"`
NzbInfoURL string `json:"nzbInfoUrl"`
Protocol starr.Protocol `json:"protocol"`
PublishedDate time.Time `json:"publishedDate"`
Reason string `json:"reason"`
ReleaseGroup string `json:"releaseGroup"`
Size string `json:"size"`
StatusMessages string `json:"statusMessages"`
TorrentInfoHash string `json:"torrentInfoHash"`
} `json:"data"`
}

Expand Down
4 changes: 2 additions & 2 deletions lidarr/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type IndexerInput struct {
ConfigContract string `json:"configContract"`
Implementation string `json:"implementation"`
Name string `json:"name"`
Protocol string `json:"protocol"`
Protocol starr.Protocol `json:"protocol"`
Tags []int `json:"tags"`
Fields []*starr.FieldInput `json:"fields"`
}
Expand All @@ -42,7 +42,7 @@ type IndexerOutput struct {
ImplementationName string `json:"implementationName"`
InfoLink string `json:"infoLink"`
Name string `json:"name"`
Protocol string `json:"protocol"`
Protocol starr.Protocol `json:"protocol"`
Tags []int `json:"tags"`
Fields []*starr.FieldOutput `json:"fields"`
}
Expand Down
2 changes: 1 addition & 1 deletion lidarr/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type QueueRecord struct {
TrackedDownloadStatus string `json:"trackedDownloadStatus"`
StatusMessages []*starr.StatusMessage `json:"statusMessages"`
DownloadID string `json:"downloadId"`
Protocol string `json:"protocol"`
Protocol starr.Protocol `json:"protocol"`
DownloadClient string `json:"downloadClient"`
Indexer string `json:"indexer"`
OutputPath string `json:"outputPath"`
Expand Down
4 changes: 2 additions & 2 deletions prowlarr/downloadclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type DownloadClientInput struct {
ConfigContract string `json:"configContract"`
Implementation string `json:"implementation"`
Name string `json:"name"`
Protocol string `json:"protocol"`
Protocol starr.Protocol `json:"protocol"`
Tags []int `json:"tags"`
Fields []*starr.FieldInput `json:"fields"`
}
Expand All @@ -37,7 +37,7 @@ type DownloadClientOutput struct {
ImplementationName string `json:"implementationName"`
InfoLink string `json:"infoLink"`
Name string `json:"name"`
Protocol string `json:"protocol"`
Protocol starr.Protocol `json:"protocol"`
Tags []int `json:"tags"`
Fields []*starr.FieldOutput `json:"fields"`
}
Expand Down
4 changes: 2 additions & 2 deletions prowlarr/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type IndexerInput struct {
ConfigContract string `json:"configContract"`
Implementation string `json:"implementation"`
Name string `json:"name"`
Protocol string `json:"protocol"`
Protocol starr.Protocol `json:"protocol"`
Tags []int `json:"tags,omitempty"`
Fields []*starr.FieldInput `json:"fields"`
}
Expand All @@ -41,7 +41,7 @@ type IndexerOutput struct {
Priority int64 `json:"priority"`
SortName string `json:"sortName"`
Name string `json:"name"`
Protocol string `json:"protocol"`
Protocol starr.Protocol `json:"protocol"`
Privacy string `json:"privacy"`
DefinitionName string `json:"definitionName"`
Description string `json:"description"`
Expand Down
102 changes: 102 additions & 0 deletions prowlarr/search.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package prowlarr

import (
"context"
"fmt"
"net/url"
"time"

"golift.io/starr"
)

const bpSearch = APIver + "/search"

// Search is the output from the Prowlarr search endpoint.
type Search struct {
GUID string `json:"guid"`
Age int64 `json:"age"`
AgeHours float64 `json:"ageHours"`
AgeMinutes float64 `json:"ageMinutes"`
Size int64 `json:"size"`
Files int `json:"files"`
Grabs int `json:"grabs"`
IndexerID int64 `json:"indexerId"`
Indexer string `json:"indexer"`
Title string `json:"title"`
SortTitle string `json:"sortTitle"`
ImdbID int64 `json:"imdbId"`
TmdbID int64 `json:"tmdbId"`
TvdbID int64 `json:"tvdbId"`
TvMazeID int64 `json:"tvMazeId"`
PublishDate time.Time `json:"publishDate"`
CommentURL string `json:"commentUrl"`
DownloadURL string `json:"downloadUrl"`
InfoURL string `json:"infoUrl"`
IndexerFlags []string `json:"indexerFlags"`
Categories []*Category `json:"categories"`
Protocol starr.Protocol `json:"protocol"`
FileName string `json:"fileName"`
InfoHash string `json:"infoHash"`
Seeders int `json:"seeders"`
Leechers int `json:"leechers"`
}

// Category is part of the Search output.
type Category struct {
ID int64 `json:"id"`
Name string `json:"name"`
SubCategories []*Category `json:"subCategories"`
}

// SearchInput is the input to the search endpoint.
type SearchInput struct {
Query string `json:"query"` // Query is required. Fill it in.
Type string `json:"type"` // defaults to "search" if left empty
IndexerIDs []int64 `json:"indexerIds"`
Categories []int64 `json:"categories"`
Limit int `json:"limit"` // Defaults to 100 if left empty or less than 1.
Offset int `json:"offset"` // Skip this many records.
}

// Search the Prowlarr indexers for media and content. Must provide a Query in the SearchInput.
func (p *Prowlarr) Search(search SearchInput) ([]*Search, error) {
return p.SearchContext(context.Background(), search)
}

// SearchContext searches the Prowlarr indexers for media and content.
func (p *Prowlarr) SearchContext(ctx context.Context, search SearchInput) ([]*Search, error) {
const defaultSearchLimit = 100

if search.Type == "" {
search.Type = "search"
}

if search.Limit < 1 {
search.Limit = defaultSearchLimit
}

if search.Limit < 0 {
search.Limit = 0
}

req := starr.Request{URI: bpSearch, Query: make(url.Values)}
req.Query.Set("query", search.Query)
req.Query.Set("type", search.Type)
req.Query.Set("limit", starr.Itoa(int64(search.Limit)))
req.Query.Set("offset", starr.Itoa(int64(search.Offset)))

for _, val := range search.Categories {
req.Query.Add("categories", starr.Itoa(val))
}

for _, val := range search.IndexerIDs {
req.Query.Add("indexerIds", starr.Itoa(val))
}

var output []*Search
if err := p.GetInto(ctx, req, &output); err != nil {
return nil, fmt.Errorf("api.Get(%s): %w", &req, err)
}

return output, nil
}
2 changes: 1 addition & 1 deletion radarr/blocklist.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type BlockListRecord struct {
ID int64 `json:"id"`
Date time.Time `json:"date"`
SourceTitle string `json:"sourceTitle"`
Protocol string `json:"protocol"`
Protocol starr.Protocol `json:"protocol"`
Indexer string `json:"indexer"`
Message string `json:"message"`
}
Expand Down
18 changes: 9 additions & 9 deletions radarr/delayprofile.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ const bpDelayProfile = APIver + "/delayProfile"

// DelayProfile is the /api/v3/delayprofile endpoint.
type DelayProfile struct {
EnableUsenet bool `json:"enableUsenet,omitempty"`
EnableTorrent bool `json:"enableTorrent,omitempty"`
BypassIfHighestQuality bool `json:"bypassIfHighestQuality,omitempty"`
UsenetDelay int64 `json:"usenetDelay,omitempty"`
TorrentDelay int64 `json:"torrentDelay,omitempty"`
ID int64 `json:"id,omitempty"`
Order int64 `json:"order,omitempty"`
Tags []int `json:"tags"`
PreferredProtocol string `json:"preferredProtocol,omitempty"`
EnableUsenet bool `json:"enableUsenet,omitempty"`
EnableTorrent bool `json:"enableTorrent,omitempty"`
BypassIfHighestQuality bool `json:"bypassIfHighestQuality,omitempty"`
UsenetDelay int64 `json:"usenetDelay,omitempty"`
TorrentDelay int64 `json:"torrentDelay,omitempty"`
ID int64 `json:"id,omitempty"`
Order int64 `json:"order,omitempty"`
Tags []int `json:"tags"`
PreferredProtocol starr.Protocol `json:"preferredProtocol,omitempty"`
}

// GetDelayProfiles returns all configured delay profiles.
Expand Down
4 changes: 2 additions & 2 deletions radarr/downloadclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type DownloadClientInput struct {
ConfigContract string `json:"configContract"`
Implementation string `json:"implementation"`
Name string `json:"name"`
Protocol string `json:"protocol"`
Protocol starr.Protocol `json:"protocol"`
Tags []int `json:"tags"`
Fields []*starr.FieldInput `json:"fields"`
}
Expand All @@ -41,7 +41,7 @@ type DownloadClientOutput struct {
ImplementationName string `json:"implementationName"`
InfoLink string `json:"infoLink"`
Name string `json:"name"`
Protocol string `json:"protocol"`
Protocol starr.Protocol `json:"protocol"`
Tags []int `json:"tags"`
Fields []*starr.FieldOutput `json:"fields"`
}
Expand Down
44 changes: 22 additions & 22 deletions radarr/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,28 @@ type HistoryRecord struct {
DownloadID string `json:"downloadId"`
EventType string `json:"eventType"`
Data struct {
Age string `json:"age"`
AgeHours string `json:"ageHours"`
AgeMinutes string `json:"ageMinutes"`
DownloadClient string `json:"downloadClient"`
DownloadClientName string `json:"downloadClientName"`
DownloadURL string `json:"downloadUrl"`
DroppedPath string `json:"droppedPath"`
FileID string `json:"fileId"`
GUID string `json:"guid"`
ImportedPath string `json:"importedPath"`
Indexer string `json:"indexer"`
IndexerFlags string `json:"indexerFlags"`
IndexerID string `json:"indexerId"`
Message string `json:"message"`
NzbInfoURL string `json:"nzbInfoUrl"`
Protocol string `json:"protocol"`
PublishedDate time.Time `json:"publishedDate"`
Reason string `json:"reason"`
ReleaseGroup string `json:"releaseGroup"`
Size string `json:"size"`
TmdbID string `json:"tmdbId"`
TorrentInfoHash string `json:"torrentInfoHash"`
Age string `json:"age"`
AgeHours string `json:"ageHours"`
AgeMinutes string `json:"ageMinutes"`
DownloadClient string `json:"downloadClient"`
DownloadClientName string `json:"downloadClientName"`
DownloadURL string `json:"downloadUrl"`
DroppedPath string `json:"droppedPath"`
FileID string `json:"fileId"`
GUID string `json:"guid"`
ImportedPath string `json:"importedPath"`
Indexer string `json:"indexer"`
IndexerFlags string `json:"indexerFlags"`
IndexerID string `json:"indexerId"`
Message string `json:"message"`
NzbInfoURL string `json:"nzbInfoUrl"`
Protocol starr.Protocol `json:"protocol"`
PublishedDate time.Time `json:"publishedDate"`
Reason string `json:"reason"`
ReleaseGroup string `json:"releaseGroup"`
Size string `json:"size"`
TmdbID string `json:"tmdbId"`
TorrentInfoHash string `json:"torrentInfoHash"`
} `json:"data"`
}

Expand Down
4 changes: 2 additions & 2 deletions radarr/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type IndexerInput struct {
ConfigContract string `json:"configContract"`
Implementation string `json:"implementation"`
Name string `json:"name"`
Protocol string `json:"protocol"`
Protocol starr.Protocol `json:"protocol"`
Tags []int `json:"tags"`
Fields []*starr.FieldInput `json:"fields"`
}
Expand All @@ -44,7 +44,7 @@ type IndexerOutput struct {
ImplementationName string `json:"implementationName"`
InfoLink string `json:"infoLink"`
Name string `json:"name"`
Protocol string `json:"protocol"`
Protocol starr.Protocol `json:"protocol"`
Tags []int `json:"tags"`
Fields []*starr.FieldOutput `json:"fields"`
}
Expand Down
2 changes: 1 addition & 1 deletion radarr/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type QueueRecord struct {
TrackedDownloadState string `json:"trackedDownloadState"`
StatusMessages []*starr.StatusMessage `json:"statusMessages"`
DownloadID string `json:"downloadId"`
Protocol string `json:"protocol"`
Protocol starr.Protocol `json:"protocol"`
DownloadClient string `json:"downloadClient"`
Indexer string `json:"indexer"`
OutputPath string `json:"outputPath"`
Expand Down
Loading
Loading