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