Search in sources :

Example 11 with SearchResultItem

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

the class Binsearch method parseRow.

private SearchResultItem parseRow(Element row) {
    SearchResultItem item = new SearchResultItem();
    Element titleElement = getElementOrNone(row, "span[class=s]");
    if (titleElement == null) {
        debug("Table row does not have a title");
        return null;
    }
    String title = titleElement.ownText();
    if (title.contains("password protect") || title.contains("passworded")) {
        item.setPassworded(true);
    }
    Matcher matcher = TITLE_PATTERN.matcher(title);
    if (matcher.find()) {
        title = matcher.group(1);
    }
    title = cleanUpTitle(title);
    item.setTitle(title);
    item.setIndexerGuid(getElementOrNone(row, "input[type=checkbox]").attr("name"));
    item.setLink("https://www.binsearch.info/?action=nzb&" + item.getIndexerGuid() + "=1");
    Element infoElement = getElementOrNone(row, "span.d");
    if (infoElement == null) {
        debug("Ignored entry because it has no info");
        return null;
    }
    // e.g. /?b=Supers.Troopers.of.Mega.3D.TOPBOT.TrueFrench.1080p.X264.A&g=alt.binaries.movies.mkv&p=Ramer%40marmer.com+%28Clown_nez%29&max=250
    String collectionLink = getElementOrNone(row, "a").attr("href");
    item.setDetails("https://www.binsearch.info" + collectionLink);
    Matcher groupMatcher = GROUP_PATTERN.matcher(collectionLink);
    if (groupMatcher.find()) {
        item.setGroup(groupMatcher.group(1).trim());
    }
    // e.g. Ramer%40marmer.com+%28Clown_nez%29
    Matcher posterMatcher = POSTER_PATTERN.matcher(collectionLink);
    if (posterMatcher.find()) {
        String poster = posterMatcher.group(1).trim();
        try {
            poster = URLDecoder.decode(poster, "UTF-8").replace("+", " ");
            item.setPoster(poster);
        } catch (UnsupportedEncodingException e) {
            debug("Unable to decode poster {}", poster);
        }
    }
    Matcher sizeMatcher = SIZE_PATTERN.matcher(infoElement.ownText());
    if (sizeMatcher.find()) {
        Float size = Float.valueOf(sizeMatcher.group("size"));
        String unit = sizeMatcher.group("unit");
        switch(unit) {
            case "GB":
                size = size * 1000 * 1000 * 1000;
                break;
            case "MB":
                size = size * 1000 * 1000;
                break;
            case "KB":
                size = size * 1000;
                break;
        }
        item.setSize(size.longValue());
    } else {
        debug("Unable to find size in text {}", infoElement.ownText());
        return null;
    }
    Matcher nfoMatcher = NFO_INFO_PATTERN.matcher(infoElement.ownText());
    item.setHasNfo(nfoMatcher.find() ? HasNfo.YES : HasNfo.NO);
    Matcher pubdateMatcher = PUBDATE_PATTERN.matcher(row.text());
    if (pubdateMatcher.find()) {
        String pubdateString = pubdateMatcher.group(1);
        Instant pubdate = DATE_TIME_FORMATTER.parse(pubdateString, Instant::from);
        item.setPubDate(pubdate);
        item.setAgePrecise(false);
    } else {
        debug("Unable to find pubdate in row {}", row.text());
        return null;
    }
    item.setCategory(categoryProvider.getNotAvailable());
    item.setIndexer(this);
    item.setDownloadType(DownloadType.NZB);
    item.setIndexerScore(config.getScore().orElse(0));
    return item;
}
Also used : Matcher(java.util.regex.Matcher) Element(org.jsoup.nodes.Element) Instant(java.time.Instant) SearchResultItem(org.nzbhydra.searching.SearchResultItem) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 12 with SearchResultItem

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

the class Torznab method createSearchResultItem.

protected SearchResultItem createSearchResultItem(NewznabXmlItem item) {
    // Not set in RSS but actually always true
    item.getRssGuid().setPermaLink(true);
    SearchResultItem searchResultItem = super.createSearchResultItem(item);
    if (item.getCategory() != null) {
        computeCategory(searchResultItem, Collections.singletonList(Integer.valueOf(item.getCategory())));
    } else {
        searchResultItem.setCategory(categoryProvider.getNotAvailable());
    }
    searchResultItem.setGrabs(item.getGrabs());
    searchResultItem.setIndexerGuid(item.getRssGuid().getGuid());
    for (NewznabAttribute attribute : item.getTorznabAttributes()) {
        searchResultItem.getAttributes().put(attribute.getName(), attribute.getValue());
        switch(attribute.getName()) {
            case "grabs":
                searchResultItem.setGrabs(Integer.valueOf(attribute.getValue()));
                break;
            case "guid":
                searchResultItem.setIndexerGuid(attribute.getValue());
                break;
            case "seeders":
                searchResultItem.setSeeders(Integer.valueOf(attribute.getValue()));
                break;
            case "peers":
                searchResultItem.setPeers(Integer.valueOf(attribute.getValue()));
                break;
        }
    }
    searchResultItem.setHasNfo(HasNfo.NO);
    searchResultItem.setIndexerScore(config.getScore().orElse(0));
    searchResultItem.setDownloadType(DownloadType.TORRENT);
    searchResultItem.setGuid(SearchResultIdCalculator.calculateSearchResultId(searchResultItem));
    return searchResultItem;
}
Also used : SearchResultItem(org.nzbhydra.searching.SearchResultItem)

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