Search in sources :

Example 1 with IndexerParsingException

use of org.nzbhydra.indexers.exceptions.IndexerParsingException 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

ArrayList (java.util.ArrayList)1 Document (org.jsoup.nodes.Document)1 Element (org.jsoup.nodes.Element)1 Elements (org.jsoup.select.Elements)1 IndexerParsingException (org.nzbhydra.indexers.exceptions.IndexerParsingException)1 SearchResultItem (org.nzbhydra.searching.SearchResultItem)1