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;
}
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, ""));
}
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);
}
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);
}
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);
}
Aggregations