use of org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot 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");
}
use of org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot 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;
}
}
});
}
use of org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot in project nzbhydra2 by theotherp.
the class ExternalApiSearchingIntegrationTest method shouldUseProvidedIdentifiers.
@Test
public void shouldUseProvidedIdentifiers() throws Exception {
prepareIndexerWithOneResponse();
searchModuleProvider.getIndexers().get(0).getConfig().setSupportedSearchIds(Arrays.asList(IdType.IMDB, IdType.TMDB));
NewznabXmlRoot root = (NewznabXmlRoot) externalApi.api(NewznabParameters.builder().tmdbid("abcd").imdbid("1234").t(ActionAttribute.MOVIE).apikey("apikey").build()).getBody();
RecordedRequest request = webServer.takeRequest(2, TimeUnit.SECONDS);
assertThat(request.getPath()).contains("imdbid=1234").contains("tmdbid=abcd");
assertThat(root.getRssChannel().getNewznabResponse().getTotal()).isEqualTo(1);
assertThat(root.getRssChannel().getItems().size()).isEqualTo(1);
}
use of org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot in project nzbhydra2 by theotherp.
the class ExternalApiSearchingIntegrationTest method shouldCallNewznabTwice.
@Test
public void shouldCallNewznabTwice() throws Exception {
NewznabResponseBuilder builder = new NewznabResponseBuilder();
String xml1 = builder.getTestResult(1, 100, "indexer1", 0, 150).toXmlString();
String xml2 = builder.getTestResult(101, 150, "indexer1", 100, 150).toXmlString();
String xml3 = builder.getTestResult(1, 0, "indexer2", 0, 0).toXmlString();
webServer.enqueue(new MockResponse().setBody(xml1).setHeader("Content-Type", "application/xml; charset=utf-8"));
webServer.enqueue(new MockResponse().setBody(xml2).setHeader("Content-Type", "application/xml; charset=utf-8"));
webServer.enqueue(new MockResponse().setBody(xml3).setHeader("Content-Type", "application/xml; charset=utf-8"));
NewznabParameters apiCallParameters = new NewznabParameters();
apiCallParameters.setApikey("apikey");
apiCallParameters.setOffset(0);
apiCallParameters.setLimit(100);
apiCallParameters.setT(ActionAttribute.SEARCH);
NewznabXmlRoot apiSearchResult = (NewznabXmlRoot) externalApi.api(apiCallParameters).getBody();
assertThat(apiSearchResult.getRssChannel().getItems().size()).isEqualTo(100);
apiCallParameters.setLimit(100);
apiCallParameters.setOffset(100);
apiSearchResult = (NewznabXmlRoot) externalApi.api(apiCallParameters).getBody();
assertThat(apiSearchResult.getRssChannel().getItems().size()).isEqualTo(50);
}
use of org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot 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;
}
Aggregations