From 00b36bb75aec8838ffa3473b14c42b275fa06747 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 20 Jan 2022 21:35:45 +0100 Subject: [PATCH] =?utf8?q?=F0=9F=9A=A7=20Add=20comic=20filter=20for=20Ogla?= =?utf8?q?f?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../rhynodge/filters/comics/OglafComicSiteFilter.kt | 21 +++++++++++++++++++++ .../filters/comics/OglafComicSiteFilterTest.kt | 17 +++++++++++++++++ .../rhynodge/filters/comics/oglaf.html | 4 ++++ 3 files changed, 42 insertions(+) create mode 100644 src/main/kotlin/net/pterodactylus/rhynodge/filters/comics/OglafComicSiteFilter.kt create mode 100644 src/test/kotlin/net/pterodactylus/rhynodge/filters/comics/OglafComicSiteFilterTest.kt create mode 100644 src/test/resources/net/pterodactylus/rhynodge/filters/comics/oglaf.html diff --git a/src/main/kotlin/net/pterodactylus/rhynodge/filters/comics/OglafComicSiteFilter.kt b/src/main/kotlin/net/pterodactylus/rhynodge/filters/comics/OglafComicSiteFilter.kt new file mode 100644 index 0000000..777eca8 --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/rhynodge/filters/comics/OglafComicSiteFilter.kt @@ -0,0 +1,21 @@ +package net.pterodactylus.rhynodge.filters.comics + +import net.pterodactylus.rhynodge.filters.ComicSiteFilter +import net.pterodactylus.rhynodge.utils.asOptional +import org.jsoup.nodes.Document + +class OglafComicSiteFilter : ComicSiteFilter() { + + override fun extractTitle(document: Document) = document.title().asOptional() + + override fun extractImageUrls(document: Document) = + document.getElementById("strip") + .attr("src") + .let(::listOf) + + override fun extractImageComments(document: Document) = + document.getElementById("strip") + .attr("title") + .let(::listOf) + +} diff --git a/src/test/kotlin/net/pterodactylus/rhynodge/filters/comics/OglafComicSiteFilterTest.kt b/src/test/kotlin/net/pterodactylus/rhynodge/filters/comics/OglafComicSiteFilterTest.kt new file mode 100644 index 0000000..1bf90d2 --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/rhynodge/filters/comics/OglafComicSiteFilterTest.kt @@ -0,0 +1,17 @@ +package net.pterodactylus.rhynodge.filters.comics + +import net.pterodactylus.rhynodge.states.ComicState +import net.pterodactylus.rhynodge.states.ComicState.Comic + +class OglafComicSiteFilterTest : ComicSiteFilterTest() { + + override val filter = OglafComicSiteFilter() + override val baseUrl = "https://www.oglaf.com/" + override val resource = "oglaf.html" + override val expectedComics = listOf( + Comic("Lightning Rod") + .add(ComicState.Strip("https://media.oglaf.com/comic/lightning_rod.jpg", "With Zeus, ‘aftercare’ usually means turning you into an animal")) + ) + +} + diff --git a/src/test/resources/net/pterodactylus/rhynodge/filters/comics/oglaf.html b/src/test/resources/net/pterodactylus/rhynodge/filters/comics/oglaf.html new file mode 100644 index 0000000..66ac736 --- /dev/null +++ b/src/test/resources/net/pterodactylus/rhynodge/filters/comics/oglaf.html @@ -0,0 +1,4 @@ +Lightning Rod
lovingly rendered pictures of cocks.
-- 2.7.4