Search in sources :

Example 1 with SearchResultItem

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;
}
Also used : Matcher(java.util.regex.Matcher) SearchResultItem(org.nzbhydra.searching.SearchResultItem) ArrayList(java.util.ArrayList) NewznabXmlItem(org.nzbhydra.mapping.newznab.xml.NewznabXmlItem)

Example 2 with SearchResultItem

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;
}
Also used : SearchResultItem(org.nzbhydra.searching.SearchResultItem) ArrayList(java.util.ArrayList) NewznabXmlItem(org.nzbhydra.mapping.newznab.xml.NewznabXmlItem)

Example 3 with SearchResultItem

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;
}
Also used : ArrayList(java.util.ArrayList) SearchResultItem(org.nzbhydra.searching.SearchResultItem)

Example 4 with SearchResultItem

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));
}
Also used : SearchRequest(org.nzbhydra.searching.searchrequests.SearchRequest) SearchResultItem(org.nzbhydra.searching.SearchResultItem) ArrayList(java.util.ArrayList) IndexerSearchResult(org.nzbhydra.searching.IndexerSearchResult) Test(org.junit.Test)

Example 5 with SearchResultItem

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");
}
Also used : SearchRequest(org.nzbhydra.searching.searchrequests.SearchRequest) SearchResultItem(org.nzbhydra.searching.SearchResultItem) NewznabXmlItem(org.nzbhydra.mapping.newznab.xml.NewznabXmlItem) Test(org.junit.Test)

Aggregations

SearchResultItem (org.nzbhydra.searching.SearchResultItem)12 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)5 NewznabXmlItem (org.nzbhydra.mapping.newznab.xml.NewznabXmlItem)3 Instant (java.time.Instant)2 Matcher (java.util.regex.Matcher)2 Element (org.jsoup.nodes.Element)2 SearchRequest (org.nzbhydra.searching.searchrequests.SearchRequest)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Document (org.jsoup.nodes.Document)1 Elements (org.jsoup.select.Elements)1 IndexerParsingException (org.nzbhydra.indexers.exceptions.IndexerParsingException)1 NewznabXmlEnclosure (org.nzbhydra.mapping.newznab.xml.NewznabXmlEnclosure)1 NewznabXmlGuid (org.nzbhydra.mapping.newznab.xml.NewznabXmlGuid)1 NewznabXmlRoot (org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot)1 IndexerSearchResult (org.nzbhydra.searching.IndexerSearchResult)1