use of org.nzbhydra.mapping.newznab.xml.NewznabXmlItem in project nzbhydra2 by theotherp.
the class NewznabXmlTransformerTest method shouldUseCorrectApplicationType.
@Test
public void shouldUseCorrectApplicationType() {
SearchRequest searchRequest = new SearchRequest(SearchSource.INTERNAL, SearchType.SEARCH, 0, 100);
SearchResultItem searchResultItem = new SearchResultItem();
searchResultItem.setIndexer(indexerMock);
searchResultItem.setCategory(new Category());
searchRequest.setDownloadType(DownloadType.NZB);
NewznabXmlItem item = testee.buildRssItem(searchResultItem, searchRequest);
assertThat(item.getEnclosure().getType()).isEqualTo("application/x-nzb");
searchRequest.setDownloadType(DownloadType.TORRENT);
item = testee.buildRssItem(searchResultItem, searchRequest);
assertThat(item.getEnclosure().getType()).isEqualTo("application/x-bittorrent");
}
use of org.nzbhydra.mapping.newznab.xml.NewznabXmlItem 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"));
}
}
});
}
use of org.nzbhydra.mapping.newznab.xml.NewznabXmlItem 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"));
}
}
});
}
use of org.nzbhydra.mapping.newznab.xml.NewznabXmlItem 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"));
}
}
});
}
use of org.nzbhydra.mapping.newznab.xml.NewznabXmlItem in project nzbhydra2 by theotherp.
the class ExternalApiEndToEndTest method shouldAllowMagnetLinkDownload.
@Test
public void shouldAllowMagnetLinkDownload() throws Exception {
replaceIndexers(Arrays.asList(IndexerConfigBuilder.builder().searchModuleType(SearchModuleType.TORZNAB).apiKey("apikey").build()));
NewznabXmlItem result = RssItemBuilder.builder("result").category("5000").link("magnet:x&dn=y").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);
Response response = new OkHttpClient.Builder().build().newCall(new Request.Builder().url(link).build()).execute();
assertThat(response.code()).isEqualTo(302);
assertThat(response.header("Location")).isEqualTo("magnet:x&dn=y");
}
Aggregations