Search in sources :

Example 6 with NewznabAttribute

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

the class ExternalApiEndToEndTest method prepareFiveResultsFromOneIndexer.

protected void prepareFiveResultsFromOneIndexer() throws Exception {
    replaceConfig(getClass().getResource("oneIndexer.json"));
    mockWebServer.setDispatcher(new Dispatcher() {

        @Override
        public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
            String mockServerBaseUrl = getMockServerBaseUrl();
            if (request.getRequestUrl().toString().contains("t=search")) {
                NewznabXmlItem result1 = RssItemBuilder.builder("result1").pubDate(Instant.now().minus(1, ChronoUnit.DAYS)).link(mockServerBaseUrl + "nzblink1").hasNfo(false).grabs(1).size(mbToBytes(1)).newznabAttributes(new ArrayList<>(Arrays.asList(new NewznabAttribute("category", "5000")))).category("TV").build();
                NewznabXmlItem result2 = RssItemBuilder.builder("result2").pubDate(Instant.now().minus(2, ChronoUnit.DAYS)).link(mockServerBaseUrl + "nzblink2").hasNfo(false).grabs(1).size(mbToBytes(1)).newznabAttributes(new ArrayList<>(Arrays.asList(new NewznabAttribute("category", "5000")))).category("TV").build();
                NewznabXmlRoot rssRoot = NewznabMockBuilder.getRssRoot(Arrays.asList(result1, result2), 0, 2);
                return new MockResponse().setBody(rssRoot.toXmlString()).setHeader("Content-Type", "application/xml; charset=utf-8");
            } else if (request.getRequestUrl().toString().contains("nzblink1")) {
                return new MockResponse().setBody("nzbcontent1").setHeader("Content-Type", "application/xml; charset=utf-8");
            } else if (request.getRequestUrl().toString().contains("nzblink2")) {
                return new MockResponse().setBody("nzbcontent2").setHeader("Content-Type", "application/xml; charset=utf-8");
            } else {
                return null;
            }
        }
    });
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) NewznabAttribute(org.nzbhydra.mapping.newznab.xml.NewznabAttribute) NewznabXmlRoot(org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot) ArrayList(java.util.ArrayList) NewznabXmlItem(org.nzbhydra.mapping.newznab.xml.NewznabXmlItem) Dispatcher(okhttp3.mockwebserver.Dispatcher)

Example 7 with NewznabAttribute

use of org.nzbhydra.mapping.newznab.xml.NewznabAttribute 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 8 with NewznabAttribute

use of org.nzbhydra.mapping.newznab.xml.NewznabAttribute 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 9 with NewznabAttribute

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

NewznabAttribute (org.nzbhydra.mapping.newznab.xml.NewznabAttribute)9 NewznabXmlItem (org.nzbhydra.mapping.newznab.xml.NewznabXmlItem)9 NewznabXmlRoot (org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot)8 ArrayList (java.util.ArrayList)5 Dispatcher (okhttp3.mockwebserver.Dispatcher)4 MockResponse (okhttp3.mockwebserver.MockResponse)4 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)4 NewznabXmlEnclosure (org.nzbhydra.mapping.newznab.xml.NewznabXmlEnclosure)4 NewznabXmlGuid (org.nzbhydra.mapping.newznab.xml.NewznabXmlGuid)4 NewznabXmlChannel (org.nzbhydra.mapping.newznab.xml.NewznabXmlChannel)3 Test (org.junit.Test)2 NewznabXmlResponse (org.nzbhydra.mapping.newznab.xml.NewznabXmlResponse)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 List (java.util.List)1 FileZipResponse (org.nzbhydra.downloading.FileZipResponse)1 NewznabMockRequest (org.nzbhydra.mapping.newznab.mock.NewznabMockRequest)1 JaxbPubdateAdapter (org.nzbhydra.mapping.newznab.xml.JaxbPubdateAdapter)1