Search in sources :

Example 1 with NewznabAttribute

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

the class TorznabMappingTest method testMappingFromXml.

@Test
public void testMappingFromXml() throws Exception {
    NewznabXmlRoot rssRoot = getRssRootFromXml("cardigann.xml");
    NewznabXmlChannel channel = rssRoot.getRssChannel();
    assertThat(channel.getTitle(), is("some-torrents"));
    assertThat(channel.getLink(), is("https://some-torrents.com/"));
    assertThat(channel.getLanguage(), is("en-us"));
    List<NewznabXmlItem> items = channel.getItems();
    assertThat(items.size(), is(2));
    NewznabXmlItem item = items.get(0);
    assertThat(item.getLink(), is("http://127.0.0.1:5060/download/111.torrent"));
    assertThat(item.getPubDate(), is(Instant.ofEpochSecond(1493900064)));
    assertThat(item.getComments(), is("https://some-torrents.com/details.php?id=111&page=0#startcomments"));
    NewznabXmlGuid rssGuid = item.getRssGuid();
    assertThat(rssGuid.getGuid(), is("https://some-torrents.com/details.php?id=111"));
    NewznabXmlEnclosure enclosure = item.getEnclosure();
    assertThat(enclosure.getUrl(), is("http://127.0.0.1:5060/download/111.torrent"));
    List<NewznabAttribute> attributes = item.getTorznabAttributes();
    assertThat(attributes.size(), is(8));
    assertThat(attributes.get(1).getName(), is("seeders"));
    assertThat(attributes.get(1).getValue(), is("11"));
    assertThat(attributes.get(5).getName(), is("size"));
    assertThat(attributes.get(5).getValue(), is("620000000"));
}
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) Test(org.junit.Test)

Example 2 with NewznabAttribute

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

the class DevIndexer method getAndStoreResultToDatabase.

