use of com.hippo.ehviewer.client.exception.ParseException in project EhViewer by seven332.
the class WhatsHotParser method parse.
@SuppressWarnings("ConstantConditions")
public static List<GalleryInfo> parse(String body) throws ParseException {
try {
List<GalleryInfo> galleryInfoList = new ArrayList<>(15);
Document d = Jsoup.parse(body);
Element pp = d.getElementById("pp");
Elements id1List = pp.getElementsByClass("id1");
for (int i = 0, n = id1List.size(); i < n; i++) {
GalleryInfo galleryInfo = new GalleryInfo();
Element id1 = id1List.get(i);
Element id3 = JsoupUtils.getElementByClass(id1, "id3");
Element temp = JsoupUtils.getElementByTag(id3, "a");
String url = temp.attr("href");
GalleryDetailUrlParser.Result result = GalleryDetailUrlParser.parse(url);
galleryInfo.gid = result.gid;
galleryInfo.token = result.token;
temp = JsoupUtils.getElementByTag(temp, "img");
galleryInfo.thumb = EhUtils.handleThumbUrlResolution(temp.attr("src"));
galleryInfo.title = temp.attr("title");
galleryInfo.generateSLang();
galleryInfoList.add(galleryInfo);
}
return galleryInfoList;
} catch (Exception e) {
throw new ParseException("Parse whats hot error", body);
}
}
use of com.hippo.ehviewer.client.exception.ParseException in project EhViewer by seven332.
the class ForumsParser method parse.
public static String parse(String body) throws ParseException {
try {
Document d = Jsoup.parse(body, EhUrl.URL_FORUMS);
Element userlinks = d.getElementById("userlinks");
Element child = userlinks.child(0).child(0).child(0);
return child.attr("href");
} catch (Exception e) {
throw new ParseException("Parse forums error", body);
}
}
use of com.hippo.ehviewer.client.exception.ParseException in project EhViewer by seven332.
the class GalleryDetailParser method parseLargePreviewSet.
/**
* Parse large previews with regular expressions
*/
private static LargePreviewSet parseLargePreviewSet(String body) throws ParseException {
Matcher m = PATTERN_LARGE_PREVIEW.matcher(body);
LargePreviewSet largePreviewSet = new LargePreviewSet();
while (m.find()) {
int index = ParserUtils.parseInt(m.group(2)) - 1;
String imageUrl = ParserUtils.trim(m.group(3));
String pageUrl = ParserUtils.trim(m.group(1));
if (Settings.getFixThumbUrl()) {
imageUrl = EhUrl.getFixedPreviewThumbUrl(imageUrl);
}
largePreviewSet.addItem(index, imageUrl, pageUrl);
}
if (largePreviewSet.size() == 0) {
throw new ParseException("Can't parse large preview", body);
}
return largePreviewSet;
}
use of com.hippo.ehviewer.client.exception.ParseException in project EhViewer by seven332.
the class GalleryDetailParser method parseNormalPreviewSet.
/**
* Parse normal previews with regular expressions
*/
private static NormalPreviewSet parseNormalPreviewSet(String body) throws ParseException {
Matcher m = PATTERN_NORMAL_PREVIEW.matcher(body);
NormalPreviewSet normalPreviewSet = new NormalPreviewSet();
while (m.find()) {
normalPreviewSet.addItem(ParserUtils.parseInt(m.group(6)) - 1, ParserUtils.trim(m.group(3)), ParserUtils.parseInt((m.group(4))), 0, ParserUtils.parseInt(m.group(1)), ParserUtils.parseInt(m.group(2)), ParserUtils.trim(m.group(5)));
}
if (normalPreviewSet.size() == 0) {
throw new ParseException("Can't parse normal preview", body);
}
return normalPreviewSet;
}
use of com.hippo.ehviewer.client.exception.ParseException in project EhViewer by seven332.
the class GalleryListParser method parse.
public static Result parse(@NonNull String body) throws Exception {
Result result = new Result();
Document d = Jsoup.parse(body);
try {
result.pages = parsePages(d, body);
} catch (ParseException e) {
if (body.contains("No hits found</p>")) {
result.pages = 0;
// noinspection unchecked
result.galleryInfoList = Collections.EMPTY_LIST;
return result;
} else {
throw e;
}
}
try {
Elements es = d.getElementsByClass("itg").first().child(0).children();
List<GalleryInfo> list = new ArrayList<>(es.size() - 1);
for (int i = 1; i < es.size(); i++) {
// First one is table header, skip it
GalleryInfo gi = parseGalleryInfo(es.get(i));
if (null != gi) {
list.add(gi);
}
}
result.galleryInfoList = list;
} catch (Exception e) {
throw new ParseException("Can't parse gallery list", body);
}
return result;
}
Aggregations