Search in sources :

Example 1 with MediaInfo

use of org.nzbhydra.mediainfo.MediaInfo in project nzbhydra2 by theotherp.

the class Newznab method extendQueryUrlWithSearchIds.

protected UriComponentsBuilder extendQueryUrlWithSearchIds(SearchRequest searchRequest, UriComponentsBuilder componentsBuilder) throws IndexerSearchAbortedException {
    if (!searchRequest.getIdentifiers().isEmpty()) {
        Map<IdType, String> params = new HashMap<>();
        boolean indexerSupportsAnyOfTheProvidedIds = searchRequest.getIdentifiers().keySet().stream().anyMatch(x -> config.getSupportedSearchIds().contains(x));
        if (!indexerSupportsAnyOfTheProvidedIds) {
            boolean canConvertAnyId = infoProvider.canConvertAny(searchRequest.getIdentifiers().keySet(), new HashSet<>(config.getSupportedSearchIds()));
            if (canConvertAnyId) {
                try {
                    MediaInfo info = infoProvider.convert(searchRequest.getIdentifiers());
                    if (info.getImdbId().isPresent()) {
                        params.put(IdType.IMDB, info.getImdbId().get().replace("tt", ""));
                    }
                    if (info.getTmdbId().isPresent()) {
                        params.put(IdType.TMDB, info.getTmdbId().get());
                    }
                    if (info.getTvRageId().isPresent()) {
                        params.put(IdType.TVRAGE, info.getTvRageId().get());
                    }
                    if (info.getTvMazeId().isPresent()) {
                        params.put(IdType.TVMAZE, info.getTvMazeId().get());
                    }
                    if (info.getTvDbId().isPresent()) {
                        params.put(IdType.TVDB, info.getTvDbId().get());
                    }
                } catch (InfoProviderException e) {
                    error("Error while converting search ID", e);
                }
            }
        }
        searchRequest.getIdentifiers().putAll(params);
        for (Map.Entry<IdType, String> entry : searchRequest.getIdentifiers().entrySet()) {
            // We just add all IDs that we have. Some indexers support more than they say or will find results under one ID but not the other
            if (entry.getValue() == null) {
                continue;
            }
            componentsBuilder.queryParam(idTypeToParamValueMap.get(entry.getKey()), entry.getValue().replace("tt", ""));
        }
    }
    return componentsBuilder;
}
Also used : MediaInfo(org.nzbhydra.mediainfo.MediaInfo) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) InfoProviderException(org.nzbhydra.mediainfo.InfoProviderException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IdType(org.nzbhydra.mediainfo.InfoProvider.IdType)

Example 2 with MediaInfo

use of org.nzbhydra.mediainfo.MediaInfo in project nzbhydra2 by theotherp.

the class NewznabTest method shouldGenerateQueryIfFallbackRequested.

@Test
public void shouldGenerateQueryIfFallbackRequested() throws Exception {
    testee.config = new IndexerConfig();
    baseConfig.getSearching().setGenerateQueries(SearchSourceRestriction.BOTH);
    testee.config.setHost("http://www.indexer.com");
    testee.config.setSupportedSearchIds(Arrays.asList(IdType.TVDB));
    testee.config.setSupportedSearchTypes(Arrays.asList(ActionAttribute.TVSEARCH, ActionAttribute.SEARCH));
    SearchRequest searchRequest = new SearchRequest(SearchSource.INTERNAL, SearchType.TVSEARCH, 0, 100);
    searchRequest.getInternalData().setFallbackState(FallbackState.REQUESTED);
    searchRequest.getIdentifiers().put(IdType.TVDB, "tvdbId");
    when(infoProviderMock.canConvert(any(), any())).thenReturn(false);
    MediaInfo mediaInfo = new MediaInfo();
    mediaInfo.setTitle("someShow");
    when(infoProviderMock.convert("tvdbId", IdType.TVDB)).thenReturn(mediaInfo);
    assertEquals("someShow", testee.generateQueryIfApplicable(searchRequest, ""));
    // Don't add season/episode for fallback queries
    searchRequest.getInternalData().setFallbackState(FallbackState.REQUESTED);
    searchRequest.setSeason(1);
    searchRequest.setEpisode("1");
    assertEquals("someShow", testee.generateQueryIfApplicable(searchRequest, ""));
}
Also used : SearchRequest(org.nzbhydra.searching.searchrequests.SearchRequest) MediaInfo(org.nzbhydra.mediainfo.MediaInfo) Test(org.junit.Test)

Example 3 with MediaInfo

use of org.nzbhydra.mediainfo.MediaInfo in project nzbhydra2 by theotherp.

the class NewznabTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    testee = spy(testee);
    when(infoProviderMock.canConvert(IdType.IMDB, IdType.TMDB)).thenReturn(true);
    MediaInfo info = new MediaInfo();
    info.setImdbId("imdbId");
    info.setTmdbId("tmdbId");
    info.setTvmazeId("tvmazeId");
    info.setTvrageId("tvrageId");
    info.setTvdbId("tvdbId");
    when(infoProviderMock.convert("imdbId", IdType.IMDB)).thenReturn(info);
    when(infoProviderMock.convert(anyMap())).thenReturn(info);
    when(infoProviderMock.convert("tvmazeId", IdType.TVMAZE)).thenReturn(info);
    // when(indexerEntityMock.getStatus()).thenReturn(indexerStatusEntityMock);
    testee.config = new IndexerConfig();
    testee.config.setSupportedSearchIds(Lists.newArrayList(IdType.TMDB, IdType.TVRAGE));
    testee.config.setHost("http://127.0.0.1:1234");
    baseConfig = new BaseConfig();
    when(configProviderMock.getBaseConfig()).thenReturn(baseConfig);
    baseConfig.getSearching().setRemoveTrailing(Collections.emptyList());
    baseConfig.getSearching().setGenerateQueries(SearchSourceRestriction.NONE);
    when(resultAcceptorMock.acceptResults(any(), any(), any())).thenAnswer(new Answer<AcceptorResult>() {

        @Override
        public AcceptorResult answer(InvocationOnMock invocation) throws Throwable {
            return new AcceptorResult(invocation.getArgument(0), HashMultiset.create());
        }
    });
    animeCategory.setSubtype(Subtype.ANIME);
    when(categoryProviderMock.fromSubtype(Subtype.ANIME)).thenReturn(Optional.of(animeCategory));
    when(categoryProviderMock.fromSearchNewznabCategories(any(), any())).thenAnswer(x -> x.getArgument(1));
    when(categoryProviderMock.getNotAvailable()).thenReturn(naCategory);
}
Also used : AcceptorResult(org.nzbhydra.searching.SearchResultAcceptor.AcceptorResult) MediaInfo(org.nzbhydra.mediainfo.MediaInfo) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Before(org.junit.Before)

