From 6a703ead9ba06c26e63e66017483f4dfcf426a26 Mon Sep 17 00:00:00 2001 From: Mike <51273546+SnakeDoc83@users.noreply.github.com> Date: Wed, 25 Dec 2019 16:57:57 -0500 Subject: [PATCH] MangaCards update (#1911) MangaCards update --- src/all/mangacards/build.gradle | 2 +- .../extension/all/mangacards/MangaCards.kt | 55 ++++++++----------- 2 files changed, 23 insertions(+), 34 deletions(-) diff --git a/src/all/mangacards/build.gradle b/src/all/mangacards/build.gradle index a46723758..234c179fd 100644 --- a/src/all/mangacards/build.gradle +++ b/src/all/mangacards/build.gradle @@ -5,7 +5,7 @@ ext { appName = 'Tachiyomi: MangaCards (Valhalla, NANI?)' pkgNameSuffix = 'all.mangacards' extClass = '.MangaCardsFactory' - extVersionCode = 5 + extVersionCode = 6 libVersion = '1.2' } diff --git a/src/all/mangacards/src/eu/kanade/tachiyomi/extension/all/mangacards/MangaCards.kt b/src/all/mangacards/src/eu/kanade/tachiyomi/extension/all/mangacards/MangaCards.kt index 3ad295de5..74bf1a7cf 100644 --- a/src/all/mangacards/src/eu/kanade/tachiyomi/extension/all/mangacards/MangaCards.kt +++ b/src/all/mangacards/src/eu/kanade/tachiyomi/extension/all/mangacards/MangaCards.kt @@ -15,6 +15,7 @@ import okhttp3.Request import okhttp3.Response import org.jsoup.nodes.Document import org.jsoup.nodes.Element +import java.lang.Exception import java.text.SimpleDateFormat import java.util.Locale @@ -31,7 +32,7 @@ abstract class MangaCards( // Popular override fun popularMangaRequest(page: Int): Request { - return GET("$baseUrl/projects") + return GET("$baseUrl/projects", headers) } override fun popularMangaSelector() = "div.col-sm-4" @@ -46,32 +47,20 @@ abstract class MangaCards( return manga } - override fun popularMangaNextPageSelector() = "No next page" + override fun popularMangaNextPageSelector(): String? = null // Latest - // Track which manga titles have been added to latestUpdates's MangasPage - private val latestUpdatesTitles = mutableSetOf() - override fun latestUpdatesRequest(page: Int): Request { - if (page == 1) latestUpdatesTitles.clear() - return GET(baseUrl) + return GET(baseUrl, headers) } - // Only add manga to MangasPage if its title is not one we've added already override fun latestUpdatesParse(response: Response): MangasPage { - val latestManga = mutableListOf() - val document = response.asJsoup() + val mangas = response.asJsoup().select(latestUpdatesSelector()) + .distinctBy { it.select("div.pt-0 a").text() } + .map { latestUpdatesFromElement(it) } - document.select(latestUpdatesSelector()).forEach { element -> - latestUpdatesFromElement(element).let { manga -> - if (manga.title !in latestUpdatesTitles) { - latestManga.add(manga) - latestUpdatesTitles.add(manga.title) - } - } - } - return MangasPage(latestManga, document.select(latestUpdatesNextPageSelector()).hasText()) + return MangasPage(mangas, false) } override fun latestUpdatesSelector() = "div.col-sm-6" @@ -86,25 +75,24 @@ abstract class MangaCards( return manga } - override fun latestUpdatesNextPageSelector() = "No next page" + override fun latestUpdatesNextPageSelector(): String? = null // Search /* Source websites aren't able to search their whole catalog at once, instead we'd have to do separate searches for ongoing, hiatus, dropped, and completed and then combine those results. Since their catalogs are small, it seems easier to do the search client-side */ - private var searchQuery = "" + private lateinit var searchQuery: String override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { - searchQuery = query.toLowerCase() + searchQuery = query return popularMangaRequest(1) } override fun searchMangaParse(response: Response): MangasPage { - val searchMatches = mutableListOf() - response.asJsoup().select(searchMangaSelector()) - .filter { it.text().toLowerCase().contains(searchQuery) } - .map { searchMatches.add(searchMangaFromElement(it)) } + val searchMatches = response.asJsoup().select(searchMangaSelector()) + .filter { it.text().contains(searchQuery, ignoreCase = true) } + .map { searchMangaFromElement(it) } return MangasPage(searchMatches, false) } @@ -113,7 +101,7 @@ abstract class MangaCards( override fun searchMangaFromElement(element: Element) = popularMangaFromElement(element) - override fun searchMangaNextPageSelector() = popularMangaNextPageSelector() + override fun searchMangaNextPageSelector(): String? = null // Manga details @@ -151,7 +139,11 @@ abstract class MangaCards( } private fun parseDate(date: String): Long { - return SimpleDateFormat("dd/MM/yyyy", Locale.US).parse(date).time + return try { + SimpleDateFormat("dd/MM/yyyy", Locale.US).parse(date).time + } catch (e: Exception) { + 0L + } } override fun pageListRequest(chapter: SChapter): Request { @@ -162,12 +154,9 @@ abstract class MangaCards( } override fun pageListParse(document: Document): List { - val pages = mutableListOf() - - document.select("div#pages img").forEachIndexed { i, element -> - pages.add(Page(i, "", element.attr("abs:src"))) + return document.select("div#pages img").mapIndexed { i, element -> + Page(i, "", element.attr("abs:src")) } - return pages } override fun imageUrlParse(document: Document): String = throw UnsupportedOperationException("Not used")