use of org.nzbhydra.indexers.exceptions.IndexerAccessException in project nzbhydra2 by theotherp.
the class NzbIndex method getNfo.
@Override
public NfoResult getNfo(String guid) {
URI nfoUri = getBaseUri().pathSegment("nfo", guid).build().toUri();
try {
String html = getAndStoreResultToDatabase(nfoUri, String.class, IndexerApiAccessType.NFO);
Matcher matcher = NFO_PATTERN.matcher(html);
if (!matcher.find()) {
return NfoResult.withoutNfo();
}
return NfoResult.withNfo(matcher.group(1));
} catch (IndexerAccessException e) {
return NfoResult.unsuccessful(e.getMessage());
}
}
use of org.nzbhydra.indexers.exceptions.IndexerAccessException 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());
}
}
use of org.nzbhydra.indexers.exceptions.IndexerAccessException in project nzbhydra2 by theotherp.
the class NewznabChecker method checkCaps.
/**
* Attempts to determine which search IDs like IMDB or TVDB ID are supported by the indexer specified in the config.
* <p>
* Executes a search for each of the known IDs. If enough returned results match the expected title the ID is probably supported.
*/
public CheckCapsResponse checkCaps(IndexerConfig indexerConfig) {
List<CheckCapsRequest> requests = Arrays.asList(new CheckCapsRequest(indexerConfig, "tvsearch", "tvdbid", "121361", Arrays.asList("Thrones", "GOT")), new CheckCapsRequest(indexerConfig, "tvsearch", "rid", "24493", Arrays.asList("Thrones", "GOT")), new CheckCapsRequest(indexerConfig, "tvsearch", "tvmazeid", "82", Arrays.asList("Thrones", "GOT")), new CheckCapsRequest(indexerConfig, "tvsearch", "traktid", "1390", Arrays.asList("Thrones", "GOT")), new CheckCapsRequest(indexerConfig, "movie", "tmdbid", "1399", Arrays.asList("Avengers", "Vengadores")), new CheckCapsRequest(indexerConfig, "movie", "imdbid", "0848228", Arrays.asList("Avengers", "Vengadores")));
boolean allChecked = true;
boolean configComplete = true;
Integer timeout = indexerConfig.getTimeout().orElse(configProvider.getBaseConfig().getSearching().getTimeout()) + 1;
List<Callable<SingleCheckCapsResponse>> callables = new ArrayList<>();
for (int i = 0; i < requests.size(); i++) {
CheckCapsRequest request = requests.get(i);
callables.add(() -> {
// Give indexer some time to breathe
Thread.sleep(PAUSE_BETWEEN_CALLS);
return singleCheckCaps(request, indexerConfig);
});
}
Set<SingleCheckCapsResponse> responses = new HashSet<>();
Set<IdType> supportedIds;
String backend = null;
ExecutorService executor = MdcThreadPoolExecutor.newWithInheritedMdc(MAX_CONNECTIONS);
try {
logger.info("Will check capabilities of indexer {} using {} concurrent connections", indexerConfig.getName(), MAX_CONNECTIONS);
List<Future<SingleCheckCapsResponse>> futures = executor.invokeAll(callables);
for (Future<SingleCheckCapsResponse> future : futures) {
try {
SingleCheckCapsResponse response = future.get(timeout, TimeUnit.SECONDS);
if (response.getBackend() != null) {
backend = response.getBackend();
}
responses.add(response);
} catch (ExecutionException e) {
if (e.getCause() instanceof IndexerAccessException) {
logger.error("Error while communicating with indexer: " + e.getMessage());
} else {
logger.error("Unexpected error while checking caps", e);
}
allChecked = false;
} catch (TimeoutException e) {
logger.error("Indexer {] failed to answer in {} seconds", indexerConfig.getName(), timeout);
allChecked = false;
}
}
supportedIds = responses.stream().filter(SingleCheckCapsResponse::isSupported).map(x -> Newznab.paramValueToIdMap.get(x.getKey())).collect(Collectors.toSet());
if (supportedIds.isEmpty()) {
logger.info("Indexer {} does not support searching by any IDs", indexerConfig.getName());
} else {
logger.info("Indexer {} supports searching using the following IDs: {}", indexerConfig.getName(), supportedIds.stream().map(Enum::name).collect(Collectors.joining(", ")));
}
indexerConfig.setSupportedSearchIds(new ArrayList<>(supportedIds));
} catch (InterruptedException e) {
logger.error("Unexpected error while checking caps", e);
allChecked = false;
} finally {
executor.shutdown();
}
try {
indexerConfig.setCategoryMapping(setSupportedSearchTypesAndIndexerCategoryMapping(indexerConfig, timeout));
if (indexerConfig.getSupportedSearchTypes().isEmpty()) {
logger.info("Indexer {} does not support any special search types", indexerConfig.getName());
} else {
logger.info("Indexer {} supports the following search types: {}", indexerConfig.getName(), indexerConfig.getSupportedSearchTypes().stream().map(Enum::name).collect(Collectors.joining(", ")));
}
} catch (IndexerAccessException e) {
logger.error("Error while accessing indexer: " + e.getMessage());
configComplete = false;
}
BackendType backendType = BackendType.NEWZNAB;
if (backend == null && indexerConfig.getSearchModuleType() == SearchModuleType.NEWZNAB) {
logger.info("Indexer {} didn't provide a backend type. Will use newznab.", indexerConfig.getName());
} else if (backend != null) {
try {
backendType = BackendType.valueOf(backend.toUpperCase());
logger.info("Indexer {} uses backend type {}", indexerConfig.getName(), backendType);
} catch (IllegalArgumentException e) {
logger.warn("Indexer {} reported unknown backend type {}. Will use newznab for now. Please report this.", indexerConfig.getName(), backend);
}
}
indexerConfig.setBackend(backendType);
indexerConfig.setConfigComplete(configComplete);
indexerConfig.setAllCapsChecked(allChecked);
indexerConfig.setState(configComplete ? IndexerConfig.State.ENABLED : IndexerConfig.State.DISABLED_SYSTEM);
return new CheckCapsResponse(indexerConfig, allChecked, configComplete);
}
Aggregations