Example 4 with MediaInfo

use of org.nzbhydra.mediainfo.MediaInfo in project nzbhydra2 by theotherp.

the class NewznabTest method shouldGenerateQueryIfNecessaryAndAllowed.

@Test
public void shouldGenerateQueryIfNecessaryAndAllowed() throws Exception {
    testee.config = new IndexerConfig();
    baseConfig.getSearching().setGenerateQueries(SearchSourceRestriction.BOTH);
    testee.config.setHost("http://www.indexer.com");
    testee.config.setSupportedSearchIds(Collections.emptyList());
    SearchRequest searchRequest = new SearchRequest(SearchSource.INTERNAL, SearchType.SEARCH, 0, 100);
    searchRequest.getIdentifiers().put(IdType.IMDB, "imdbId");
    when(infoProviderMock.canConvert(any(), any())).thenReturn(false);
    MediaInfo mediaInfo = new MediaInfo();
    mediaInfo.setTitle("someMovie");
    when(infoProviderMock.convert("imdbId", IdType.IMDB)).thenReturn(mediaInfo);
    assertEquals(UriComponentsBuilder.fromHttpUrl("http://www.indexer.com/api?t=search&extended=1&imdbid=imdbId&q=someMovie").build(), testee.buildSearchUrl(searchRequest, null, null).build());
    // Should use title if provided
    searchRequest = new SearchRequest(SearchSource.INTERNAL, SearchType.SEARCH, 0, 100);
    searchRequest.setTitle("anotherTitle");
    UriComponents actual = testee.buildSearchUrl(searchRequest, null, null).build();
    assertEquals(UriComponentsBuilder.fromHttpUrl("http://www.indexer.com/api?t=search&extended=1&q=anotherTitle").build(), actual);
}
Also used : SearchRequest(org.nzbhydra.searching.searchrequests.SearchRequest) UriComponents(org.springframework.web.util.UriComponents) MediaInfo(org.nzbhydra.mediainfo.MediaInfo) Test(org.junit.Test)

Example 5 with MediaInfo

use of org.nzbhydra.mediainfo.MediaInfo in project nzbhydra2 by theotherp.

the class ExternalApiSearchingIntegrationTest method shouldGenerateQuery.

@Test
public void shouldGenerateQuery() throws Exception {
    prepareIndexerWithOneResponse();
    configProvider.getBaseConfig().getSearching().setGenerateQueries(SearchSourceRestriction.API);
    searchModuleProvider.getIndexers().get(0).getConfig().setSupportedSearchIds(Collections.emptyList());
    when(infoProvider.convert(anyMap())).thenReturn(new MediaInfo(new MovieInfo(null, null, "title", 0, null)));
    when(infoProvider.convert(any(), any())).thenReturn(new MediaInfo(new MovieInfo(null, null, "title", 0, null)));
    when(infoProvider.canConvertAny(anySet(), anySet())).thenReturn(false);
    NewznabXmlRoot root = (NewznabXmlRoot) externalApi.api(NewznabParameters.builder().tmdbid("abcd").t(ActionAttribute.MOVIE).apikey("apikey").build()).getBody();
    RecordedRequest request = webServer.takeRequest(2, TimeUnit.SECONDS);
    assertThat(request.getRequestUrl().queryParameter("q")).isEqualTo("title");
    assertThat(root.getRssChannel().getNewznabResponse().getTotal()).isEqualTo(1);
    assertThat(root.getRssChannel().getItems().size()).isEqualTo(1);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MediaInfo(org.nzbhydra.mediainfo.MediaInfo) NewznabXmlRoot(org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot) MovieInfo(org.nzbhydra.mediainfo.MovieInfo) Test(org.junit.Test) AbstractConfigReplacingTest(org.nzbhydra.tests.AbstractConfigReplacingTest) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

MediaInfo (org.nzbhydra.mediainfo.MediaInfo)8 Test (org.junit.Test)5 SearchRequest (org.nzbhydra.searching.searchrequests.SearchRequest)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 Before (org.junit.Before)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 NewznabXmlRoot (org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot)2 IdType (org.nzbhydra.mediainfo.InfoProvider.IdType)2 MovieInfo (org.nzbhydra.mediainfo.MovieInfo)2 TvInfo (org.nzbhydra.mediainfo.TvInfo)2 AcceptorResult (org.nzbhydra.searching.SearchResultAcceptor.AcceptorResult)2 AbstractConfigReplacingTest (org.nzbhydra.tests.AbstractConfigReplacingTest)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 BaseConfig (org.nzbhydra.config.BaseConfig)1 InfoProviderException (org.nzbhydra.mediainfo.InfoProviderException)1 UriComponents (org.springframework.web.util.UriComponents)1