Search in sources :

Example 11 with NewznabXmlRoot

use of org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot 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 12 with NewznabXmlRoot

use of org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot in project nzbhydra2 by theotherp.

the class DevIndexer method getAndStoreResultToDatabase.

protected Xml getAndStoreResultToDatabase(URI uri, IndexerApiAccessType apiAccessType) throws IndexerAccessException {
    NewznabXmlRoot rssRoot = new NewznabXmlRoot();
    if (uri.toString().contains("oneduplicate")) {
        NewznabMockRequest mockRequest = NewznabMockRequest.builder().numberOfResults(1).titleBase("oneresult").titleWords(Collections.emptyList()).total(1).build();
        rssRoot = NewznabMockBuilder.generateResponse(mockRequest);
        rssRoot.getRssChannel().getNewznabResponse().setTotal(1);
        rssRoot.getRssChannel().getItems().get(0).getEnclosure().setLength(100000L);
        rssRoot.getRssChannel().getItems().get(0).getNewznabAttributes().clear();
    } else if (uri.toString().contains("duplicatesandtitlegroups")) {
        // One duplicate
        NewznabMockRequest mockRequest = NewznabMockRequest.builder().numberOfResults(1).titleBase("oneresult").titleWords(Collections.emptyList()).total(1).build();
        rssRoot = NewznabMockBuilder.generateResponse(mockRequest);
        rssRoot.getRssChannel().getItems().get(0).getEnclosure().setLength(100000L);
        rssRoot.getRssChannel().getItems().get(0).getNewznabAttributes().clear();
        rssRoot.getRssChannel().getItems().get(0).getTorznabAttributes().clear();
        rssRoot.getRssChannel().getItems().get(0).getNewznabAttributes().add(new NewznabAttribute("grabs", "100"));
        // Another duplicate in the same title group
        mockRequest = NewznabMockRequest.builder().numberOfResults(1).titleBase("oneresult").titleWords(Collections.emptyList()).total(1).build();
        NewznabXmlRoot rssRoot3 = NewznabMockBuilder.generateResponse(mockRequest);
        rssRoot3.getRssChannel().getItems().get(0).getEnclosure().setLength(200000L);
        rssRoot3.getRssChannel().getItems().get(0).getNewznabAttributes().clear();
        rssRoot3.getRssChannel().getItems().get(0).getTorznabAttributes().clear();
        rssRoot3.getRssChannel().getItems().get(0).getNewznabAttributes().add(new NewznabAttribute("grabs", "2000"));
        // Otherwise it will result in a unique key exception
        rssRoot3.getRssChannel().getItems().get(0).setLink("anotherlink");
        rssRoot.getRssChannel().getItems().add(rssRoot3.getRssChannel().getItems().get(0));
        // Will be a grouped title but have no duplicates
        mockRequest = NewznabMockRequest.builder().numberOfResults(1).titleBase("anotherresult").titleWords(Collections.emptyList()).total(1).build();
        NewznabXmlRoot rssRoot2 = NewznabMockBuilder.generateResponse(mockRequest);
        rssRoot.getRssChannel().getItems().add(rssRoot2.getRssChannel().getItems().get(0));
        rssRoot.getRssChannel().getNewznabResponse().setTotal(3);
    } else if (uri.toString().contains("duplicates")) {
        NewznabMockRequest mockRequest = NewznabMockRequest.builder().numberOfResults(10).titleBase("duplicates").titleWords(Collections.emptyList()).total(10).build();
        rssRoot = NewznabMockBuilder.generateResponse(mockRequest);
        rssRoot.getRssChannel().getNewznabResponse().setTotal(10);
        for (NewznabXmlItem rssItem : rssRoot.getRssChannel().getItems()) {
            rssItem.getEnclosure().setLength(100000L);
            rssItem.getNewznabAttributes().clear();
            rssItem.setPubDate(Instant.now());
            rssItem.setDescription("Indexer: " + getName() + ", title:" + rssItem.getTitle());
        }
    } else if (uri.toString().contains("tworesults")) {
        rssRoot = NewznabMockBuilder.generateResponse(0, 2, "results", false, Collections.emptyList());
        rssRoot.getRssChannel().getNewznabResponse().setTotal(2);
    } else {
        rssRoot = NewznabMockBuilder.generateResponse(0, 100, "results", false, Collections.emptyList());
        rssRoot.getRssChannel().getNewznabResponse().setTotal(100);
    }
    if (uri.toString().contains("punkte")) {
        rssRoot.getRssChannel().getItems().get(0).setTitle("a a");
        rssRoot.getRssChannel().getItems().get(1).setTitle("ab");
        rssRoot.getRssChannel().getItems().get(2).setTitle("a.c");
    }
    return rssRoot;
}
Also used : NewznabXmlRoot(org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot) NewznabMockRequest(org.nzbhydra.mapping.newznab.mock.NewznabMockRequest) NewznabAttribute(org.nzbhydra.mapping.newznab.xml.NewznabAttribute) NewznabXmlItem(org.nzbhydra.mapping.newznab.xml.NewznabXmlItem)

