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

Added Handling for Extended & Unmatched Attributes #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 9 additions & 1 deletion newznab/newznab.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ type Client struct {
apiBaseURL string
apiUserID int
client *http.Client

ExtendedAttrs bool
}

// New returns a new instance of Client
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 3 additions & 0 deletions newznab/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down