Search in sources :

Example 1 with Xml

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());
    }
}
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 2 with Xml

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);
}
Also used : Xml(org.nzbhydra.mapping.newznab.xml.Xml) NewznabXmlRoot(org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot) Test(org.junit.Test)

Example 3 with Xml

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());
    }
}
Also used : 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)

Aggregations

NewznabXmlRoot (org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot)3 Xml (org.nzbhydra.mapping.newznab.xml.Xml)3 URI (java.net.URI)2 IndexerAccessException (org.nzbhydra.indexers.exceptions.IndexerAccessException)2 NewznabXmlError (org.nzbhydra.mapping.newznab.xml.NewznabXmlError)2 Strings (com.google.common.base.Strings)1 java.util (java.util)1 java.util.concurrent (java.util.concurrent)1 Collectors (java.util.stream.Collectors)1 AllArgsConstructor (lombok.AllArgsConstructor)1 Data (lombok.Data)1 Test (org.junit.Test)1 GenericResponse (org.nzbhydra.GenericResponse)1 ConfigProvider (org.nzbhydra.config.ConfigProvider)1 IndexerCategoryConfig (org.nzbhydra.config.IndexerCategoryConfig)1 MainCategory (org.nzbhydra.config.IndexerCategoryConfig.MainCategory)1 SubCategory (org.nzbhydra.config.IndexerCategoryConfig.SubCategory)1 IndexerConfig (org.nzbhydra.config.IndexerConfig)1 SearchModuleType (org.nzbhydra.config.SearchModuleType)1 BackendType (org.nzbhydra.indexers.Indexer.BackendType)1