protected Xml getAndStoreResultToDatabase(URI uri, IndexerApiAccessType apiAccessType) throws IndexerAccessException {
    NewznabXmlRoot rssRoot = new NewznabXmlRoot();
    if (uri.toString().contains("oneduplicate")) {
        NewznabMockRequest mockRequest = NewznabMockRequest.builder().numberOfResults(1).titleBase("oneresult").titleWords(Collections.emptyList()).total(1).build();
        rssRoot = NewznabMockBuilder.generateResponse(mockRequest);
        rssRoot.getRssChannel().getNewznabResponse().setTotal(1);
        rssRoot.getRssChannel().getItems().get(0).getEnclosure().setLength(100000L);
        rssRoot.getRssChannel().getItems().get(0).getNewznabAttributes().clear();
    } else if (uri.toString().contains("duplicatesandtitlegroups")) {
        // One duplicate
        NewznabMockRequest mockRequest = NewznabMockRequest.builder().numberOfResults(1).titleBase("oneresult").titleWords(Collections.emptyList()).total(1).build();
        rssRoot = NewznabMockBuilder.generateResponse(mockRequest);
        rssRoot.getRssChannel().getItems().get(0).getEnclosure().setLength(100000L);
        rssRoot.getRssChannel().getItems().get(0).getNewznabAttributes().clear();
        rssRoot.getRssChannel().getItems().get(0).getTorznabAttributes().clear();
        rssRoot.getRssChannel().getItems().get(0).getNewznabAttributes().add(new NewznabAttribute("grabs", "100"));
        // Another duplicate in the same title group
        mockRequest = NewznabMockRequest.builder().numberOfResults(1).titleBase("oneresult").titleWords(Collections.emptyList()).total(1).build();
        NewznabXmlRoot rssRoot3 = NewznabMockBuilder.generateResponse(mockRequest);
        rssRoot3.getRssChannel().getItems().get(0).getEnclosure().setLength(200000L);
        rssRoot3.getRssChannel().getItems().get(0).getNewznabAttributes().clear();
        rssRoot3.getRssChannel().getItems().get(0).getTorznabAttributes().clear();
        rssRoot3.getRssChannel().getItems().get(0).getNewznabAttributes().add(new NewznabAttribute("grabs", "2000"));
        // Otherwise it will result in a unique key exception
        rssRoot3.getRssChannel().getItems().get(0).setLink("anotherlink");
        rssRoot.getRssChannel().getItems().add(rssRoot3.getRssChannel().getItems().get(0));
        // Will be a grouped title but have no duplicates
        mockRequest = NewznabMockRequest.builder().numberOfResults(1).titleBase("anotherresult").titleWords(Collections.emptyList()).total(1).build();
        NewznabXmlRoot rssRoot2 = NewznabMockBuilder.generateResponse(mockRequest);
        rssRoot.getRssChannel().getItems().add(rssRoot2.getRssChannel().getItems().get(0));
        rssRoot.getRssChannel().getNewznabResponse().setTotal(3);
    } else if (uri.toString().contains("duplicates")) {
        NewznabMockRequest mockRequest = NewznabMockRequest.builder().numberOfResults(10).titleBase("duplicates").titleWords(Collections.emptyList()).total(10).build();
        rssRoot = NewznabMockBuilder.generateResponse(mockRequest);
        rssRoot.getRssChannel().getNewznabResponse().setTotal(10);
        for (NewznabXmlItem rssItem : rssRoot.getRssChannel().getItems()) {
            rssItem.getEnclosure().setLength(100000L);
            rssItem.getNewznabAttributes().clear();
            rssItem.setPubDate(Instant.now());
            rssItem.setDescription("Indexer: " + getName() + ", title:" + rssItem.getTitle());
        }
    } else if (uri.toString().contains("tworesults")) {
        rssRoot = NewznabMockBuilder.generateResponse(0, 2, "results", false, Collections.emptyList());
        rssRoot.getRssChannel().getNewznabResponse().setTotal(2);
    } else {
        rssRoot = NewznabMockBuilder.generateResponse(0, 100, "results", false, Collections.emptyList());
        rssRoot.getRssChannel().getNewznabResponse().setTotal(100);
    }
    if (uri.toString().contains("punkte")) {
        rssRoot.getRssChannel().getItems().get(0).setTitle("a a");
        rssRoot.getRssChannel().getItems().get(1).setTitle("ab");
        rssRoot.getRssChannel().getItems().get(2).setTitle("a.c");
    }
    return rssRoot;
}
Also used : NewznabXmlRoot(org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot) NewznabMockRequest(org.nzbhydra.mapping.newznab.mock.NewznabMockRequest) NewznabAttribute(org.nzbhydra.mapping.newznab.xml.NewznabAttribute) NewznabXmlItem(org.nzbhydra.mapping.newznab.xml.NewznabXmlItem)

Example 3 with NewznabAttribute

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

