From 2b93bfdcf54b42d409406b529b7aac19429ca11e Mon Sep 17 00:00:00 2001 From: Anagh Kumar Baranwal <6824881+darthShadow@users.noreply.github.com> Date: Wed, 22 Jan 2020 20:38:10 +0530 Subject: [PATCH] - Added option to fetch extended attributes too - Added variable to store any unmatched attributes Signed-off-by: Anagh Kumar Baranwal <6824881+darthShadow@users.noreply.github.com> --- README.md | 2 +- go.mod | 2 ++ newznab/newznab.go | 10 +++++++++- newznab/structs.go | 3 +++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b700484..e6a3874 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ results, _ := client.SearchWithTVMaze(categories, 80, 3, 1) ### Search using a name and set of categories: ``` -results, _ := client.SearchWithQueries(categories, "Oldboy", "movie") +results, _ := client.SearchWithQuery(categories, "Oldboy", "movie") ``` ### Get latest releases for set of categories: diff --git a/go.mod b/go.mod index 8999bb1..6692cb0 100644 --- a/go.mod +++ b/go.mod @@ -6,3 +6,5 @@ require ( github.com/stretchr/testify v1.3.0 golang.org/x/sys v0.0.0-20190405154228-4b34438f7a67 // indirect ) + +go 1.13 diff --git a/newznab/newznab.go b/newznab/newznab.go index abeccca..74b5e37 100644 --- a/newznab/newznab.go +++ b/newznab/newznab.go @@ -57,6 +57,8 @@ type Client struct { apiBaseURL string apiUserID int client *http.Client + + ExtendedAttrs bool } // New returns a new instance of Client @@ -227,6 +229,7 @@ func (c Client) process(vals url.Values, path string) ([]NZB, error) { DownloadURL: gotNZB.Enclosure.URL, SourceEndpoint: c.apiBaseURL, SourceAPIKey: c.apikey, + UnmatchedAttrs: make(map[string]string), } for _, attr := range gotNZB.Attributes { switch attr.Name { @@ -303,7 +306,8 @@ func (c Client) process(vals url.Values, path string) ([]NZB, error) { log.WithFields(log.Fields{ "name": attr.Name, "value": attr.Value, - }).Debug("encontered unknown attribute") + }).Debug("encountered unknown attribute") + nzb.UnmatchedAttrs[attr.Name] = attr.Value } } if nzb.Size == 0 { @@ -383,6 +387,10 @@ func (c Client) buildURL(vals url.Values, path string) (string, error) { return "", errors.Wrap(err, "failed to parse base API url") } + if c.ExtendedAttrs { + vals["extended"] = []string{"1"} + } + parsedURL.RawQuery = vals.Encode() return parsedURL.String(), nil } diff --git a/newznab/structs.go b/newznab/structs.go index 8bd951e..901c818 100644 --- a/newznab/structs.go +++ b/newznab/structs.go @@ -52,6 +52,9 @@ type NZB struct { InfoHash string `json:"infohash,omitempty"` DownloadURL string `json:"download_url,omitempty"` IsTorrent bool `json:"is_torrent,omitempty"` + + // All the unmatched attributes from the response + UnmatchedAttrs map[string]string } // Comment represents a user comment left on an NZB record