Search in sources :

Example 11 with NewznabXmlItem

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

the class ExternalApiEndToEndTest method shouldAllowTorrentFileDownload.

@Test
public void shouldAllowTorrentFileDownload() throws Exception {
    replaceIndexers(Arrays.asList(IndexerConfigBuilder.builder().searchModuleType(SearchModuleType.TORZNAB).apiKey("apikey").build()));
    NewznabXmlItem result = RssItemBuilder.builder("result").category("5000").link(getMockServerBaseUrl() + "torrentlink").build();
    NewznabXmlRoot rssRoot = NewznabMockBuilder.getRssRoot(Arrays.asList(result), 0, 1);
    mockWebServer.enqueue(new MockResponse().setBody(rssRoot.toXmlString()).setHeader("Content-Type", "application/xml; charset=utf-8"));
    mockWebServer.enqueue(new MockResponse().setBody("torrentcontent").setHeader("Content-Type", "application/xml; charset=utf-8"));
    String body = getStringFromUrl("http://127.0.0.1:5077/torznab/api?apikey=apikey&t=search&q=whatever");
    // Extract link
    Matcher matcher = Pattern.compile("enclosure url=\"([^\"]+)\"").matcher(body);
    assertThat(matcher.find()).isTrue();
    String link = matcher.group(1);
    // Download torrent using link
    String torrentContent = getStringFromUrl(link);
    assertThat(torrentContent).isEqualTo("torrentcontent");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) Matcher(java.util.regex.Matcher) NewznabXmlRoot(org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot) NewznabXmlItem(org.nzbhydra.mapping.newznab.xml.NewznabXmlItem) NzbhydraMockMvcTest(org.nzbhydra.tests.NzbhydraMockMvcTest) Test(org.junit.Test) AbstractConfigReplacingTest(org.nzbhydra.tests.AbstractConfigReplacingTest)

Example 12 with NewznabXmlItem

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

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

the class RssItemBuilderTest method testBuilder.

@Test
public void testBuilder() {
    NewznabXmlItem item = RssItemBuilder.builder("title").group("group").poster("poster").size(1000L).category("category").categoryNewznab("5000").description("desc").link("link").hasNfo(true).grabs(10).build();
    Map<String, String> attributes = item.getNewznabAttributes().stream().collect(Collectors.toMap(NewznabAttribute::getName, NewznabAttribute::getValue));
    assertEquals("group", attributes.get("group"));
    assertEquals("poster", attributes.get("poster"));
    assertEquals("5000", attributes.get("category"));
    assertEquals("1", attributes.get("nfo"));
    assertEquals(Long.valueOf(1000), item.getEnclosure().getLength());
    assertEquals("desc", item.getDescription());
    assertEquals("category", item.getCategory());
    assertEquals("link", item.getEnclosure().getUrl());
}
Also used : NewznabXmlItem(org.nzbhydra.mapping.newznab.xml.NewznabXmlItem) Test(org.junit.Test)

Example 14 with NewznabXmlItem

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

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

the class RssBuilder method createDuplicates.

public List<NewznabXmlItem> createDuplicates(int count) {
    List<NewznabXmlItem> duplicates = new ArrayList<>();
    Random random = new Random();
    int rnd = random.nextInt();
    long size = random.nextLong();
    Instant pubDate = Instant.now().minus(random.nextInt(100), ChronoUnit.DAYS);
    for (int i = 1; i <= count; i++) {
        duplicates.add(RssItemBuilder.builder("duplicate-" + rnd).size(size).pubDate(pubDate).poster("poster-" + rnd).group("group-" + rnd).build());
    }
    return duplicates;
}
Also used : Random(java.util.Random) Instant(java.time.Instant) ArrayList(java.util.ArrayList) NewznabXmlItem(org.nzbhydra.mapping.newznab.xml.NewznabXmlItem)

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