X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Frhynodge%2Ffilters%2FComicSiteFilter.java;h=9b3dfcd6978b2198154fb8f61fb10ba0a5d7fbce;hb=bfe1d5647f8c29a202b8c37aeee91d4598354f99;hp=fb01349e683369e1e0524e88a703ba6cc05a3645;hpb=a4dfb17e4e1d00440a049cb1063e1b1509216739;p=rhynodge.git diff --git a/src/main/java/net/pterodactylus/rhynodge/filters/ComicSiteFilter.java b/src/main/java/net/pterodactylus/rhynodge/filters/ComicSiteFilter.java index fb01349..9b3dfcd 100644 --- a/src/main/java/net/pterodactylus/rhynodge/filters/ComicSiteFilter.java +++ b/src/main/java/net/pterodactylus/rhynodge/filters/ComicSiteFilter.java @@ -25,6 +25,7 @@ import net.pterodactylus.rhynodge.Filter; import net.pterodactylus.rhynodge.State; import net.pterodactylus.rhynodge.states.ComicState; import net.pterodactylus.rhynodge.states.ComicState.Comic; +import net.pterodactylus.rhynodge.states.ComicState.Strip; import net.pterodactylus.rhynodge.states.HtmlState; import com.google.common.base.Optional; @@ -49,12 +50,17 @@ public abstract class ComicSiteFilter implements Filter { /* extract comics. */ Optional title = extractTitle(htmlState.document()); List imageUrls = extractImageUrls(htmlState.document()); + List imageComments = extractImageComments(htmlState.document()); /* store comic, if found, into state. */ if (title.isPresent() && !imageUrls.isEmpty()) { Comic comic = new Comic(title.get()); + int imageCounter = 0; for (String imageUrl : imageUrls) { - comic.addImageUrl(imageUrl); + String imageComment = (imageCounter < imageComments.size()) ? imageComments.get(imageCounter) : ""; + Strip strip = new Strip(imageUrl, imageComment); + imageCounter++; + comic.add(strip); } comicState.add(comic); } @@ -86,4 +92,16 @@ public abstract class ComicSiteFilter implements Filter { */ protected abstract List extractImageUrls(Document document); + /** + * Extracts the image comments from the given document. The elements of this + * last and of the list returned by {@link #extractImageUrls(org.jsoup.nodes.Document)} + * are paired up and added as {@link Strip}s. If the list returned by this + * method has less elements, an empty string is used for the remaining images. + * + * @param document + * The document to extract the image comments from + * @return The extracted image comments + */ + protected abstract List extractImageComments(Document document); + }