the class SearchingResultsUiTest method prepareFiveResultsFromTwoIndexers.

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

        @Override
        public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
            int mockServerPort = mockWebServer.getPort();
            String mockServerBaseUrl = "http://127.0.0.1:" + mockServerPort + "/";
            if (request.getRequestUrl().queryParameter("apikey") != null && request.getRequestUrl().queryParameter("apikey").equals("apikey1")) {
                NewznabXmlItem result1 = RssItemBuilder.builder("indexer1-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("indexer1-result2").pubDate(Instant.now().minus(2, ChronoUnit.DAYS)).link(mockServerBaseUrl + "nzblink2").hasNfo(true).grabs(2).size(mbToBytes(2)).newznabAttributes(new ArrayList<>(Arrays.asList(new NewznabAttribute("category", "5040")))).category("TV SD").build();
                NewznabXmlItem result3 = RssItemBuilder.builder("indexer1-result3").pubDate(Instant.now().minus(3, ChronoUnit.DAYS)).link(mockServerBaseUrl + "nzblink3").comments("comments").grabs(3).size(mbToBytes(3)).newznabAttributes(new ArrayList<>(Arrays.asList(new NewznabAttribute("category", "5030")))).category("TV HD").build();
                NewznabXmlRoot rssRoot = NewznabMockBuilder.getRssRoot(Arrays.asList(result1, result2, result3), 0, 3);
                return new MockResponse().setBody(rssRoot.toXmlString()).setHeader("Content-Type", "application/xml; charset=utf-8");
            } else if (request.getRequestUrl().queryParameter("apikey") != null && request.getRequestUrl().queryParameter("apikey").equals("apikey2")) {
                NewznabXmlItem result5 = RssItemBuilder.builder("indexer2-result2").pubDate(Instant.now().minus(5, ChronoUnit.DAYS)).link(mockServerBaseUrl + "nzblink5").grabs(5).size(mbToBytes(5)).newznabAttributes(new ArrayList<>(Arrays.asList(new NewznabAttribute("category", "2040")))).category("Movies HD").build();
                NewznabXmlItem result4 = RssItemBuilder.builder("indexer2-result1").pubDate(Instant.now().minus(4, ChronoUnit.DAYS)).link(mockServerBaseUrl + "nzblink4").grabs(4).size(mbToBytes(4)).newznabAttributes(new ArrayList<>(Arrays.asList(new NewznabAttribute("category", "2000")))).category("Movies").build();
                NewznabXmlRoot rssRoot = NewznabMockBuilder.getRssRoot(Arrays.asList(result4, result5), 0, 2);
                return new MockResponse().setBody(rssRoot.toXmlString()).setHeader("Content-Type", "application/xml; charset=utf-8");
            } else if (request.getPath().endsWith("nzbzip")) {
                System.out.println("Returning NZB ZIP response");
                String body = request.getBody().readString(Charset.defaultCharset());
                ObjectMapper objectMapper = new ObjectMapper();
                try {
                    List<Long> ids = objectMapper.readValue(body, new TypeReference<List<Long>>() {
                    });
                    FileZipResponse response = new FileZipResponse(true, "bla", null, ids, Collections.emptyList());
                    return new MockResponse().setBody(objectMapper.writeValueAsString(response)).setHeader("Content-Type", "application/xml; charset=utf-8");
                } catch (IOException e) {
                }
                throw new RuntimeException("Unable to handle nzbzip");
            } else if (request.getPath().contains("nzblink")) {
                System.out.println("Returning NZB");
                return new MockResponse().setBody("nzb").setHeader("Content-Type", "application/x-nzb; charset=utf-8");
            } else {
                throw new RuntimeException("Unexpected api key " + request.getRequestUrl().queryParameter("apikey"));
            }
        }
    });
}
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) IOException(java.io.IOException) Dispatcher(okhttp3.mockwebserver.Dispatcher) ArrayList(java.util.ArrayList) List(java.util.List) FileZipResponse(org.nzbhydra.downloading.FileZipResponse) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 4 with NewznabAttribute

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

the class SearchingResultsUiTest method prepareDuplicateAndTitleGroupedResults.

