Search in sources :

Example 1 with IndexerCategoryConfig

use of org.nzbhydra.config.IndexerCategoryConfig in project nzbhydra2 by theotherp.

the class Experiments method createSimpleYaml.

@Test
@Ignore
public void createSimpleYaml() throws IOException, InterruptedException {
    ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
    objectMapper.registerModule(new Jdk8Module());
    IndexerConfig indexerConfig = new IndexerConfig();
    indexerConfig.setCategoryMapping(new IndexerCategoryConfig());
    BaseConfig baseConfig = new BaseConfig();
    baseConfig.setIndexers(Arrays.asList(indexerConfig));
    String s = objectMapper.writeValueAsString(baseConfig);
    System.out.println(s);
    objectMapper.readValue(s, BaseConfig.class);
}
Also used : Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) IndexerConfig(org.nzbhydra.config.IndexerConfig) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) IndexerCategoryConfig(org.nzbhydra.config.IndexerCategoryConfig) BaseConfig(org.nzbhydra.config.BaseConfig) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with IndexerCategoryConfig

use of org.nzbhydra.config.IndexerCategoryConfig in project nzbhydra2 by theotherp.

the class Newznab method computeCategory.

protected void computeCategory(SearchResultItem searchResultItem, List<Integer> newznabCategories) {
    if (!newznabCategories.isEmpty()) {
        Integer mostSpecific = newznabCategories.stream().max(Integer::compareTo).get();
        IndexerCategoryConfig mapping = config.getCategoryMapping();
        Category category;
        if (mapping == null) {
            // May be the case in some corner cases
            category = categoryProvider.fromSearchNewznabCategories(newznabCategories, categoryProvider.getNotAvailable());
            searchResultItem.setOriginalCategory(categoryProvider.getNotAvailable().getName());
        } else {
            category = idToCategory.computeIfAbsent(mostSpecific, x -> {
                Optional<Category> categoryOptional = Optional.empty();
                if (mapping.getAnime().isPresent() && Objects.equals(mapping.getAnime().get(), mostSpecific)) {
                    categoryOptional = categoryProvider.fromSubtype(Subtype.ANIME);
                } else if (mapping.getAudiobook().isPresent() && Objects.equals(mapping.getAudiobook().get(), mostSpecific)) {
                    categoryOptional = categoryProvider.fromSubtype(Subtype.AUDIOBOOK);
                } else if (mapping.getEbook().isPresent() && Objects.equals(mapping.getEbook().get(), mostSpecific)) {
                    categoryOptional = categoryProvider.fromSubtype(Subtype.EBOOK);
                } else if (mapping.getComic().isPresent() && Objects.equals(mapping.getComic().get(), mostSpecific)) {
                    categoryOptional = categoryProvider.fromSubtype(Subtype.COMIC);
                } else if (mapping.getMagazine().isPresent() && Objects.equals(mapping.getMagazine().get(), mostSpecific)) {
                    categoryOptional = categoryProvider.fromSubtype(Subtype.MAGAZINE);
                }
                return categoryOptional.orElse(categoryProvider.fromResultNewznabCategories(newznabCategories));
            });
            // Use the indexer's own category mapping to build the category name
            searchResultItem.setOriginalCategory(mapping.getNameFromId(mostSpecific));
        }
        searchResultItem.setCategory(category);
    } else {
        searchResultItem.setCategory(categoryProvider.getNotAvailable());
    }
}
Also used : AcceptorResult(org.nzbhydra.searching.SearchResultAcceptor.AcceptorResult) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) Setter(lombok.Setter) java.util(java.util) Getter(lombok.Getter) org.nzbhydra.searching(org.nzbhydra.searching) StreamSource(javax.xml.transform.stream.StreamSource) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) SearchModuleType(org.nzbhydra.config.SearchModuleType) Unmarshaller(org.springframework.oxm.Unmarshaller) Subtype(org.nzbhydra.config.Category.Subtype) Strings(com.google.common.base.Strings) Matcher(java.util.regex.Matcher) URI(java.net.URI) Category(org.nzbhydra.config.Category) org.nzbhydra.indexers.exceptions(org.nzbhydra.indexers.exceptions) HasNfo(org.nzbhydra.searching.SearchResultItem.HasNfo) Order(org.springframework.core.annotation.Order) SearchRequest(org.nzbhydra.searching.searchrequests.SearchRequest) Logger(org.slf4j.Logger) IndexerConfig(org.nzbhydra.config.IndexerConfig) InfoProviderException(org.nzbhydra.mediainfo.InfoProviderException) MediaInfo(org.nzbhydra.mediainfo.MediaInfo) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) org.nzbhydra.mapping.newznab.xml(org.nzbhydra.mapping.newznab.xml) IdType(org.nzbhydra.mediainfo.InfoProvider.IdType) IOException(java.io.IOException) Instant(java.time.Instant) IndexerCategoryConfig(org.nzbhydra.config.IndexerCategoryConfig) DownloadType(org.nzbhydra.searching.SearchResultItem.DownloadType) Collectors(java.util.stream.Collectors) ActionAttribute(org.nzbhydra.mapping.newznab.ActionAttribute) Component(org.springframework.stereotype.Component) Stream(java.util.stream.Stream) StringReader(java.io.StringReader) Pattern(java.util.regex.Pattern) Joiner(com.google.common.base.Joiner) Category(org.nzbhydra.config.Category) IndexerCategoryConfig(org.nzbhydra.config.IndexerCategoryConfig)

