use of org.nzbhydra.mapping.newznab.xml.Xml 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.Xml in project nzbhydra2 by theotherp.
the class DevIndexerTest method testGeneration.
@Test
public void testGeneration() throws Exception {
Xml xml = testee.getAndStoreResultToDatabase(URI.create("http://127.0.01/duplicatesandtitlegroups"), null);
NewznabXmlRoot root = (NewznabXmlRoot) xml;
System.out.println(root);
}
use of org.nzbhydra.mapping.newznab.xml.Xml in project nzbhydra2 by theotherp.
the class NewznabChecker method checkConnection.
public GenericResponse checkConnection(IndexerConfig indexerConfig) {
Xml xmlResponse;
try {
URI uri = getBaseUri(indexerConfig).queryParam("t", "search").build().toUri();
xmlResponse = indexerWebAccess.get(uri, indexerConfig);
logger.debug("Checking connection to indexer {} using URI {}", indexerConfig.getName(), uri);
if (xmlResponse instanceof NewznabXmlError) {
logger.warn("Connection check with indexer {} failed with message: {}", indexerConfig.getName(), ((NewznabXmlError) xmlResponse).getDescription());
return GenericResponse.notOk("Indexer returned message: " + ((NewznabXmlError) xmlResponse).getDescription());
}
NewznabXmlRoot rssRoot = (NewznabXmlRoot) xmlResponse;
if (!rssRoot.getRssChannel().getItems().isEmpty()) {
logger.info("Connection to indexer {} successful", indexerConfig.getName());
return GenericResponse.ok();
} else {
logger.warn("Connection to indexer {} successful but search did not return any results", indexerConfig.getName());
return GenericResponse.notOk("Indexer did not return any results");
}
} catch (IndexerAccessException e) {
logger.warn("Connection check with indexer {} failed with message: {}", indexerConfig.getName(), e.getMessage());
return GenericResponse.notOk(e.getMessage());
}
}
Aggregations