Search in sources :

Example 1 with IndexerConfig

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();
}
Also used : IndexerConfig(org.nzbhydra.config.IndexerConfig) Before(org.junit.Before)

Example 2 with 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);
}
Also used : Newznab(org.nzbhydra.indexers.Newznab) IndexerConfig(org.nzbhydra.config.IndexerConfig) IndexerEntity(org.nzbhydra.indexers.IndexerEntity)

Example 3 with IndexerConfig

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());
    }
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) java.util(java.util) NewznabXmlRoot(org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) SearchModuleType(org.nzbhydra.config.SearchModuleType) MainCategory(org.nzbhydra.config.IndexerCategoryConfig.MainCategory) Strings(com.google.common.base.Strings) GenericResponse(org.nzbhydra.GenericResponse) Newznab(org.nzbhydra.indexers.Newznab) ConfigProvider(org.nzbhydra.config.ConfigProvider) BackendType(org.nzbhydra.indexers.Indexer.BackendType) Xml(org.nzbhydra.mapping.newznab.xml.Xml) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) SubCategory(org.nzbhydra.config.IndexerCategoryConfig.SubCategory) CheckType(org.nzbhydra.indexers.capscheck.CapsCheckRequest.CheckType) CapsRoot(org.nzbhydra.mapping.newznab.caps.CapsRoot) URI(java.net.URI) IndexerWebAccess(org.nzbhydra.indexers.IndexerWebAccess) Logger(org.slf4j.Logger) IndexerConfig(org.nzbhydra.config.IndexerConfig) CapsCategory(org.nzbhydra.mapping.newznab.caps.CapsCategory) NewznabXmlError(org.nzbhydra.mapping.newznab.xml.NewznabXmlError) java.util.concurrent(java.util.concurrent) IdType(org.nzbhydra.mediainfo.InfoProvider.IdType) IndexerCategoryConfig(org.nzbhydra.config.IndexerCategoryConfig) Collectors(java.util.stream.Collectors) ActionAttribute(org.nzbhydra.mapping.newznab.ActionAttribute) Component(org.springframework.stereotype.Component) Data(lombok.Data) MdcThreadPoolExecutor(org.nzbhydra.logging.MdcThreadPoolExecutor) AllArgsConstructor(lombok.AllArgsConstructor) IndexerAccessException(org.nzbhydra.indexers.exceptions.IndexerAccessException) NewznabXmlError(org.nzbhydra.mapping.newznab.xml.NewznabXmlError) Xml(org.nzbhydra.mapping.newznab.xml.Xml) NewznabXmlRoot(org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot) IndexerAccessException(org.nzbhydra.indexers.exceptions.IndexerAccessException) URI(java.net.URI)

Example 4 with IndexerConfig

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();
}
Also used : IndexerConfig(org.nzbhydra.config.IndexerConfig) HydraTask(org.nzbhydra.tasks.HydraTask)

Example 5 with IndexerConfig

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");
}
Also used : IndexerConfig(org.nzbhydra.config.IndexerConfig) Before(org.junit.Before)

Aggregations

IndexerConfig (org.nzbhydra.config.IndexerConfig)11 Before (org.junit.Before)4 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 Test (org.junit.Test)2 IndexerCategoryConfig (org.nzbhydra.config.IndexerCategoryConfig)2 Newznab (org.nzbhydra.indexers.Newznab)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Component (org.springframework.stereotype.Component)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)1 Jdk8Module (com.fasterxml.jackson.datatype.jdk8.Jdk8Module)1 Stopwatch (com.google.common.base.Stopwatch)1 Strings (com.google.common.base.Strings)1 URI (java.net.URI)1 Timestamp (java.sql.Timestamp)1 java.util.concurrent (java.util.concurrent)1 Query (javax.persistence.Query)1