Skip to content

Commit

Permalink
Merge pull request #12 from lsnow99/add-details-method
Browse files Browse the repository at this point in the history
Add a method to return details for an nzb
  • Loading branch information
Michael Robinson authored Jun 30, 2021
2 parents 506d57a + d76b8bb commit a24716a
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
21 changes: 21 additions & 0 deletions newznab/newznab.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
Expand Down
6 changes: 6 additions & 0 deletions newznab/newznab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
}
33 changes: 33 additions & 0 deletions newznab/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:newznab="http://nzbgeek.info/feeds/attributes/">
<channel>
<atom:link href="https://api.nzbgeek.info/api?t=details&amp;apikey=7c1yDyAz12ZJDpUunuXyAeFxeFv0jjeI&amp;guid=cd0faeca5a5b93c50b3f568b7e2ec560" rel="self" type="application/rss+xml" />
<title>api.nzbgeek.info</title>
<description>NZBgeek API</description>
<link>http://api.nzbgeek.info/</link>
<language>en-gb</language>
<webMaster>[email protected] (NZBgeek)</webMaster>
<category></category>
<image>
<url>https://api.nzbgeek.info/covers/nzbgeek.png</url>
<title>api.nzbgeek.info</title>
<link>http://api.nzbgeek.info/</link>
<description>NZBgeek</description>
</image>
<item>
<title>Car.Craft-July.2015</title>
<guid isPermaLink="true">https://nzbgeek.info/geekseek.php?guid=4694b91a86adc4ebd3b289687ebf4b0d</guid>
<link>http://api.nzbgeek.info/api?t=get&amp;id=4694b91a86adc4ebd3b289687ebf4b0d&amp;apikey=7c1yDyAz12ZJDpUunuXyAeFxeFv0jjeI</link>
<comments>https://nzbgeek.info/geekseek.php?guid=4694b91a86adc4ebd3b289687ebf4b0d</comments>
<pubDate>Fri, 24 Apr 2015 15:03:34 +0000</pubDate>
<category>Books > Mags</category>
<description>Car.Craft-July.2015</description>
<enclosure url="http://api.nzbgeek.info/api?t=get&amp;id=4694b91a86adc4ebd3b289687ebf4b0d&amp;apikey=7c1yDyAz12ZJDpUunuXyAeFxeFv0jjeI" length="30383000" type="application/x-nzb"/>
<newznab:attr name="category" value="7000"/>
<newznab:attr name="category" value="7010"/>
<newznab:attr name="size" value="30383000"/>
<newznab:attr name="guid" value="4694b91a86adc4ebd3b289687ebf4b0d"/>
<newznab:attr name="files" value="6"/>
<newznab:attr name="poster" value="anonymous"/>
<newznab:attr name="grabs" value="9"/>
<newznab:attr name="comments" value="0"/>
<newznab:attr name="password" value="0"/>
<newznab:attr name="usenetdate" value="Fri, 24 Apr 2015 15:03:34 +0000"/>
<newznab:attr name="group" value="alt.binaries.nzb"/>
<newznab:attr name="thumbsup" value="0"/>
<newznab:attr name="thumbsdown" value="0"/>
</item>
</channel>
</rss>

0 comments on commit a24716a

Please sign in to comment.