From abcea920179d3719ede1ccf6cd64624ae08d5b69 Mon Sep 17 00:00:00 2001 From: Rolando Lecca <90949336+bapeey@users.noreply.github.com> Date: Sun, 6 Aug 2023 11:32:57 -0500 Subject: [PATCH] Fix ReaperScans(BR) and YugenMangas(ES) (#17407) * Reaper new api * I forgot to copy the DTO * Minor change * Minor change * Minor change * Also yugen * Update multisrc/overrides/heancms/reaperscans/src/ReaperScans.kt Co-authored-by: Alessandro Jean <14254807+alessandrojean@users.noreply.github.com> * Update multisrc/overrides/heancms/yugenmangas/src/YugenMangas.kt Co-authored-by: Alessandro Jean <14254807+alessandrojean@users.noreply.github.com> * Update multisrc/overrides/heancms/reaperscans/src/ReaperScans.kt Co-authored-by: Alessandro Jean <14254807+alessandrojean@users.noreply.github.com> * Update multisrc/overrides/heancms/yugenmangas/src/YugenMangas.kt Co-authored-by: Alessandro Jean <14254807+alessandrojean@users.noreply.github.com> --------- Co-authored-by: Alessandro Jean <14254807+alessandrojean@users.noreply.github.com> --- .../heancms/reaperscans/src/ReaperScans.kt | 86 +++++++++++++++++++ .../heancms/yugenmangas/src/YugenMangas.kt | 86 +++++++++++++++++++ .../tachiyomi/multisrc/heancms/HeanCms.kt | 7 +- .../tachiyomi/multisrc/heancms/HeanCmsDto.kt | 7 ++ .../multisrc/heancms/HeanCmsGenerator.kt | 4 +- .../tachiyomi/multisrc/heancms/HeanCmsIntl.kt | 6 ++ 6 files changed, 191 insertions(+), 5 deletions(-) diff --git a/multisrc/overrides/heancms/reaperscans/src/ReaperScans.kt b/multisrc/overrides/heancms/reaperscans/src/ReaperScans.kt index 78e494d92..89a6c1027 100644 --- a/multisrc/overrides/heancms/reaperscans/src/ReaperScans.kt +++ b/multisrc/overrides/heancms/reaperscans/src/ReaperScans.kt @@ -1,10 +1,21 @@ package eu.kanade.tachiyomi.extension.pt.reaperscans import eu.kanade.tachiyomi.multisrc.heancms.Genre +import eu.kanade.tachiyomi.multisrc.heancms.GenreFilter import eu.kanade.tachiyomi.multisrc.heancms.HeanCms +import eu.kanade.tachiyomi.multisrc.heancms.HeanCmsSeriesDto +import eu.kanade.tachiyomi.multisrc.heancms.SortByFilter +import eu.kanade.tachiyomi.multisrc.heancms.StatusFilter +import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.interceptor.rateLimitHost +import eu.kanade.tachiyomi.source.model.FilterList +import eu.kanade.tachiyomi.source.model.Page +import eu.kanade.tachiyomi.source.model.SChapter +import eu.kanade.tachiyomi.util.asJsoup import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.OkHttpClient +import okhttp3.Request +import okhttp3.Response import java.text.SimpleDateFormat import java.util.TimeZone @@ -27,6 +38,81 @@ class ReaperScans : HeanCms( timeZone = TimeZone.getTimeZone("GMT+01:00") } + override fun popularMangaRequest(page: Int): Request { + val url = "$apiUrl/query".toHttpUrl().newBuilder() + .addQueryParameter("query_string", "") + .addQueryParameter("series_status", "All") + .addQueryParameter("order", "desc") + .addQueryParameter("orderBy", "total_views") + .addQueryParameter("series_type", "Comic") + .addQueryParameter("page", page.toString()) + .addQueryParameter("perPage", "12") + .addQueryParameter("tags_ids", "[]") + + return GET(url.build(), headers) + } + + override fun latestUpdatesRequest(page: Int): Request { + val url = "$apiUrl/query".toHttpUrl().newBuilder() + .addQueryParameter("query_string", "") + .addQueryParameter("series_status", "All") + .addQueryParameter("order", "desc") + .addQueryParameter("orderBy", "latest") + .addQueryParameter("series_type", "Comic") + .addQueryParameter("page", page.toString()) + .addQueryParameter("perPage", "12") + .addQueryParameter("tags_ids", "[]") + + return GET(url.build(), headers) + } + + override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { + val sortByFilter = filters.firstInstanceOrNull() + val statusFilter = filters.firstInstanceOrNull() + + val tagIds = filters.firstInstanceOrNull()?.state.orEmpty() + .filter(Genre::state) + .map(Genre::id) + .joinToString(",", prefix = "[", postfix = "]") + + val url = "$apiUrl/query".toHttpUrl().newBuilder() + .addQueryParameter("query_string", query) + .addQueryParameter("series_status", statusFilter?.selected?.value ?: "All") + .addQueryParameter("order", if (sortByFilter?.state?.ascending == true) "asc" else "desc") + .addQueryParameter("orderBy", sortByFilter?.selected ?: "total_views") + .addQueryParameter("series_type", "Comic") + .addQueryParameter("page", page.toString()) + .addQueryParameter("perPage", "12") + .addQueryParameter("tags_ids", tagIds) + + return GET(url.build(), headers) + } + + override fun chapterListParse(response: Response): List { + val result = response.parseAs() + + val currentTimestamp = System.currentTimeMillis() + + return result.seasons.orEmpty() + .flatMap { it.chapters.orEmpty() } + .filterNot { it.price == 1 } + .map { it.toSChapter(result.slug, dateFormat) } + .filter { it.date_upload <= currentTimestamp } + } + + override fun pageListRequest(chapter: SChapter) = GET(baseUrl + chapter.url, headers) + + override fun pageListParse(response: Response): List { + val document = response.asJsoup() + + val images = document.selectFirst("div.min-h-screen > div.container > p.items-center") + + return images?.select("img").orEmpty().mapIndexed { i, img -> + val imageUrl = if (img.hasClass("lazy")) img.absUrl("data-src") else img.absUrl("src") + Page(i, "", imageUrl) + } + } + override fun getGenreList(): List = listOf( Genre("Artes Marciais", 2), Genre("Aventura", 10), diff --git a/multisrc/overrides/heancms/yugenmangas/src/YugenMangas.kt b/multisrc/overrides/heancms/yugenmangas/src/YugenMangas.kt index 9c51306b7..2ed16fc13 100644 --- a/multisrc/overrides/heancms/yugenmangas/src/YugenMangas.kt +++ b/multisrc/overrides/heancms/yugenmangas/src/YugenMangas.kt @@ -1,9 +1,20 @@ package eu.kanade.tachiyomi.extension.es.yugenmangas import eu.kanade.tachiyomi.multisrc.heancms.Genre +import eu.kanade.tachiyomi.multisrc.heancms.GenreFilter import eu.kanade.tachiyomi.multisrc.heancms.HeanCms +import eu.kanade.tachiyomi.multisrc.heancms.HeanCmsSeriesDto +import eu.kanade.tachiyomi.multisrc.heancms.SortByFilter +import eu.kanade.tachiyomi.multisrc.heancms.StatusFilter +import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.interceptor.rateLimitHost +import eu.kanade.tachiyomi.source.model.FilterList +import eu.kanade.tachiyomi.source.model.Page +import eu.kanade.tachiyomi.source.model.SChapter +import eu.kanade.tachiyomi.util.asJsoup import okhttp3.HttpUrl.Companion.toHttpUrl +import okhttp3.Request +import okhttp3.Response import java.text.SimpleDateFormat import java.util.TimeZone import java.util.concurrent.TimeUnit @@ -31,6 +42,81 @@ class YugenMangas : timeZone = TimeZone.getTimeZone("UTC") } + override fun popularMangaRequest(page: Int): Request { + val url = "$apiUrl/query".toHttpUrl().newBuilder() + .addQueryParameter("query_string", "") + .addQueryParameter("series_status", "All") + .addQueryParameter("order", "desc") + .addQueryParameter("orderBy", "total_views") + .addQueryParameter("series_type", "Comic") + .addQueryParameter("page", page.toString()) + .addQueryParameter("perPage", "12") + .addQueryParameter("tags_ids", "[]") + + return GET(url.build(), headers) + } + + override fun latestUpdatesRequest(page: Int): Request { + val url = "$apiUrl/query".toHttpUrl().newBuilder() + .addQueryParameter("query_string", "") + .addQueryParameter("series_status", "All") + .addQueryParameter("order", "desc") + .addQueryParameter("orderBy", "latest") + .addQueryParameter("series_type", "Comic") + .addQueryParameter("page", page.toString()) + .addQueryParameter("perPage", "12") + .addQueryParameter("tags_ids", "[]") + + return GET(url.build(), headers) + } + + override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { + val sortByFilter = filters.firstInstanceOrNull() + val statusFilter = filters.firstInstanceOrNull() + + val tagIds = filters.firstInstanceOrNull()?.state.orEmpty() + .filter(Genre::state) + .map(Genre::id) + .joinToString(",", prefix = "[", postfix = "]") + + val url = "$apiUrl/query".toHttpUrl().newBuilder() + .addQueryParameter("query_string", query) + .addQueryParameter("series_status", statusFilter?.selected?.value ?: "All") + .addQueryParameter("order", if (sortByFilter?.state?.ascending == true) "asc" else "desc") + .addQueryParameter("orderBy", sortByFilter?.selected ?: "total_views") + .addQueryParameter("series_type", "Comic") + .addQueryParameter("page", page.toString()) + .addQueryParameter("perPage", "12") + .addQueryParameter("tags_ids", tagIds) + + return GET(url.build(), headers) + } + + override fun chapterListParse(response: Response): List { + val result = response.parseAs() + + val currentTimestamp = System.currentTimeMillis() + + return result.seasons.orEmpty() + .flatMap { it.chapters.orEmpty() } + .filterNot { it.price == 1 } + .map { it.toSChapter(result.slug, dateFormat) } + .filter { it.date_upload <= currentTimestamp } + } + + override fun pageListRequest(chapter: SChapter) = GET(baseUrl + chapter.url, headers) + + override fun pageListParse(response: Response): List { + val document = response.asJsoup() + + val images = document.selectFirst("div.min-h-screen > div.container > p.items-center") + + return images?.select("img").orEmpty().mapIndexed { i, img -> + val imageUrl = if (img.hasClass("lazy")) img.absUrl("data-src") else img.absUrl("src") + Page(i, "", imageUrl) + } + } + override fun getGenreList(): List = listOf( Genre("+18", 1), Genre("Acción", 36), diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCms.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCms.kt index 469f25576..e1cdce178 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCms.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCms.kt @@ -267,6 +267,7 @@ abstract class HeanCms( } protected open fun getStatusList(): List = listOf( + Status(intl.statusAll, "All"), Status(intl.statusOngoing, "Ongoing"), Status(intl.statusOnHiatus, "Hiatus"), Status(intl.statusDropped, "Dropped"), @@ -294,13 +295,13 @@ abstract class HeanCms( return FilterList(filters) } - private inline fun Response.parseAs(): T = use { + protected inline fun Response.parseAs(): T = use { it.body.string().parseAs() } - private inline fun String.parseAs(): T = json.decodeFromString(this) + protected inline fun String.parseAs(): T = json.decodeFromString(this) - private inline fun List<*>.firstInstanceOrNull(): R? = + protected inline fun List<*>.firstInstanceOrNull(): R? = filterIsInstance().firstOrNull() companion object { diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCmsDto.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCmsDto.kt index 201220bb1..24e296a33 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCmsDto.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCmsDto.kt @@ -55,6 +55,7 @@ data class HeanCmsSeriesDto( val title: String, val tags: List? = emptyList(), val chapters: List? = emptyList(), + val seasons: List? = emptyList(), ) { fun toSManga( @@ -79,6 +80,12 @@ data class HeanCmsSeriesDto( } } +@Serializable +data class HeanCmsSeasonsDto( + val index: Int, + val chapters: List? = emptyList(), +) + @Serializable data class HeanCmsTagDto(val name: String) diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCmsGenerator.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCmsGenerator.kt index 6418abd61..ea924e216 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCmsGenerator.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCmsGenerator.kt @@ -14,8 +14,8 @@ class HeanCmsGenerator : ThemeSourceGenerator { override val sources = listOf( SingleLang("Glorious Scan", "https://gloriousscan.com", "pt-BR", overrideVersionCode = 17), SingleLang("Omega Scans", "https://omegascans.org", "en", isNsfw = true, overrideVersionCode = 17), - SingleLang("Reaper Scans", "https://reaperscans.net", "pt-BR", overrideVersionCode = 35), - SingleLang("YugenMangas", "https://yugenmangas.net", "es", isNsfw = true, overrideVersionCode = 5), + SingleLang("Reaper Scans", "https://reaperscans.net", "pt-BR", overrideVersionCode = 36), + SingleLang("YugenMangas", "https://yugenmangas.net", "es", isNsfw = true, overrideVersionCode = 6), ) companion object { diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCmsIntl.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCmsIntl.kt index 433a13b0f..60bb20f22 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCmsIntl.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/heancms/HeanCmsIntl.kt @@ -16,6 +16,12 @@ class HeanCmsIntl(lang: String) { else -> "Status" } + val statusAll: String = when (availableLang) { + BRAZILIAN_PORTUGUESE -> "Todos" + SPANISH -> "Todos" + else -> "All" + } + val statusOngoing: String = when (availableLang) { BRAZILIAN_PORTUGUESE -> "Em andamento" SPANISH -> "En curso"