use of org.nzbhydra.config.IndexerConfig in project nzbhydra2 by theotherp.
the class NzbIndexTest method setUp.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
testee.config = new IndexerConfig();
}
use of org.nzbhydra.config.IndexerConfig in project nzbhydra2 by theotherp.
the class DuplicateDetectorTest method setValues.
protected void setValues(SearchResultItem item, String indexerName, String poster, String group, Instant pubDate) {
item.setAgePrecise(true);
item.setTitle("title");
item.setIndexerGuid("123");
item.setPubDate(pubDate);
item.setPoster(poster);
item.setGroup(group);
item.setSize(10000L);
Newznab indexer = new Newznab();
IndexerConfig config = new IndexerConfig();
config.setName(indexerName);
IndexerEntity indexerEntity = new IndexerEntity();
indexerEntity.setName(indexerName);
indexer.initialize(config, indexerEntity);
item.setIndexer(indexer);
}
use of org.nzbhydra.config.IndexerConfig 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.config.IndexerConfig in project nzbhydra2 by theotherp.
the class IndexerStatusesCleanupTask method cleanup.
@HydraTask(configId = "cleanUpIndexerStatuses", name = "Clean up indexer statuses", interval = MINUTE)
public void cleanup() {
for (IndexerConfig config : configProvider.getBaseConfig().getIndexers()) {
if (config.getState() == IndexerConfig.State.DISABLED_SYSTEM_TEMPORARY && config.getDisabledUntil() != null && Instant.ofEpochMilli(config.getDisabledUntil()).isBefore(Instant.now())) {
// Do not reset the level. When the indexer is called the next time (when disabledUntil is in the past)
// and an error occurs the level is increased and the indexer gets disabled for a longer time
logger.debug("Setting indexer {} back to enabled after having been temporarily disabled until {}", config.getName(), Instant.ofEpochMilli(config.getDisabledUntil()));
config.setState(IndexerConfig.State.ENABLED);
config.setDisabledUntil(null);
config.setLastError(null);
}
}
configProvider.getBaseConfig().saveInternal();
}
use of org.nzbhydra.config.IndexerConfig in project nzbhydra2 by theotherp.
the class StatsComponentTest method setUp.
@Before
public void setUp() {
indexerRepository.deleteAll();
apiAccessRepository.deleteAll();
indexerConfig1 = new IndexerConfig();
indexerConfig1.setName("indexer1");
indexerConfig1.setSearchModuleType(SearchModuleType.NEWZNAB);
indexerConfig1.setState(IndexerConfig.State.ENABLED);
indexerConfig1.setHost("somehost");
indexerConfig2 = new IndexerConfig();
indexerConfig2.setName("indexer2");
indexerConfig2.setSearchModuleType(SearchModuleType.NEWZNAB);
indexerConfig2.setState(IndexerConfig.State.DISABLED_USER);
indexerConfig2.setHost("somehost");
searchModuleConfigProvider.setIndexers(Arrays.asList(indexerConfig1, indexerConfig2));
searchModuleProvider.loadIndexers(Arrays.asList(indexerConfig1, indexerConfig2));
indexer1 = indexerRepository.findByName("indexer1");
indexer2 = indexerRepository.findByName("indexer2");
}
Aggregations