use of org.nzbhydra.searching.SearchResultItem in project nzbhydra2 by theotherp.
the class NzbIndex method getSearchResultItems.
@Override
protected List<SearchResultItem> getSearchResultItems(NewznabXmlRoot rssRoot) {
if (rssRoot.getRssChannel().getItems() == null || rssRoot.getRssChannel().getItems().isEmpty()) {
debug("No results found");
return Collections.emptyList();
}
List<SearchResultItem> items = new ArrayList<>();
for (NewznabXmlItem rssItem : rssRoot.getRssChannel().getItems()) {
SearchResultItem item = new SearchResultItem();
item.setPubDate(rssItem.getPubDate());
String nzbIndexLink = rssItem.getLink();
// Use the NZB name as title because it's already somewhat cleaned up
item.setTitle(nzbIndexLink.substring(nzbIndexLink.lastIndexOf('/') + 1, nzbIndexLink.length() - 4));
item.setAgePrecise(true);
item.setGroup(rssItem.getCategory().replace("a.b", "alt.binaries"));
item.setLink(rssItem.getEnclosure().getUrl());
item.setSize(rssItem.getEnclosure().getLength());
Matcher matcher = GUID_PATTERN.matcher(nzbIndexLink);
boolean found = matcher.find();
if (!found) {
logger.error("Unable to parse '{}' result for link. Skipping it", nzbIndexLink);
continue;
}
item.setIndexerGuid(matcher.group(1));
item.setCategory(categoryProvider.getNotAvailable());
item.setOriginalCategory("N/A");
item.setIndexerScore(config.getScore().orElse(0));
item.setHasNfo(rssItem.getDescription().contains("1 NFO") ? HasNfo.YES : HasNfo.NO);
item.setIndexer(this);
item.setDownloadType(DownloadType.NZB);
items.add(item);
}
return items;
}
use of org.nzbhydra.searching.SearchResultItem in project nzbhydra2 by theotherp.
the class Anizb method getSearchResultItems.
@Override
protected List<SearchResultItem> getSearchResultItems(NewznabXmlRoot rssRoot) throws IndexerParsingException {
List<SearchResultItem> items = new ArrayList<>();
for (NewznabXmlItem rssItem : rssRoot.getRssChannel().getItems()) {
SearchResultItem item = new SearchResultItem();
item.setOriginalCategory("Anime");
item.setTitle(rssItem.getTitle());
item.setLink(rssItem.getLink());
item.setIndexerGuid(rssItem.getRssGuid().getGuid());
item.setSize(rssItem.getEnclosure().getLength());
item.setPubDate(rssItem.getPubDate());
item.setIndexerScore(config.getScore().orElse(0));
item.setHasNfo(HasNfo.NO);
item.setAgePrecise(true);
item.setCategory(categoryProvider.getByInternalName("Anime"));
item.setIndexer(this);
item.setDownloadType(DownloadType.NZB);
items.add(item);
}
return items;
}
use of org.nzbhydra.searching.SearchResultItem in project nzbhydra2 by theotherp.
the class NewznabJsonTransformer method transformToRoot.
NewznabJsonRoot transformToRoot(List<SearchResultItem> searchResultItems, Integer offset, int total, SearchRequest searchRequest) {
NewznabJsonRoot rssRoot = new NewznabJsonRoot();
NewznabJsonChannel channel = new NewznabJsonChannel();
channel.setTitle("NZBHydra 2");
channel.setLink("https://www.github.com/theotherp/nzbhydra2");
channel.setWebMaster("theotherp@gmx.de");
channel.setResponse(new NewznabJsonChannelResponse(new NewznabJsonResponseAttributes(offset, total)));
channel.setGenerator("NZBHydra2");
rssRoot.setChannel(channel);
List<NewznabJsonItem> items = new ArrayList<>();
for (SearchResultItem searchResultItem : searchResultItems) {
NewznabJsonItem rssItem = buildRssItem(searchResultItem, searchRequest);
items.add(rssItem);
}
channel.setItem(items);
return rssRoot;
}
use of org.nzbhydra.searching.SearchResultItem in project nzbhydra2 by theotherp.
the class BinsearchTest method shouldRecognizeIfSingleResultPage.
@Test
public void shouldRecognizeIfSingleResultPage() throws Exception {
SearchRequest searchRequest = new SearchRequest(SearchSource.INTERNAL, SearchType.SEARCH, 0, 100);
String html = Resources.toString(Resources.getResource(BinsearchTest.class, "/org/nzbhydra/mapping/binsearch_singlepage.html"), Charsets.UTF_8);
IndexerSearchResult indexerSearchResult = new IndexerSearchResult(testee, "");
List<SearchResultItem> items = new ArrayList<>();
for (int i = 0; i < 24; i++) {
items.add(new SearchResultItem());
}
indexerSearchResult.setSearchResultItems(items);
testee.completeIndexerSearchResult(html, indexerSearchResult, null, searchRequest);
assertThat(indexerSearchResult.getOffset(), is(0));
assertThat(indexerSearchResult.getLimit(), is(100));
assertThat(indexerSearchResult.getTotalResults(), is(24));
assertThat(indexerSearchResult.isTotalResultsKnown(), is(true));
assertThat(indexerSearchResult.isHasMoreResults(), is(false));
}
use of org.nzbhydra.searching.SearchResultItem in project nzbhydra2 by theotherp.
the class NewznabXmlTransformerTest method shouldUseCorrectApplicationType.
@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);
assertThat(item.getEnclosure().getType()).isEqualTo("application/x-nzb");
searchRequest.setDownloadType(DownloadType.TORRENT);
item = testee.buildRssItem(searchResultItem, searchRequest);
assertThat(item.getEnclosure().getType()).isEqualTo("application/x-bittorrent");
}
Aggregations