Search in sources :

Example 16 with NewznabXmlItem

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;
}
Also used : NewznabXmlEnclosure(org.nzbhydra.mapping.newznab.xml.NewznabXmlEnclosure) JaxbPubdateAdapter(org.nzbhydra.mapping.newznab.xml.JaxbPubdateAdapter) NewznabXmlGuid(org.nzbhydra.mapping.newznab.xml.NewznabXmlGuid) NewznabAttribute(org.nzbhydra.mapping.newznab.xml.NewznabAttribute) NewznabXmlItem(org.nzbhydra.mapping.newznab.xml.NewznabXmlItem)

Example 17 with NewznabXmlItem

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"));
}
Also used : NewznabXmlEnclosure(org.nzbhydra.mapping.newznab.xml.NewznabXmlEnclosure) NewznabXmlGuid(org.nzbhydra.mapping.newznab.xml.NewznabXmlGuid) NewznabXmlRoot(org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot) NewznabAttribute(org.nzbhydra.mapping.newznab.xml.NewznabAttribute) NewznabXmlItem(org.nzbhydra.mapping.newznab.xml.NewznabXmlItem) NewznabXmlChannel(org.nzbhydra.mapping.newznab.xml.NewznabXmlChannel) NewznabXmlResponse(org.nzbhydra.mapping.newznab.xml.NewznabXmlResponse) Test(org.junit.Test)

Aggregations

NewznabXmlItem (org.nzbhydra.mapping.newznab.xml.NewznabXmlItem)17 NewznabXmlRoot (org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot)11 NewznabAttribute (org.nzbhydra.mapping.newznab.xml.NewznabAttribute)9 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)7 MockResponse (okhttp3.mockwebserver.MockResponse)6 Dispatcher (okhttp3.mockwebserver.Dispatcher)4 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)4 NewznabXmlChannel (org.nzbhydra.mapping.newznab.xml.NewznabXmlChannel)4 NewznabXmlEnclosure (org.nzbhydra.mapping.newznab.xml.NewznabXmlEnclosure)4 NewznabXmlGuid (org.nzbhydra.mapping.newznab.xml.NewznabXmlGuid)4 Matcher (java.util.regex.Matcher)3 NewznabXmlResponse (org.nzbhydra.mapping.newznab.xml.NewznabXmlResponse)3 SearchResultItem (org.nzbhydra.searching.SearchResultItem)3 AbstractConfigReplacingTest (org.nzbhydra.tests.AbstractConfigReplacingTest)2 NzbhydraMockMvcTest (org.nzbhydra.tests.NzbhydraMockMvcTest)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 Instant (java.time.Instant)1