diff --git a/newznab/newznab.go b/newznab/newznab.go index abeccca..f2e573e 100644 --- a/newznab/newznab.go +++ b/newznab/newznab.go @@ -172,6 +172,14 @@ func (c Client) LoadRSSFeedUntilNZBID(categories []int, num int, id string, maxR return nzbs, nil } +// Details get the details of a particular nzb +func (c Client) Details(guid string) (Details, error) { + return c.details(url.Values{ + "t": []string{"details"}, + "guid": []string{guid}, + }) +} + func (c Client) splitCats(cats []int) []string { var categories, catsOut []string for _, v := range cats { @@ -205,6 +213,19 @@ func (c Client) caps(vals url.Values) (Capabilities, error) { return cResp, nil } +func (c Client) details(vals url.Values) (Details, error) { + vals.Set("apikey", c.apikey) + resp, err := c.getURL(c.buildURL(vals, apiPath)) + if err != nil { + return Details{}, errors.Wrap(err, "failed to get details") + } + var dResp Details + if err = xml.Unmarshal(resp, &dResp); err != nil { + return dResp, errors.Wrap(err, "failed to unmarshal xml") + } + return dResp, nil +} + func (c Client) process(vals url.Values, path string) ([]NZB, error) { var nzbs []NZB resp, err := c.getURL(c.buildURL(vals, path)) diff --git a/newznab/newznab_test.go b/newznab/newznab_test.go index 8435590..6146405 100644 --- a/newznab/newznab_test.go +++ b/newznab/newznab_test.go @@ -177,5 +177,11 @@ func TestUsenetCrawlerClient(t *testing.T) { }) }) }) + + t.Run("single nzb details", func(t *testing.T) { + d, err := client.Details("4694b91a86adc4ebd3b289687ebf4b0d") + require.NoError(t, err) + require.Equal(t, "Car.Craft-July.2015", d.Channel.Item.Title) + }) }) } diff --git a/newznab/structs.go b/newznab/structs.go index 8bd951e..4599c9f 100644 --- a/newznab/structs.go +++ b/newznab/structs.go @@ -211,3 +211,36 @@ type Capabilities struct { } `xml:"category" json:"category,omitempty"` } `xml:"categories" json:"categories,omitempty"` } + +type Details struct { + XMLName xml.Name `xml:"rss"` + Text string `xml:",chardata"` + Version string `xml:"version,attr"` + Channel struct { + Text string `xml:",chardata"` + Item struct { + Text string `xml:",chardata"` + Title string `xml:"title"` + Guid struct { + Text string `xml:",chardata"` + IsPermaLink string `xml:"isPermaLink,attr"` + } `xml:"guid"` + Link string `xml:"link"` + Comments string `xml:"comments"` + PubDate string `xml:"pubDate"` + Category string `xml:"category"` + Description string `xml:"description"` + Enclosure struct { + Text string `xml:",chardata"` + URL string `xml:"url,attr"` + Length string `xml:"length,attr"` + Type string `xml:"type,attr"` + } `xml:"enclosure"` + Attr []struct { + Text string `xml:",chardata"` + Name string `xml:"name,attr"` + Value string `xml:"value,attr"` + } `xml:"attr"` + } `xml:"item"` + } `xml:"channel"` +} diff --git a/tests/fixtures/api/apikey_gibberish_guid_4694b91a86adc4ebd3b289687ebf4b0d_t_details.xml b/tests/fixtures/api/apikey_gibberish_guid_4694b91a86adc4ebd3b289687ebf4b0d_t_details.xml new file mode 100644 index 0000000..607f279 --- /dev/null +++ b/tests/fixtures/api/apikey_gibberish_guid_4694b91a86adc4ebd3b289687ebf4b0d_t_details.xml @@ -0,0 +1,43 @@ + + + + + api.nzbgeek.info + NZBgeek API + http://api.nzbgeek.info/ + en-gb + info@nzbgeek.info (NZBgeek) + + + https://api.nzbgeek.info/covers/nzbgeek.png + api.nzbgeek.info + http://api.nzbgeek.info/ + NZBgeek + + + Car.Craft-July.2015 + https://nzbgeek.info/geekseek.php?guid=4694b91a86adc4ebd3b289687ebf4b0d + http://api.nzbgeek.info/api?t=get&id=4694b91a86adc4ebd3b289687ebf4b0d&apikey=7c1yDyAz12ZJDpUunuXyAeFxeFv0jjeI + https://nzbgeek.info/geekseek.php?guid=4694b91a86adc4ebd3b289687ebf4b0d + Fri, 24 Apr 2015 15:03:34 +0000 + Books > Mags + Car.Craft-July.2015 + + + + + + + + + + + + + + + + +