protected void prepareDuplicateAndTitleGroupedResults() throws IOException {
    replaceConfig(getClass().getResource("twoIndexers.json"));
    mockWebServer.setDispatcher(new Dispatcher() {

        @Override
        public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
            if (request.getRequestUrl().queryParameter("apikey").equals("apikey1")) {
                NewznabXmlItem duplicate = RssItemBuilder.builder("duplicate").pubDate(Instant.now().minus(1, ChronoUnit.DAYS)).hasNfo(false).grabs(1).size(mbToBytes(3)).newznabAttributes(new ArrayList<>(Arrays.asList(new NewznabAttribute("category", "5000")))).category("TV").link("link1").build();
                NewznabXmlItem result2 = RssItemBuilder.builder("grouptitle").pubDate(Instant.now().minus(2, ChronoUnit.DAYS)).hasNfo(true).grabs(2).size(mbToBytes(2)).newznabAttributes(new ArrayList<>(Arrays.asList(new NewznabAttribute("category", "5040")))).category("TV SD").link("link2").build();
                NewznabXmlItem result3 = RssItemBuilder.builder("grouptitle").pubDate(Instant.now().minus(3, ChronoUnit.DAYS)).comments("comments").grabs(3).size(mbToBytes(1)).newznabAttributes(new ArrayList<>(Arrays.asList(new NewznabAttribute("category", "5030")))).category("TV HD").link("link3").build();
                NewznabXmlRoot rssRoot = NewznabMockBuilder.getRssRoot(Arrays.asList(duplicate, result2, result3), 0, 3);
                return new MockResponse().setBody(rssRoot.toXmlString()).setHeader("Content-Type", "application/xml; charset=utf-8");
            } else if (request.getRequestUrl().queryParameter("apikey").equals("apikey2")) {
                NewznabXmlItem duplicate = RssItemBuilder.builder("duplicate").pubDate(Instant.now().minus(1, ChronoUnit.DAYS)).hasNfo(false).grabs(1).size(mbToBytes(3)).newznabAttributes(new ArrayList<>(Arrays.asList(new NewznabAttribute("category", "5000")))).category("TV").link("link4").build();
                NewznabXmlRoot rssRoot = NewznabMockBuilder.getRssRoot(Arrays.asList(duplicate), 0, 1);
                return new MockResponse().setBody(rssRoot.toXmlString()).setHeader("Content-Type", "application/xml; charset=utf-8");
            } else {
                throw new RuntimeException("Unexpected api key " + request.getRequestUrl().queryParameter("apikey"));
            }
        }
    });
}
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 5 with NewznabAttribute

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

the class ExternalApiEndToEndTest method prepareDuplicateAndTitleGroupedResults.

protected void prepareDuplicateAndTitleGroupedResults() throws IOException {
    replaceConfig(getClass().getResource("twoIndexers.json"));
    mockWebServer.setDispatcher(new Dispatcher() {

        @Override
        public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
            if (request.getRequestUrl().queryParameter("apikey").equals("apikey1")) {
                NewznabXmlItem duplicate = RssItemBuilder.builder("duplicate").pubDate(Instant.now().minus(1, ChronoUnit.DAYS)).hasNfo(false).grabs(1).size(mbToBytes(3)).newznabAttributes(new ArrayList<>(Arrays.asList(new NewznabAttribute("category", "5000")))).category("TV").link("link1").build();
                NewznabXmlItem result2 = RssItemBuilder.builder("grouptitle").pubDate(Instant.now().minus(2, ChronoUnit.DAYS)).hasNfo(true).grabs(2).size(mbToBytes(2)).newznabAttributes(new ArrayList<>(Arrays.asList(new NewznabAttribute("category", "5040")))).category("TV SD").link("link2").build();
                NewznabXmlItem result3 = RssItemBuilder.builder("grouptitle").pubDate(Instant.now().minus(3, ChronoUnit.DAYS)).comments("comments").grabs(3).size(mbToBytes(1)).newznabAttributes(new ArrayList<>(Arrays.asList(new NewznabAttribute("category", "5030")))).category("TV HD").link("link3").build();
                NewznabXmlRoot rssRoot = NewznabMockBuilder.getRssRoot(Arrays.asList(duplicate, result2, result3), 0, 3);
                return new MockResponse().setBody(rssRoot.toXmlString()).setHeader("Content-Type", "application/xml; charset=utf-8");
            } else if (request.getRequestUrl().queryParameter("apikey").equals("apikey2")) {
                NewznabXmlItem duplicate = RssItemBuilder.builder("duplicate").pubDate(Instant.now().minus(1, ChronoUnit.DAYS)).hasNfo(false).grabs(1).size(mbToBytes(3)).newznabAttributes(new ArrayList<>(Arrays.asList(new NewznabAttribute("category", "5000")))).category("TV").link("link4").build();
                NewznabXmlRoot rssRoot = NewznabMockBuilder.getRssRoot(Arrays.asList(duplicate), 0, 1);
                return new MockResponse().setBody(rssRoot.toXmlString()).setHeader("Content-Type", "application/xml; charset=utf-8");
            } else {
                throw new RuntimeException("Unexpected api key " + request.getRequestUrl().queryParameter("apikey"));
            }
        }
    });
}
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)

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