Example 3 with IndexerCategoryConfig

use of org.nzbhydra.config.IndexerCategoryConfig in project nzbhydra2 by theotherp.

the class NewznabChecker method setSupportedSearchTypesAndIndexerCategoryMapping.

public IndexerCategoryConfig setSupportedSearchTypesAndIndexerCategoryMapping(IndexerConfig indexerConfig, int timeout) throws IndexerAccessException {
    List<IdType> supportedSearchIds = indexerConfig.getSupportedSearchIds();
    List<ActionAttribute> supportedSearchTypes = new ArrayList<>();
    if (supportedSearchIds.contains(IdType.TVDB) || supportedSearchIds.contains(IdType.TVRAGE) || supportedSearchIds.contains(IdType.TVMAZE) || supportedSearchIds.contains(IdType.TRAKT)) {
        supportedSearchTypes.add(ActionAttribute.TVSEARCH);
    }
    if (supportedSearchIds.contains(IdType.IMDB) || supportedSearchIds.contains(IdType.TMDB)) {
        supportedSearchTypes.add(ActionAttribute.MOVIE);
    }
    URI uri = getBaseUri(indexerConfig).queryParam("t", "caps").build().toUri();
    CapsRoot capsRoot = indexerWebAccess.get(uri, indexerConfig);
    if (capsRoot.getSearching().getAudioSearch() != null) {
        supportedSearchTypes.add(ActionAttribute.AUDIO);
    }
    if (capsRoot.getSearching().getBookSearch() != null) {
        supportedSearchTypes.add(ActionAttribute.BOOK);
    }
    indexerConfig.setSupportedSearchTypes(supportedSearchTypes);
    IndexerCategoryConfig categoryConfig = new IndexerCategoryConfig();
    List<CapsCategory> categories = readAndConvertCategories(capsRoot, categoryConfig);
    setCategorySpecificMappings(categoryConfig, categories);
    return categoryConfig;
}
Also used : CapsRoot(org.nzbhydra.mapping.newznab.caps.CapsRoot) IndexerCategoryConfig(org.nzbhydra.config.IndexerCategoryConfig) URI(java.net.URI) CapsCategory(org.nzbhydra.mapping.newznab.caps.CapsCategory) ActionAttribute(org.nzbhydra.mapping.newznab.ActionAttribute) IdType(org.nzbhydra.mediainfo.InfoProvider.IdType)

Aggregations

IndexerCategoryConfig (org.nzbhydra.config.IndexerCategoryConfig)3 URI (java.net.URI)2 IndexerConfig (org.nzbhydra.config.IndexerConfig)2 ActionAttribute (org.nzbhydra.mapping.newznab.ActionAttribute)2 IdType (org.nzbhydra.mediainfo.InfoProvider.IdType)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)1 Jdk8Module (com.fasterxml.jackson.datatype.jdk8.Jdk8Module)1 Joiner (com.google.common.base.Joiner)1 Strings (com.google.common.base.Strings)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 Instant (java.time.Instant)1 java.util (java.util)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 StreamSource (javax.xml.transform.stream.StreamSource)1