use of org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot in project nzbhydra2 by theotherp.
the class NewznabChecker method singleCheckCaps.
private SingleCheckCapsResponse singleCheckCaps(CheckCapsRequest request, IndexerConfig indexerConfig) throws IndexerAccessException {
URI uri = getBaseUri(request.getIndexerConfig()).queryParam("t", request.getTMode()).queryParam(request.getKey(), request.getValue()).build().toUri();
logger.debug("Calling URL {}", uri);
Xml response = indexerWebAccess.get(uri, indexerConfig);
if (response instanceof NewznabXmlError) {
String errorDescription = ((NewznabXmlError) response).getDescription();
if (errorDescription.toLowerCase().contains("function not available")) {
logger.error("Indexer {} reports that it doesn't support the ID type {}", request.indexerConfig.getName(), request.getKey());
eventPublisher.publishEvent(new CheckerEvent(indexerConfig.getName(), "Doesn't support " + request.getKey()));
return new SingleCheckCapsResponse(request.getKey(), false, null);
}
logger.debug("RSS error from indexer {}: {}", request.indexerConfig.getName(), errorDescription);
eventPublisher.publishEvent(new CheckerEvent(indexerConfig.getName(), "RSS error from indexer: " + errorDescription));
throw new IndexerAccessException("RSS error from indexer: " + errorDescription);
}
NewznabXmlRoot rssRoot = (NewznabXmlRoot) response;
if (rssRoot.getRssChannel().getItems().isEmpty()) {
logger.info("Indexer {} probably doesn't support the ID type {}. It returned no results.", request.indexerConfig.getName(), request.getKey());
eventPublisher.publishEvent(new CheckerEvent(indexerConfig.getName(), "Probably doesn't support " + request.getKey()));
return new SingleCheckCapsResponse(request.getKey(), false, rssRoot.getRssChannel().getGenerator());
}
long countCorrectResults = rssRoot.getRssChannel().getItems().stream().filter(x -> request.getTitleExpectedToContain().stream().anyMatch(y -> x.getTitle().toLowerCase().contains(y.toLowerCase()))).count();
float percentCorrect = (100 * countCorrectResults) / rssRoot.getRssChannel().getItems().size();
boolean supported = percentCorrect >= ID_THRESHOLD_PERCENT;
if (supported) {
logger.info("Indexer {} probably supports the ID type {}. {}% of results were correct.", request.indexerConfig.getName(), request.getKey(), percentCorrect);
eventPublisher.publishEvent(new CheckerEvent(indexerConfig.getName(), "Probably supports " + request.getKey()));
return new SingleCheckCapsResponse(request.getKey(), true, rssRoot.getRssChannel().getGenerator());
} else {
logger.info("Indexer {} probably doesn't support the ID type {}. {}% of results were correct.", request.indexerConfig.getName(), request.getKey(), percentCorrect);
eventPublisher.publishEvent(new CheckerEvent(indexerConfig.getName(), "Probably doesn't support " + request.getKey()));
return new SingleCheckCapsResponse(request.getKey(), false, rssRoot.getRssChannel().getGenerator());
}
}
use of org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot 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;
}
use of org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot in project nzbhydra2 by theotherp.
the class NewznabResponseBuilderTest method shouldInsertOffsetAndTotal.
@Test
public void shouldInsertOffsetAndTotal() {
NewznabXmlRoot root = testee.getTestResult(1, 2, "itemTitle", null, null);
assertEquals(0, root.getRssChannel().getNewznabResponse().getOffset().intValue());
assertEquals(2, root.getRssChannel().getNewznabResponse().getTotal().intValue());
root = testee.getTestResult(1, 2, "itemTitle", 2, 100);
assertEquals(2, root.getRssChannel().getNewznabResponse().getOffset().intValue());
assertEquals(100, root.getRssChannel().getNewznabResponse().getTotal().intValue());
}
use of org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot in project nzbhydra2 by theotherp.
the class NewznabResponseBuilderTest method shouldBuild.
@Test
public void shouldBuild() {
NewznabXmlRoot root = testee.getTestResult(1, 2, "itemTitle", null, null);
assertEquals(2, root.getRssChannel().getItems().size());
assertEquals("itemTitle1", root.getRssChannel().getItems().get(0).getTitle());
root = testee.getTestResult(3, 3, "itemTitle", null, null);
assertEquals(1, root.getRssChannel().getItems().size());
assertEquals("itemTitle3", root.getRssChannel().getItems().get(0).getTitle());
}
use of org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot in project nzbhydra2 by theotherp.
the class SearchingResultsUiTest method testMessageIfNoResults.
@Test
public void testMessageIfNoResults() throws Exception {
replaceIndexers(Arrays.asList(IndexerConfigBuilder.builder().build()));
NewznabXmlRoot rssRoot = NewznabMockBuilder.getRssRoot(Arrays.asList(), 0, 0);
mockWebServer.enqueue(new MockResponse().setBody(rssRoot.toXmlString()).setHeader("Content-Type", "application/xml; charset=utf-8"));
webDriver.get(url + "/?category=All&query=uitest&mode=search");
WebDriverWait wait = new WebDriverWait(webDriver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("no-search-results")));
SearchResultsPO searchResultsPage = factory.createPage(SearchResultsPO.class);
assertThat(searchResultsPage.noSearchResultsWarning().text()).isEqualTo("No results were found for this search");
assertThat(webDriver.findElements(By.className("search-results-table")).isEmpty()).isTrue();
}
Aggregations