From dede8612b6a32658db53d6d828c48289bd007b47 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 30 Apr 2023 07:34:19 +0200 Subject: [PATCH 1/1] =?utf8?q?=E2=9C=85=20Add=20test=20for=20=E2=80=9CPoor?= =?utf8?q?ly=20Drawn=20Lines=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../comics/PoorlyDrawnLinesComicFilter.java | 7 +- .../comics/PoorlyDrawnLinesComicFilterTest.kt | 28 + .../filters/comics/poorly-drawn-lines.html | 3762 ++++++++++++++++++++ 3 files changed, 3795 insertions(+), 2 deletions(-) create mode 100644 src/test/kotlin/net/pterodactylus/rhynodge/filters/comics/PoorlyDrawnLinesComicFilterTest.kt create mode 100644 src/test/resources/net/pterodactylus/rhynodge/filters/comics/poorly-drawn-lines.html diff --git a/src/main/java/net/pterodactylus/rhynodge/filters/comics/PoorlyDrawnLinesComicFilter.java b/src/main/java/net/pterodactylus/rhynodge/filters/comics/PoorlyDrawnLinesComicFilter.java index 865e302..c01f5a9 100644 --- a/src/main/java/net/pterodactylus/rhynodge/filters/comics/PoorlyDrawnLinesComicFilter.java +++ b/src/main/java/net/pterodactylus/rhynodge/filters/comics/PoorlyDrawnLinesComicFilter.java @@ -26,6 +26,8 @@ import net.pterodactylus.rhynodge.filters.ComicSiteFilter; import com.google.common.base.Optional; import org.jsoup.nodes.Document; +import static java.util.Arrays.stream; + /** * {@link ComicSiteFilter} implementation that can parse Poorly Drawn Lines * comics. @@ -36,12 +38,13 @@ public class PoorlyDrawnLinesComicFilter extends ComicSiteFilter { @Override protected Optional extractTitle(Document document) { - return Optional.of(document.select("#post img").attr("alt")); + return Optional.of(document.select(".share-mobile .social a.facebook").attr("href")) + .transform(href -> stream(href.split("&t=")).skip(1).findFirst().orElse("")); } @Override protected List extractImageUrls(Document document) { - return Arrays.asList(document.select("#post img").attr("src")); + return Arrays.asList(document.select(".comic img").attr("src")); } @Override diff --git a/src/test/kotlin/net/pterodactylus/rhynodge/filters/comics/PoorlyDrawnLinesComicFilterTest.kt b/src/test/kotlin/net/pterodactylus/rhynodge/filters/comics/PoorlyDrawnLinesComicFilterTest.kt new file mode 100644 index 0000000..4d31c13 --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/rhynodge/filters/comics/PoorlyDrawnLinesComicFilterTest.kt @@ -0,0 +1,28 @@ +package net.pterodactylus.rhynodge.filters.comics + +import net.pterodactylus.rhynodge.filters.ResourceLoader +import net.pterodactylus.rhynodge.states.ComicState +import net.pterodactylus.rhynodge.states.ComicState.Strip +import net.pterodactylus.rhynodge.states.HtmlState +import org.hamcrest.MatcherAssert.assertThat +import org.hamcrest.Matchers.contains +import org.junit.Test + +class PoorlyDrawnLinesComicFilterTest { + + private val filter = PoorlyDrawnLinesComicFilter() + private val htmlState: HtmlState = ResourceLoader + .loadDocument(javaClass, "poorly-drawn-lines.html", baseUrl) + .let { HtmlState(baseUrl, it) } + + @Test + fun `comic is extracted correctly`() { + val comicState = filter.filter(htmlState) as ComicState + assertThat(comicState.comics(), contains( + ComicState.Comic("A New Day").add(Strip("https://poorlydrawnlines.com/wp-content/uploads/2023/04/a_new_day.png", "")) + )) + } + +} + +private const val baseUrl = "https://poorlydrawnlines.com/" diff --git a/src/test/resources/net/pterodactylus/rhynodge/filters/comics/poorly-drawn-lines.html b/src/test/resources/net/pterodactylus/rhynodge/filters/comics/poorly-drawn-lines.html new file mode 100644 index 0000000..a5b1cc1 --- /dev/null +++ b/src/test/resources/net/pterodactylus/rhynodge/filters/comics/poorly-drawn-lines.html @@ -0,0 +1,3762 @@ + + + + Poorly Drawn Lines + + + + + + + + + + + + + + + + + + + +facebookCreated with Sketch. instagramCreated with Sketch. left-navCreated with Sketch. mailCreated with Sketch. menuCreated with Sketch. pdl-title Slice 1Created with Sketch. right-navCreated with Sketch. shareCreated with Sketch. shuffleCreated with Sketch. left-navCreated with Sketch. tumblrCreated with Sketch. twitterCreated with Sketch.
+
+
+ +
+
+ +
+ contact + + + +
+
+
+
+
+ + + +
+ +
+ + + + + + + + -- 2.7.4