Search in sources :

Example 1 with CapsCategory

use of org.nzbhydra.mapping.newznab.caps.CapsCategory in project nzbhydra2 by theotherp.

the class NewznabChecker method readAndConvertCategories.

private List<CapsCategory> readAndConvertCategories(CapsRoot capsRoot, IndexerCategoryConfig categoryConfig) {
    List<CapsCategory> categories = new ArrayList<>(capsRoot.getCategories().getCategories());
    List<MainCategory> configMainCategories = new ArrayList<>();
    for (CapsCategory category : capsRoot.getCategories().getCategories()) {
        List<SubCategory> configSubcats = new ArrayList<>();
        if (category.getSubCategories() != null) {
            categories.addAll(category.getSubCategories());
            configSubcats = category.getSubCategories().stream().map(x -> new SubCategory(x.getId(), x.getName())).collect(Collectors.toList());
        }
        configMainCategories.add(new MainCategory(category.getId(), category.getName(), configSubcats));
    }
    categoryConfig.setCategories(configMainCategories);
    return categories;
}
Also used : SubCategory(org.nzbhydra.config.IndexerCategoryConfig.SubCategory) CapsCategory(org.nzbhydra.mapping.newznab.caps.CapsCategory) MainCategory(org.nzbhydra.config.IndexerCategoryConfig.MainCategory)

Example 2 with CapsCategory

use of org.nzbhydra.mapping.newznab.caps.CapsCategory in project nzbhydra2 by theotherp.

the class RssCapsMappingTest method shouldGenerateCorrectXml.

@Test
public void shouldGenerateCorrectXml() throws JsonProcessingException, JAXBException {
    CapsRoot caps = new CapsRoot();
    List<CapsCategory> categories = new ArrayList<>();
    CapsCategory capsCategory = new CapsCategory(1000, "1000");
    List<CapsCategory> subCats = new ArrayList<>();
    subCats.add(new CapsCategory(1010, "1010"));
    capsCategory.setSubCategories(subCats);
    caps.getCategories().getCategories().add(capsCategory);
    StringWriter writer = new StringWriter();
    StreamResult streamResult = new StreamResult(writer);
    jaxb2Marshaller.marshal(caps, streamResult);
    assertThat(writer.toString(), containsString("<categories>\n" + "        <category id=\"1000\" name=\"1000\">\n" + "            <subcat id=\"1010\" name=\"1010\"/>\n" + "        </category>\n" + "    </categories>"));
}
Also used : StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) CapsRoot(org.nzbhydra.mapping.newznab.caps.CapsRoot) ArrayList(java.util.ArrayList) CapsCategory(org.nzbhydra.mapping.newznab.caps.CapsCategory) Test(org.junit.Test)

Example 3 with CapsCategory

use of org.nzbhydra.mapping.newznab.caps.CapsCategory 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

CapsCategory (org.nzbhydra.mapping.newznab.caps.CapsCategory)3 CapsRoot (org.nzbhydra.mapping.newznab.caps.CapsRoot)2 StringWriter (java.io.StringWriter)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 StreamResult (javax.xml.transform.stream.StreamResult)1 Test (org.junit.Test)1 IndexerCategoryConfig (org.nzbhydra.config.IndexerCategoryConfig)1 MainCategory (org.nzbhydra.config.IndexerCategoryConfig.MainCategory)1 SubCategory (org.nzbhydra.config.IndexerCategoryConfig.SubCategory)1 ActionAttribute (org.nzbhydra.mapping.newznab.ActionAttribute)1 IdType (org.nzbhydra.mediainfo.InfoProvider.IdType)1