Search in sources :

Example 1 with LargePreviewSet

use of com.hippo.ehviewer.client.data.LargePreviewSet in project EhViewer by seven332.

the class GalleryDetailParser method parseLargePreviewSet.

/**
 * Parse large previews with regular expressions
 */
private static LargePreviewSet parseLargePreviewSet(Document d, String body) throws ParseException {
    try {
        LargePreviewSet largePreviewSet = new LargePreviewSet();
        Element gdt = d.getElementById("gdt");
        Elements gdtls = gdt.getElementsByClass("gdtl");
        int n = gdtls.size();
        if (n <= 0) {
            throw new ParseException("Can't parse large preview", body);
        }
        for (int i = 0; i < n; i++) {
            Element element = gdtls.get(i).child(0);
            String pageUrl = element.attr("href");
            element = element.child(0);
            String imageUrl = element.attr("src");
            if (Settings.getFixThumbUrl()) {
                imageUrl = EhUrl.getFixedPreviewThumbUrl(imageUrl);
            }
            int index = Integer.parseInt(element.attr("alt")) - 1;
            largePreviewSet.addItem(index, imageUrl, pageUrl);
        }
        return largePreviewSet;
    } catch (Exception e) {
        e.printStackTrace();
        throw new ParseException("Can't parse large preview", body);
    }
}
Also used : LargePreviewSet(com.hippo.ehviewer.client.data.LargePreviewSet) Element(org.jsoup.nodes.Element) ParseException(com.hippo.ehviewer.client.exception.ParseException) Elements(org.jsoup.select.Elements) EhException(com.hippo.ehviewer.client.exception.EhException) ParseException(com.hippo.ehviewer.client.exception.ParseException) OffensiveException(com.hippo.ehviewer.client.exception.OffensiveException) PiningException(com.hippo.ehviewer.client.exception.PiningException)

Example 2 with LargePreviewSet

use of com.hippo.ehviewer.client.data.LargePreviewSet 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;
}
Also used : Matcher(java.util.regex.Matcher) LargePreviewSet(com.hippo.ehviewer.client.data.LargePreviewSet) ParseException(com.hippo.ehviewer.client.exception.ParseException)

Aggregations

LargePreviewSet (com.hippo.ehviewer.client.data.LargePreviewSet)2 ParseException (com.hippo.ehviewer.client.exception.ParseException)2 EhException (com.hippo.ehviewer.client.exception.EhException)1 OffensiveException (com.hippo.ehviewer.client.exception.OffensiveException)1 PiningException (com.hippo.ehviewer.client.exception.PiningException)1 Matcher (java.util.regex.Matcher)1 Element (org.jsoup.nodes.Element)1 Elements (org.jsoup.select.Elements)1