use of org.nzbhydra.mapping.newznab.xml.NewznabXmlItem in project nzbhydra2 by theotherp.
the class RssItemBuilder method build.
public NewznabXmlItem build() {
NewznabXmlItem rssItem = new NewznabXmlItem();
rssItem.setTitle(title);
rssItem.setLink(link);
rssItem.setPubDate(pubDate);
rssItem.setDescription(description);
rssItem.setComments(comments);
rssItem.setCategory(category);
rssItem.setGrabs(grabs);
rssItem.setNewznabAttributes(newznabAttributes);
rssItem.setTorznabAttributes(torznabAttributes);
if (rssGuid == null) {
rssItem.setRssGuid(new NewznabXmlGuid(title + "-guid", false));
} else {
rssItem.setRssGuid(rssGuid);
}
newznabAttributes.add(new NewznabAttribute("size", String.valueOf(size)));
if (enclosure == null) {
rssItem.setEnclosure(new NewznabXmlEnclosure(link, size, "application/x-nzb"));
} else {
rssItem.setEnclosure(enclosure);
}
newznabAttributes.add(new NewznabAttribute("usenetdate", new JaxbPubdateAdapter().marshal(pubDate)));
if (grabs != null) {
newznabAttributes.add(new NewznabAttribute("grabs", String.valueOf(grabs)));
}
return rssItem;
}
use of org.nzbhydra.mapping.newznab.xml.NewznabXmlItem in project nzbhydra2 by theotherp.
the class RssMappingTest method testMappingFromXml.
@Test
public void testMappingFromXml() throws Exception {
NewznabXmlRoot rssRoot = getRssRootFromXml("newznab_3results.xml");
NewznabXmlChannel channel = rssRoot.getRssChannel();
assertThat(channel.getDescription(), is("indexerName(dot)com Feed"));
assertThat(channel.getLink(), is("https://indexerName.com/"));
assertThat(channel.getLanguage(), is("en-gb"));
assertThat(channel.getWebMaster(), is("admin@indexerName.com (indexerName(dot)com)"));
NewznabXmlResponse newznabResponse = channel.getNewznabResponse();
assertThat(newznabResponse.getOffset(), is(0));
assertThat(newznabResponse.getTotal(), is(1000));
List<NewznabXmlItem> items = channel.getItems();
assertThat(items.size(), is(3));
NewznabXmlItem item = items.get(0);
assertThat(item.getLink(), is("https://indexerName.com/getnzb/eff551fbdb69d6777d5030c209ee5d4b.nzb&i=1692&r=apikey"));
assertThat(item.getPubDate(), is(Instant.ofEpochSecond(1444584857)));
assertThat(item.getDescription(), is("testtitle1"));
assertThat(item.getComments(), is("https://indexerName.com/details/eff551fbdb69d6777d5030c209ee5d4b#comments"));
NewznabXmlGuid rssGuid = item.getRssGuid();
assertThat(rssGuid.getGuid(), is("eff551fbdb69d6777d5030c209ee5d4b"));
assertThat(rssGuid.isPermaLink(), is(false));
NewznabXmlEnclosure enclosure = item.getEnclosure();
assertThat(enclosure.getUrl(), is("https://indexerName.com/getnzb/eff551fbdb69d6777d5030c209ee5d4b.nzb&i=1692&r=apikey"));
assertThat(enclosure.getLength(), is(2893890900L));
List<NewznabAttribute> attributes = item.getNewznabAttributes();
assertThat(attributes.size(), is(6));
assertThat(attributes.get(0).getName(), is("category"));
assertThat(attributes.get(0).getValue(), is("7000"));
assertThat(attributes.get(2).getName(), is("size"));
assertThat(attributes.get(2).getValue(), is("2893890900"));
assertThat(attributes.get(3).getName(), is("guid"));
assertThat(attributes.get(3).getValue(), is("eff551fbdb69d6777d5030c209ee5d4b"));
assertThat(attributes.get(4).getName(), is("poster"));
assertThat(attributes.get(4).getValue(), is("chuck@norris.com"));
assertThat(attributes.get(5).getName(), is("group"));
assertThat(attributes.get(5).getValue(), is("alt.binaries.mom"));
}
Aggregations