Search in sources :

Example 6 with SearchResultItem

use of org.nzbhydra.searching.SearchResultItem in project nzbhydra2 by theotherp.

the class NewznabXmlTransformer method getRssRoot.

NewznabXmlRoot getRssRoot(List<SearchResultItem> searchResultItems, Integer offset, int total, SearchRequest searchRequest) {
    NewznabXmlRoot rssRoot = new NewznabXmlRoot();
    NewznabXmlChannel rssChannel = new NewznabXmlChannel();
    rssChannel.setTitle("NZBHydra 2");
    rssChannel.setLink("https://www.github.com/theotherp/nzbhydra2");
    rssChannel.setWebMaster("theotherp@gmx.de");
    if (searchRequest.getDownloadType() == org.nzbhydra.searching.DownloadType.NZB) {
        rssChannel.setNewznabResponse(new NewznabXmlResponse(offset == null ? 0 : offset, total));
    }
    rssChannel.setGenerator("NZBHydra2");
    rssRoot.setRssChannel(rssChannel);
    List<NewznabXmlItem> items = new ArrayList<>();
    for (SearchResultItem searchResultItem : searchResultItems) {
        NewznabXmlItem rssItem = buildRssItem(searchResultItem, searchRequest);
        items.add(rssItem);
    }
    rssChannel.setItems(items);
    return rssRoot;
}
Also used : ArrayList(java.util.ArrayList) SearchResultItem(org.nzbhydra.searching.SearchResultItem)

Example 7 with SearchResultItem

use of org.nzbhydra.searching.SearchResultItem in project nzbhydra2 by theotherp.

the class NzbIndexTest method shouldParseRows.

@Test
public void shouldParseRows() throws Exception {
    Instant now = Instant.now();
    String enclosureUrl = "http://nzbindex.com/download/164950363/Watchers.of.the.Universe.S02E09.1080p.WEB-DL.DD5.1.AAC2.0.H.264-YFN-0030-Watchers.of.the.Universe.S02E09.Cant.Get.You.out.of.My.Head.1080p.WEB-DL.nzb";
    String link = "http://nzbindex.com/release/164950363/Watchers.of.the.Universe.S02E09.1080p.WEB-DL.DD5.1.AAC2.0.H.264-YFN-0030-Watchers.of.the.Universe.S02E09.Cant.Get.You.out.of.My.Head.1080p.WEB-DL.nzb";
    NewznabXmlRoot root = RssBuilder.builder().items(Arrays.asList(RssItemBuilder.builder("[ Watchers.of.the.Universe.S02E09.1080p.WEB-DL.DD5.1.AAC2.0.H.264-YFN ] - [00/30] - \"Watchers.of.the.Universe.S02E09.Cant.Get.You.out.of.My.Head.1080p.WEB-DL.DD5.1.AAC2.0.H.264-YFN.nzb\" yEnc\n").link(link).description("<![CDATA[\n" + "<p><font color=\"gray\">alt.binaries.hdtv.x264</font><br /> <b>1.01 GB</b><br /> 7 hours<br /> <font color=\"#3DA233\">31 files (1405 parts)</font> <font color=\"gray\">by s@nd.p (SP)</font><br /> <font color=\"#E2A910\"> 1 NFO | 9 PAR2 | 1 NZB | 19 ARCHIVE</font> - <a href=\"http://nzbindex.com/nfo/164950363/Watchers.of.the.Universe.S02E09.1080p.WEB-DL.DD5.1.AAC2.0.H.264-YFN-0030-Watchers.of.the.Universe.S02E09.Cant.Get.You.out.of.My.Head.1080p.WEB-DL.nzb/?q=\" target=\"_blank\">View NFO</a></p>\n" + "]]>").category("alt.binaries.hdtv.x264").pubDate(now).rssGuid(new NewznabXmlGuid(link, true)).enclosure(new NewznabXmlEnclosure(enclosureUrl, 1089197181L, "application/x-nzb")).build())).build();
    List<SearchResultItem> items = testee.getSearchResultItems(root);
    assertThat(items.size(), is(1));
    SearchResultItem item = items.get(0);
    assertThat(item.getTitle(), is("Watchers.of.the.Universe.S02E09.1080p.WEB-DL.DD5.1.AAC2.0.H.264-YFN-0030-Watchers.of.the.Universe.S02E09.Cant.Get.You.out.of.My.Head.1080p.WEB-DL"));
    assertThat(item.getGroup().get(), is("alt.binaries.hdtv.x264"));
    assertThat(item.getPubDate(), is(now));
    assertThat(item.isAgePrecise(), is(true));
    assertThat(item.getSize(), is(1089197181L));
    assertThat(item.getIndexerGuid(), is("164950363"));
    assertThat(item.getDownloadType(), is(DownloadType.NZB));
    assertThat(item.getHasNfo(), is(HasNfo.YES));
}
Also used : NewznabXmlEnclosure(org.nzbhydra.mapping.newznab.xml.NewznabXmlEnclosure) NewznabXmlGuid(org.nzbhydra.mapping.newznab.xml.NewznabXmlGuid) Instant(java.time.Instant) NewznabXmlRoot(org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot) SearchResultItem(org.nzbhydra.searching.SearchResultItem) Test(org.junit.Test)

