@Test public void shouldUseCorrectApplicationType() { SearchRequest searchRequest = new SearchRequest(SearchSource.INTERNAL, SearchType.SEARCH, 0, 100); SearchResultItem searchResultItem = new SearchResultItem(); searchResultItem.setIndexer(indexerMock); searchResultItem.setCategory(new Category()); searchRequest.setDownloadType(DownloadType.NZB); NewznabXmlItem item = testee.buildRssItem(searchResultItem, searchRequest.getDownloadType() == DownloadType.NZB); assertThat(item.getEnclosure().getType()).isEqualTo("application/x-nzb"); searchRequest.setDownloadType(DownloadType.TORRENT); item = testee.buildRssItem(searchResultItem, searchRequest.getDownloadType() == DownloadType.NZB); assertThat(item.getEnclosure().getType()).isEqualTo("application/x-bittorrent"); }
NewznabXmlItem buildRssItem(SearchResultItem searchResultItem, boolean isNzb) { NewznabXmlItem rssItem = new NewznabXmlItem(); String link = nzbHandler.getDownloadLinkForResults(searchResultItem.getSearchResultId(), false, isNzb ? DownloadType.NZB : DownloadType.TORRENT); rssItem.setLink(link); rssItem.setTitle(searchResultItem.getTitle()); rssItem.setRssGuid(new NewznabXmlGuid(String.valueOf(searchResultItem.getGuid()), false)); rssItem.setSize(searchResultItem.getSize()); if (searchResultItem.getPubDate() != null) { rssItem.setPubDate(searchResultItem.getPubDate()); } else { rssItem.setPubDate(searchResultItem.getBestDate()); } searchResultItem.getAttributes().put("guid", String.valueOf(searchResultItem.getSearchResultId())); List<NewznabAttribute> newznabAttributes = searchResultItem.getAttributes().entrySet().stream().map(attribute -> new NewznabAttribute(attribute.getKey(), attribute.getValue())).sorted(Comparator.comparing(NewznabAttribute::getName)).collect(Collectors.toList()); if (searchResultItem.getIndexer() != null) { newznabAttributes.add(new NewznabAttribute("hydraIndexerScore", String.valueOf(searchResultItem.getIndexer().getConfig().getScore()))); newznabAttributes.add(new NewznabAttribute("hydraIndexerHost", getIndexerHost(searchResultItem))); newznabAttributes.add(new NewznabAttribute("hydraIndexerName", String.valueOf(searchResultItem.getIndexer().getName()))); } String resultType; if (isNzb) { rssItem.setNewznabAttributes(newznabAttributes); resultType = APPLICATION_TYPE_NZB; } else { rssItem.setTorznabAttributes(newznabAttributes); resultType = APPLICATION_TYPE_TORRENT; } rssItem.setEnclosure(new NewznabXmlEnclosure(link, searchResultItem.getSize(), resultType)); rssItem.setComments(searchResultItem.getCommentsLink()); rssItem.setDescription(searchResultItem.getDescription()); rssItem.setCategory(configProvider.getBaseConfig().getSearching().isUseOriginalCategories() ? searchResultItem.getOriginalCategory() : searchResultItem.getCategory().getName()); return rssItem; }
NewznabXmlTransformer { NewznabXmlItem buildRssItem(SearchResultItem searchResultItem, boolean isNzb) { NewznabXmlItem rssItem = new NewznabXmlItem(); String link = nzbHandler.getDownloadLinkForResults(searchResultItem.getSearchResultId(), false, isNzb ? DownloadType.NZB : DownloadType.TORRENT); rssItem.setLink(link); rssItem.setTitle(searchResultItem.getTitle()); rssItem.setRssGuid(new NewznabXmlGuid(String.valueOf(searchResultItem.getGuid()), false)); rssItem.setSize(searchResultItem.getSize()); if (searchResultItem.getPubDate() != null) { rssItem.setPubDate(searchResultItem.getPubDate()); } else { rssItem.setPubDate(searchResultItem.getBestDate()); } searchResultItem.getAttributes().put("guid", String.valueOf(searchResultItem.getSearchResultId())); List<NewznabAttribute> newznabAttributes = searchResultItem.getAttributes().entrySet().stream().map(attribute -> new NewznabAttribute(attribute.getKey(), attribute.getValue())).sorted(Comparator.comparing(NewznabAttribute::getName)).collect(Collectors.toList()); if (searchResultItem.getIndexer() != null) { newznabAttributes.add(new NewznabAttribute("hydraIndexerScore", String.valueOf(searchResultItem.getIndexer().getConfig().getScore()))); newznabAttributes.add(new NewznabAttribute("hydraIndexerHost", getIndexerHost(searchResultItem))); newznabAttributes.add(new NewznabAttribute("hydraIndexerName", String.valueOf(searchResultItem.getIndexer().getName()))); } String resultType; if (isNzb) { rssItem.setNewznabAttributes(newznabAttributes); resultType = APPLICATION_TYPE_NZB; } else { rssItem.setTorznabAttributes(newznabAttributes); resultType = APPLICATION_TYPE_TORRENT; } rssItem.setEnclosure(new NewznabXmlEnclosure(link, searchResultItem.getSize(), resultType)); rssItem.setComments(searchResultItem.getCommentsLink()); rssItem.setDescription(searchResultItem.getDescription()); rssItem.setCategory(configProvider.getBaseConfig().getSearching().isUseOriginalCategories() ? searchResultItem.getOriginalCategory() : searchResultItem.getCategory().getName()); return rssItem; } }
NewznabXmlTransformer { NewznabXmlItem buildRssItem(SearchResultItem searchResultItem, boolean isNzb) { NewznabXmlItem rssItem = new NewznabXmlItem(); String link = nzbHandler.getDownloadLinkForResults(searchResultItem.getSearchResultId(), false, isNzb ? DownloadType.NZB : DownloadType.TORRENT); rssItem.setLink(link); rssItem.setTitle(searchResultItem.getTitle()); rssItem.setRssGuid(new NewznabXmlGuid(String.valueOf(searchResultItem.getGuid()), false)); rssItem.setSize(searchResultItem.getSize()); if (searchResultItem.getPubDate() != null) { rssItem.setPubDate(searchResultItem.getPubDate()); } else { rssItem.setPubDate(searchResultItem.getBestDate()); } searchResultItem.getAttributes().put("guid", String.valueOf(searchResultItem.getSearchResultId())); List<NewznabAttribute> newznabAttributes = searchResultItem.getAttributes().entrySet().stream().map(attribute -> new NewznabAttribute(attribute.getKey(), attribute.getValue())).sorted(Comparator.comparing(NewznabAttribute::getName)).collect(Collectors.toList()); if (searchResultItem.getIndexer() != null) { newznabAttributes.add(new NewznabAttribute("hydraIndexerScore", String.valueOf(searchResultItem.getIndexer().getConfig().getScore()))); newznabAttributes.add(new NewznabAttribute("hydraIndexerHost", getIndexerHost(searchResultItem))); newznabAttributes.add(new NewznabAttribute("hydraIndexerName", String.valueOf(searchResultItem.getIndexer().getName()))); } String resultType; if (isNzb) { rssItem.setNewznabAttributes(newznabAttributes); resultType = APPLICATION_TYPE_NZB; } else { rssItem.setTorznabAttributes(newznabAttributes); resultType = APPLICATION_TYPE_TORRENT; } rssItem.setEnclosure(new NewznabXmlEnclosure(link, searchResultItem.getSize(), resultType)); rssItem.setComments(searchResultItem.getCommentsLink()); rssItem.setDescription(searchResultItem.getDescription()); rssItem.setCategory(configProvider.getBaseConfig().getSearching().isUseOriginalCategories() ? searchResultItem.getOriginalCategory() : searchResultItem.getCategory().getName()); return rssItem; }  }
NewznabXmlTransformer { NewznabXmlItem buildRssItem(SearchResultItem searchResultItem, boolean isNzb) { NewznabXmlItem rssItem = new NewznabXmlItem(); String link = nzbHandler.getDownloadLinkForResults(searchResultItem.getSearchResultId(), false, isNzb ? DownloadType.NZB : DownloadType.TORRENT); rssItem.setLink(link); rssItem.setTitle(searchResultItem.getTitle()); rssItem.setRssGuid(new NewznabXmlGuid(String.valueOf(searchResultItem.getGuid()), false)); rssItem.setSize(searchResultItem.getSize()); if (searchResultItem.getPubDate() != null) { rssItem.setPubDate(searchResultItem.getPubDate()); } else { rssItem.setPubDate(searchResultItem.getBestDate()); } searchResultItem.getAttributes().put("guid", String.valueOf(searchResultItem.getSearchResultId())); List<NewznabAttribute> newznabAttributes = searchResultItem.getAttributes().entrySet().stream().map(attribute -> new NewznabAttribute(attribute.getKey(), attribute.getValue())).sorted(Comparator.comparing(NewznabAttribute::getName)).collect(Collectors.toList()); if (searchResultItem.getIndexer() != null) { newznabAttributes.add(new NewznabAttribute("hydraIndexerScore", String.valueOf(searchResultItem.getIndexer().getConfig().getScore()))); newznabAttributes.add(new NewznabAttribute("hydraIndexerHost", getIndexerHost(searchResultItem))); newznabAttributes.add(new NewznabAttribute("hydraIndexerName", String.valueOf(searchResultItem.getIndexer().getName()))); } String resultType; if (isNzb) { rssItem.setNewznabAttributes(newznabAttributes); resultType = APPLICATION_TYPE_NZB; } else { rssItem.setTorznabAttributes(newznabAttributes); resultType = APPLICATION_TYPE_TORRENT; } rssItem.setEnclosure(new NewznabXmlEnclosure(link, searchResultItem.getSize(), resultType)); rssItem.setComments(searchResultItem.getCommentsLink()); rssItem.setDescription(searchResultItem.getDescription()); rssItem.setCategory(configProvider.getBaseConfig().getSearching().isUseOriginalCategories() ? searchResultItem.getOriginalCategory() : searchResultItem.getCategory().getName()); return rssItem; }   }
NewznabXmlTransformer { NewznabXmlItem buildRssItem(SearchResultItem searchResultItem, boolean isNzb) { NewznabXmlItem rssItem = new NewznabXmlItem(); String link = nzbHandler.getDownloadLinkForResults(searchResultItem.getSearchResultId(), false, isNzb ? DownloadType.NZB : DownloadType.TORRENT); rssItem.setLink(link); rssItem.setTitle(searchResultItem.getTitle()); rssItem.setRssGuid(new NewznabXmlGuid(String.valueOf(searchResultItem.getGuid()), false)); rssItem.setSize(searchResultItem.getSize()); if (searchResultItem.getPubDate() != null) { rssItem.setPubDate(searchResultItem.getPubDate()); } else { rssItem.setPubDate(searchResultItem.getBestDate()); } searchResultItem.getAttributes().put("guid", String.valueOf(searchResultItem.getSearchResultId())); List<NewznabAttribute> newznabAttributes = searchResultItem.getAttributes().entrySet().stream().map(attribute -> new NewznabAttribute(attribute.getKey(), attribute.getValue())).sorted(Comparator.comparing(NewznabAttribute::getName)).collect(Collectors.toList()); if (searchResultItem.getIndexer() != null) { newznabAttributes.add(new NewznabAttribute("hydraIndexerScore", String.valueOf(searchResultItem.getIndexer().getConfig().getScore()))); newznabAttributes.add(new NewznabAttribute("hydraIndexerHost", getIndexerHost(searchResultItem))); newznabAttributes.add(new NewznabAttribute("hydraIndexerName", String.valueOf(searchResultItem.getIndexer().getName()))); } String resultType; if (isNzb) { rssItem.setNewznabAttributes(newznabAttributes); resultType = APPLICATION_TYPE_NZB; } else { rssItem.setTorznabAttributes(newznabAttributes); resultType = APPLICATION_TYPE_TORRENT; } rssItem.setEnclosure(new NewznabXmlEnclosure(link, searchResultItem.getSize(), resultType)); rssItem.setComments(searchResultItem.getCommentsLink()); rssItem.setDescription(searchResultItem.getDescription()); rssItem.setCategory(configProvider.getBaseConfig().getSearching().isUseOriginalCategories() ? searchResultItem.getOriginalCategory() : searchResultItem.getCategory().getName()); return rssItem; }    }