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;
}
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;
}
Aggregations