From f87e261e8c6649dea8371142cd8b7d6217aaa48a Mon Sep 17 00:00:00 2001
From: Logan Snow <4197432+lsnow99@users.noreply.github.com>
Date: Tue, 29 Jun 2021 10:22:35 -0400
Subject: [PATCH 1/4] Add a method to return details for an nzb
---
newznab/newznab.go | 21 +++++++++++++++++++++
newznab/structs.go | 33 +++++++++++++++++++++++++++++++++
2 files changed, 54 insertions(+)
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/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"`
+}
From 59efa5a9d9c9799a8787cd74283e25846516a816 Mon Sep 17 00:00:00 2001
From: Logan Snow <4197432+lsnow99@users.noreply.github.com>
Date: Tue, 29 Jun 2021 21:05:17 -0400
Subject: [PATCH 2/4] Add test case
---
newznab/newznab_test.go | 6 +++
...b91a86adc4ebd3b289687ebf4b0d_t_details.xml | 43 +++++++++++++++++++
2 files changed, 49 insertions(+)
create mode 100644 tests/fixtures/api/apikey_gibberish_guid_4694b91a86adc4ebd3b289687ebf4b0d_t_details.xml
diff --git a/newznab/newznab_test.go b/newznab/newznab_test.go
index ce8633a..599da8f 100644
--- a/newznab/newznab_test.go
+++ b/newznab/newznab_test.go
@@ -22,6 +22,7 @@ func TestUsenetCrawlerClient(t *testing.T) {
reg := regexp.MustCompile(`\W`)
fixedPath := reg.ReplaceAllString(r.URL.RawQuery, "_")
+ fmt.Println(fixedPath)
if r.URL.Query()["t"][0] == "get" {
// Fetch nzb
@@ -177,5 +178,10 @@ func TestUsenetCrawlerClient(t *testing.T) {
})
})
})
+
+ t.Run("single nzb details", func(t *testing.T) {
+ _, err := client.Details("4694b91a86adc4ebd3b289687ebf4b0d")
+ require.NoError(t, err)
+ })
})
}
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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
From fea40c156fe81b7aa403ce522936513bc2a107b9 Mon Sep 17 00:00:00 2001
From: Logan Snow <4197432+lsnow99@users.noreply.github.com>
Date: Tue, 29 Jun 2021 21:09:30 -0400
Subject: [PATCH 3/4] Remove print statement
---
newznab/newznab_test.go | 1 -
1 file changed, 1 deletion(-)
diff --git a/newznab/newznab_test.go b/newznab/newznab_test.go
index 599da8f..b680d01 100644
--- a/newznab/newznab_test.go
+++ b/newznab/newznab_test.go
@@ -22,7 +22,6 @@ func TestUsenetCrawlerClient(t *testing.T) {
reg := regexp.MustCompile(`\W`)
fixedPath := reg.ReplaceAllString(r.URL.RawQuery, "_")
- fmt.Println(fixedPath)
if r.URL.Query()["t"][0] == "get" {
// Fetch nzb
From d76b8bbb9347c6512b817436658f6707e296b8b8 Mon Sep 17 00:00:00 2001
From: Michael Robinson
Date: Tue, 29 Jun 2021 20:58:43 -0600
Subject: [PATCH 4/4] add assertion to single_nzb_details test
---
newznab/newznab_test.go | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/newznab/newznab_test.go b/newznab/newznab_test.go
index b0625a5..6146405 100644
--- a/newznab/newznab_test.go
+++ b/newznab/newznab_test.go
@@ -179,8 +179,9 @@ func TestUsenetCrawlerClient(t *testing.T) {
})
t.Run("single nzb details", func(t *testing.T) {
- _, err := client.Details("4694b91a86adc4ebd3b289687ebf4b0d")
+ d, err := client.Details("4694b91a86adc4ebd3b289687ebf4b0d")
require.NoError(t, err)
+ require.Equal(t, "Car.Craft-July.2015", d.Channel.Item.Title)
})
})
}