Search in sources :

Example 1 with InfoProviderException

use of org.nzbhydra.mediainfo.InfoProviderException 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)

Aggregations

ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 IdType (org.nzbhydra.mediainfo.InfoProvider.IdType)1 InfoProviderException (org.nzbhydra.mediainfo.InfoProviderException)1 MediaInfo (org.nzbhydra.mediainfo.MediaInfo)1