Search in sources :

Example 1 with NewznabXmlResponse

use of org.nzbhydra.mapping.newznab.xml.NewznabXmlResponse in project nzbhydra2 by theotherp.

the class RssMappingTest method shouldParseResponseFromCardigann.

@Test
public void shouldParseResponseFromCardigann() throws Exception {
    NewznabXmlRoot rssRoot = getRssRootFromXml("btnJackettResponse.xml");
    NewznabXmlChannel channel = rssRoot.getRssChannel();
    assertThat(channel.getDescription(), is("Needs no description.."));
    NewznabXmlResponse newznabResponse = channel.getNewznabResponse();
    assertThat(newznabResponse, is(nullValue()));
    List<NewznabXmlItem> items = channel.getItems();
    assertThat(items.size(), is(3));
    NewznabXmlItem item = items.get(0);
    assertThat(item.getTitle(), is("The.Challenge.S30.Special.14.Times.Our.Challengers.Found.Their.Shit.1080p.WEB.x264-CookieMonster"));
    assertThat(item.getRssGuid().getGuid(), is("https://unicasthe.net/torrents.php?action=download&id=799031&authkey=authkey&torrent_pass=torrentPass"));
    assertThat(item.getLink(), startsWith("http://127.0.0.1:9117/dl/unicasthenet/jackettApiKey?path=linkstuff&file=The.Challenge.S30.Special.14.Times.Our.Challengers.Found.Their.Shit.1080p.WEB.x264-CookieMonster.torrent"));
    assertThat(item.getCategory(), is("5000"));
    assertThat(item.getEnclosure().getLength(), is(1459519537L));
    assertThat(item.getTorznabAttributes().size(), is(6));
    assertThat(item.getTorznabAttributes().get(0).getName(), is("rageid"));
    assertThat(item.getTorznabAttributes().get(0).getValue(), is("6126"));
}
Also used : NewznabXmlRoot(org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot) 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)

Example 2 with NewznabXmlResponse

use of org.nzbhydra.mapping.newznab.xml.NewznabXmlResponse in project nzbhydra2 by theotherp.

the class NewznabResponseBuilder method getTestResult.

public NewznabXmlRoot getTestResult(int startCount, int endCount, String itemTitleBase, Integer offset, Integer total) {
    NewznabXmlRoot rssRoot = new NewznabXmlRoot();
    rssRoot.setVersion("2.0");
    NewznabXmlChannel channel = new NewznabXmlChannel();
    channel.setTitle("channelTitle");
    channel.setDescription("channelDescription");
    channel.setLanguage("en-gb");
    channel.setWebMaster("webmaster@master.com");
    channel.setLink("http://www.link.xyz");
    channel.setNewznabResponse(new NewznabXmlResponse(offset == null ? startCount - 1 : offset, total == null ? endCount : total));
    List<NewznabXmlItem> items = new ArrayList<>();
    for (int i = startCount; i <= endCount; i++) {
        NewznabXmlItem item = new NewznabXmlItem();
        item.setDescription("Some longer itemDescription that whatever" + i);
        item.setTitle(itemTitleBase + i);
        item.setPubDate(Instant.now().minus(i * 1000, ChronoUnit.HOURS));
        item.setEnclosure(new NewznabXmlEnclosure("enclosureUrl", 5L, "application/x-nzb"));
        item.setComments("http://www.comments.com/" + i);
        item.setLink("http://www.link.com/" + i);
        item.setCategory("category");
        item.setRssGuid(new NewznabXmlGuid("http://www." + itemTitleBase + ".com/" + i, true));
        List<NewznabAttribute> attributes = new ArrayList<>();
        attributes.add(new NewznabAttribute("category", "7000"));
        attributes.add(new NewznabAttribute("size", String.valueOf(random.nextInt())));
        attributes.add(new NewznabAttribute("guid", "attributeGuid" + i));
        attributes.add(new NewznabAttribute("poster", "poster"));
        attributes.add(new NewznabAttribute("group", "group"));
        item.setNewznabAttributes(attributes);
        items.add(item);
    }
    channel.setItems(items);
    rssRoot.setRssChannel(channel);
    return rssRoot;
}
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) ArrayList(java.util.ArrayList) NewznabXmlItem(org.nzbhydra.mapping.newznab.xml.NewznabXmlItem) NewznabXmlChannel(org.nzbhydra.mapping.newznab.xml.NewznabXmlChannel) NewznabXmlResponse(org.nzbhydra.mapping.newznab.xml.NewznabXmlResponse)

Example 3 with NewznabXmlResponse

use of org.nzbhydra.mapping.newznab.xml.NewznabXmlResponse 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)

Example 4 with NewznabXmlResponse

use of org.nzbhydra.mapping.newznab.xml.NewznabXmlResponse in project nzbhydra2 by theotherp.

the class DogNzb method completeIndexerSearchResult.

protected void completeIndexerSearchResult(Xml response, IndexerSearchResult indexerSearchResult, AcceptorResult acceptorResult, SearchRequest searchRequest) {
    NewznabXmlResponse newznabResponse = ((NewznabXmlRoot) response).getRssChannel().getNewznabResponse();
    // DogNZB does not return a reliable total number. It's always 100 if there are more results, less if it's the last page
    indexerSearchResult.setTotalResultsKnown(false);
    if (newznabResponse != null) {
        if (newznabResponse.getTotal() == 100) {
            indexerSearchResult.setHasMoreResults(true);
            indexerSearchResult.setTotalResults(100);
        } else {
            indexerSearchResult.setTotalResultsKnown(true);
            indexerSearchResult.setHasMoreResults(false);
            indexerSearchResult.setTotalResults(searchRequest.getOffset().orElse(0) + newznabResponse.getTotal());
        }
        indexerSearchResult.setOffset(newznabResponse.getOffset());
        indexerSearchResult.setLimit(100);
    } else {
        indexerSearchResult.setTotalResults(0);
        indexerSearchResult.setHasMoreResults(false);
        indexerSearchResult.setOffset(0);
        indexerSearchResult.setLimit(0);
    }
}
Also used : NewznabXmlResponse(org.nzbhydra.mapping.newznab.xml.NewznabXmlResponse)

Aggregations

NewznabXmlResponse (org.nzbhydra.mapping.newznab.xml.NewznabXmlResponse)4 NewznabXmlChannel (org.nzbhydra.mapping.newznab.xml.NewznabXmlChannel)3 NewznabXmlItem (org.nzbhydra.mapping.newznab.xml.NewznabXmlItem)3 NewznabXmlRoot (org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot)3 Test (org.junit.Test)2 NewznabAttribute (org.nzbhydra.mapping.newznab.xml.NewznabAttribute)2 NewznabXmlEnclosure (org.nzbhydra.mapping.newznab.xml.NewznabXmlEnclosure)2 NewznabXmlGuid (org.nzbhydra.mapping.newznab.xml.NewznabXmlGuid)2 ArrayList (java.util.ArrayList)1