X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Frhynodge%2Ffilters%2FComicSiteFilter.java;h=6bc67cd1441952f861911de9579df534465f8998;hb=dede8612b6a32658db53d6d828c48289bd007b47;hp=1d9e6f7273c34a6e48a82751be9067cd6896d5d6;hpb=8b9fa1f4f9d9df7212e6e440dc42dd10f32e0596;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 1d9e6f7..6bc67cd 100644 --- a/src/main/java/net/pterodactylus/rhynodge/filters/ComicSiteFilter.java +++ b/src/main/java/net/pterodactylus/rhynodge/filters/ComicSiteFilter.java @@ -21,6 +21,7 @@ import static com.google.common.base.Preconditions.checkArgument; import java.net.URI; import java.net.URISyntaxException; +import java.util.Collections; import java.util.List; import net.pterodactylus.rhynodge.Filter; @@ -32,6 +33,7 @@ import net.pterodactylus.rhynodge.states.FailedState; import net.pterodactylus.rhynodge.states.HtmlState; import com.google.common.base.Optional; +import org.jetbrains.annotations.NotNull; import org.jsoup.nodes.Document; /** @@ -42,8 +44,9 @@ import org.jsoup.nodes.Document; */ public abstract class ComicSiteFilter implements Filter { + @NotNull @Override - public State filter(State state) { + public State filter(@NotNull State state) { checkArgument(state instanceof HtmlState, "state must be an HTML state"); /* initialize states: */ @@ -55,17 +58,16 @@ public abstract class ComicSiteFilter implements Filter { List imageComments = extractImageComments(htmlState.document()); /* store comic, if found, into state. */ - if (!title.isPresent() || imageUrls.isEmpty()) { + if (imageUrls.isEmpty()) { return new FailedState(); } - ComicState comicState = new ComicState(); - Comic comic = new Comic(title.get()); + Comic comic = new Comic(title.or("")); int imageCounter = 0; for (String imageUrl : imageUrls) { String imageComment = (imageCounter < imageComments.size()) ? imageComments.get(imageCounter) : ""; try { - URI stripUri = new URI(htmlState.uri()).resolve(imageUrl); + URI stripUri = new URI(htmlState.uri()).resolve(imageUrl.replaceAll(" ", "%20")); Strip strip = new Strip(stripUri.toString(), imageComment); imageCounter++; comic.add(strip); @@ -73,9 +75,8 @@ public abstract class ComicSiteFilter implements Filter { throw new IllegalStateException(String.format("Could not resolve image URL “%s” against base URL “%s”.", imageUrl, htmlState.uri()), use1); } } - comicState.add(comic); - return comicState; + return new ComicState(Collections.singletonList(comic)); } //