Example 8 with SearchResultItem

use of org.nzbhydra.searching.SearchResultItem in project nzbhydra2 by theotherp.

the class TorznabTest method shouldCreateSearchResultItem.

@Test
public void shouldCreateSearchResultItem() throws Exception {
    NewznabXmlItem rssItem = buildBasicRssItem();
    rssItem.getTorznabAttributes().add(new NewznabAttribute("password", "0"));
    rssItem.getTorznabAttributes().add(new NewznabAttribute("group", "group"));
    rssItem.getTorznabAttributes().add(new NewznabAttribute("poster", "poster"));
    rssItem.getTorznabAttributes().add(new NewznabAttribute("size", "456"));
    rssItem.getTorznabAttributes().add(new NewznabAttribute("files", "10"));
    rssItem.getTorznabAttributes().add(new NewznabAttribute("grabs", "20"));
    rssItem.getTorznabAttributes().add(new NewznabAttribute("comments", "30"));
    rssItem.getTorznabAttributes().add(new NewznabAttribute("usenetdate", new JaxbPubdateAdapter().marshal(Instant.ofEpochSecond(6666666))));
    rssItem.setCategory("4000");
    SearchResultItem item = testee.createSearchResultItem(rssItem);
    assertThat(item.getLink(), is("http://indexer.com/123"));
    assertThat(item.getIndexerGuid(), is("http://indexer.com/123"));
    assertThat(item.getSize(), is(456L));
    assertThat(item.getCommentsLink(), is("http://indexer.com/123/details#comments"));
    assertThat(item.getDetails(), is("http://indexer.com/123"));
    assertThat(item.isAgePrecise(), is(true));
    assertThat(item.getGrabs(), is(20));
    assertThat(item.getDownloadType(), is(DownloadType.TORRENT));
}
Also used : SearchResultItem(org.nzbhydra.searching.SearchResultItem) Test(org.junit.Test)

Example 9 with SearchResultItem

use of org.nzbhydra.searching.SearchResultItem in project nzbhydra2 by theotherp.

the class BinsearchTest method shouldParseResultsCorrectly.

@Test
public void shouldParseResultsCorrectly() throws Exception {
    String html = Resources.toString(Resources.getResource(BinsearchTest.class, "/org/nzbhydra/mapping/binsearch.html"), Charsets.UTF_8);
    List<SearchResultItem> searchResultItems = testee.getSearchResultItems(html);
    assertThat(searchResultItems.size(), is(1));
    SearchResultItem item = searchResultItems.get(0);
    assertThat(item.getTitle(), is("testtitle. 3D.TOPBOT.TrueFrench.1080p.X264.AC3.5.1-JKF.mkv"));
    assertThat(item.getLink(), is("https://www.binsearch.info/?action=nzb&176073735=1"));
    assertThat(item.getDetails(), is("https://www.binsearch.info/?b=testtitle1.3D.TOPBOT.TrueFrench.1080p.X264.A&g=alt.binaries.movies.mkv&p=Ramer%40marmer.com+%28Clown_nez%29&max=250"));
    // 12.21 GB = 12.21 * 1000*1000*1000
    assertThat(item.getSize(), is(12209999872L));
    assertThat(item.getIndexerGuid(), is("176073735"));
    assertThat(item.getPubDate(), is(Instant.ofEpochSecond(1443312000)));
    assertThat(item.isAgePrecise(), is(false));
    assertThat(item.getPoster().get(), is("Ramer@marmer.com (Clown_nez)"));
    assertThat(item.getGroup().get(), is("alt.binaries.movies.mkv"));
}
Also used : SearchResultItem(org.nzbhydra.searching.SearchResultItem) Test(org.junit.Test)

Example 10 with SearchResultItem

use of org.nzbhydra.searching.SearchResultItem in project nzbhydra2 by theotherp.

the class Binsearch method getSearchResultItems.

@SuppressWarnings("ConstantConditions")
@Override
protected List<SearchResultItem> getSearchResultItems(String searchRequestResponse) throws IndexerParsingException {
    List<SearchResultItem> items = new ArrayList<>();
    Document doc = Jsoup.parse(searchRequestResponse);
    if (doc.text().contains("No results in most popular groups")) {
        return Collections.emptyList();
    }
    Elements mainTables = doc.select("table#r2");
    if (mainTables.size() == 0) {
        throw new IndexerParsingException("Unable to find main table in binsearch page. This happens sometimes ;-)");
    }
    Element mainTable = mainTables.get(0);
    Elements rows = mainTable.select("tr");
    for (int i = 1; i < rows.size(); i++) {
        // First row is header
        Element row = rows.get(i);
        SearchResultItem item = parseRow(row);
        if (item == null) {
            continue;
        }
        items.add(item);
    }
    debug("Finished parsing {} of {} rows", items.size(), rows.size());
    return items;
}
Also used : IndexerParsingException(org.nzbhydra.indexers.exceptions.IndexerParsingException) Element(org.jsoup.nodes.Element) SearchResultItem(org.nzbhydra.searching.SearchResultItem) ArrayList(java.util.ArrayList) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements)

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