Example 13 with NewznabXmlRoot

use of org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot in project nzbhydra2 by theotherp.

the class NewznabResponseBuilderTest method shouldInsertOffsetAndTotal.

@Test
public void shouldInsertOffsetAndTotal() {
    NewznabXmlRoot root = testee.getTestResult(1, 2, "itemTitle", null, null);
    assertEquals(0, root.getRssChannel().getNewznabResponse().getOffset().intValue());
    assertEquals(2, root.getRssChannel().getNewznabResponse().getTotal().intValue());
    root = testee.getTestResult(1, 2, "itemTitle", 2, 100);
    assertEquals(2, root.getRssChannel().getNewznabResponse().getOffset().intValue());
    assertEquals(100, root.getRssChannel().getNewznabResponse().getTotal().intValue());
}
Also used : NewznabXmlRoot(org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot) Test(org.junit.Test)

Example 14 with NewznabXmlRoot

use of org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot in project nzbhydra2 by theotherp.

the class NewznabResponseBuilderTest method shouldBuild.

@Test
public void shouldBuild() {
    NewznabXmlRoot root = testee.getTestResult(1, 2, "itemTitle", null, null);
    assertEquals(2, root.getRssChannel().getItems().size());
    assertEquals("itemTitle1", root.getRssChannel().getItems().get(0).getTitle());
    root = testee.getTestResult(3, 3, "itemTitle", null, null);
    assertEquals(1, root.getRssChannel().getItems().size());
    assertEquals("itemTitle3", root.getRssChannel().getItems().get(0).getTitle());
}
Also used : NewznabXmlRoot(org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot) Test(org.junit.Test)

Example 15 with NewznabXmlRoot

use of org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot in project nzbhydra2 by theotherp.

the class SearchingResultsUiTest method testMessageIfNoResults.

@Test
public void testMessageIfNoResults() throws Exception {
    replaceIndexers(Arrays.asList(IndexerConfigBuilder.builder().build()));
    NewznabXmlRoot rssRoot = NewznabMockBuilder.getRssRoot(Arrays.asList(), 0, 0);
    mockWebServer.enqueue(new MockResponse().setBody(rssRoot.toXmlString()).setHeader("Content-Type", "application/xml; charset=utf-8"));
    webDriver.get(url + "/?category=All&query=uitest&mode=search");
    WebDriverWait wait = new WebDriverWait(webDriver, 10);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("no-search-results")));
    SearchResultsPO searchResultsPage = factory.createPage(SearchResultsPO.class);
    assertThat(searchResultsPage.noSearchResultsWarning().text()).isEqualTo("No results were found for this search");
    assertThat(webDriver.findElements(By.className("search-results-table")).isEmpty()).isTrue();
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) NewznabXmlRoot(org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) NzbhydraMockMvcTest(org.nzbhydra.tests.NzbhydraMockMvcTest) Test(org.junit.Test) AbstractConfigReplacingTest(org.nzbhydra.tests.AbstractConfigReplacingTest)

Aggregations

NewznabXmlRoot (org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot)41 Test (org.junit.Test)30 MockResponse (okhttp3.mockwebserver.MockResponse)12 NewznabXmlItem (org.nzbhydra.mapping.newznab.xml.NewznabXmlItem)11 AbstractConfigReplacingTest (org.nzbhydra.tests.AbstractConfigReplacingTest)10 NewznabAttribute (org.nzbhydra.mapping.newznab.xml.NewznabAttribute)8 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 ArrayList (java.util.ArrayList)5 Dispatcher (okhttp3.mockwebserver.Dispatcher)4 NewznabXmlChannel (org.nzbhydra.mapping.newznab.xml.NewznabXmlChannel)4 NzbhydraMockMvcTest (org.nzbhydra.tests.NzbhydraMockMvcTest)4 URI (java.net.URI)3 NewznabResponseBuilder (org.nzbhydra.fortests.NewznabResponseBuilder)3 NewznabParameters (org.nzbhydra.mapping.newznab.NewznabParameters)3 NewznabXmlEnclosure (org.nzbhydra.mapping.newznab.xml.NewznabXmlEnclosure)3 NewznabXmlGuid (org.nzbhydra.mapping.newznab.xml.NewznabXmlGuid)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Matcher (java.util.regex.Matcher)2 NewznabXmlResponse (org.nzbhydra.mapping.newznab.xml.NewznabXmlResponse)2