diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/model/Manga.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/model/Manga.kt index c8bf3b80..39c14b79 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/model/Manga.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/model/Manga.kt @@ -94,6 +94,7 @@ class Manga( largeCoverUrl: String? = this.largeCoverUrl, description: String? = this.description, chapters: List? = this.chapters, + source: MangaSource = this.source, ) = Manga( id = id, title = title, @@ -109,7 +110,7 @@ class Manga( largeCoverUrl = largeCoverUrl, description = description, chapters = chapters, - source = source + source = source, ) override fun equals(other: Any?): Boolean { diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/ru/grouple/GroupleParser.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/ru/grouple/GroupleParser.kt index 7fcdab8f..8435e190 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/ru/grouple/GroupleParser.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/ru/grouple/GroupleParser.kt @@ -4,6 +4,7 @@ import kotlinx.coroutines.flow.channelFlow import kotlinx.coroutines.flow.first import kotlinx.coroutines.launch import okhttp3.Headers +import okhttp3.HttpUrl import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.Interceptor @@ -112,7 +113,8 @@ internal abstract class GroupleParser( } override suspend fun getDetails(manga: Manga): Manga { - val doc = webClient.httpGet(manga.url.toAbsoluteUrl(domain)).checkAuthRequired().parseHtml() + val response = webClient.httpGet(manga.url.toAbsoluteUrl(domain)).checkAuthRequired() + val doc = response.parseHtml() val root = doc.body().requireElementById("mangaBox").selectFirstOrThrow("div.leftContent") val dateFormat = SimpleDateFormat("dd.MM.yy", Locale.US) val coverImg = root.selectFirst("div.subject-cover")?.selectFirst("img") @@ -125,7 +127,9 @@ internal abstract class GroupleParser( } else { null } + val newSource = getSource(response.request.url) return manga.copy( + source = newSource, description = root.selectFirst("div.manga-description")?.html(), largeCoverUrl = coverImg?.attr("data-full"), coverUrl = coverImg?.attr("data-thumb") ?: manga.coverUrl, @@ -160,7 +164,7 @@ internal abstract class GroupleParser( url = href, uploadDate = dateFormat.tryParse(tr.selectFirst("td.date")?.text()), scanlator = translators, - source = source, + source = newSource, branch = null, ), ) @@ -177,7 +181,7 @@ internal abstract class GroupleParser( url = link, uploadDate = dateFormat.tryParse(jo.getStringOrNull("dateCreated")), scanlator = null, - source = source, + source = newSource, branch = translations[personId], ) } @@ -187,7 +191,11 @@ internal abstract class GroupleParser( } override suspend fun getPages(chapter: MangaChapter): List { - val doc = webClient.httpGet(chapter.url.toAbsoluteUrl(domain) + "?mtr=1").checkAuthRequired().parseHtml() + if (chapter.source != source) { // handle redirects between websites + return context.newParserInstance(chapter.source).getPages(chapter) + } + val url = chapter.url.toAbsoluteUrl(domain).toHttpUrl().newBuilder().setQueryParameter("mtr", "1").build() + val doc = webClient.httpGet(url).checkAuthRequired().parseHtml() val scripts = doc.select("script") for (script in scripts) { val data = script.html() @@ -292,6 +300,14 @@ internal abstract class GroupleParser( return root.select("div.tile").mapNotNull(::parseManga) } + protected open fun getSource(url: HttpUrl): MangaSource = when (url.host) { + in SeiMangaParser.domains -> MangaSource.SEIMANGA + in MintMangaParser.domains -> MangaSource.MINTMANGA + in ReadmangaParser.domains -> MangaSource.READMANGA_RU + in SelfMangaParser.domains -> MangaSource.SELFMANGA + else -> source + } + private fun getSortKey(sortOrder: SortOrder) = when (sortOrder) { SortOrder.ALPHABETICAL -> "name" SortOrder.POPULARITY -> "rate" diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/ru/grouple/MintMangaParser.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/ru/grouple/MintMangaParser.kt index ed2a77d6..205225d1 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/ru/grouple/MintMangaParser.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/ru/grouple/MintMangaParser.kt @@ -10,9 +10,14 @@ internal class MintMangaParser( context: MangaLoaderContext, ) : GroupleParser(context, MangaSource.MINTMANGA, 2) { - override val configKeyDomain = ConfigKey.Domain( - "24.mintmanga.one", - "mintmanga.live", - "mintmanga.com", - ) + override val configKeyDomain = ConfigKey.Domain(*domains) + + companion object { + + val domains = arrayOf( + "24.mintmanga.one", + "mintmanga.live", + "mintmanga.com", + ) + } } diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/ru/grouple/ReadmangaParser.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/ru/grouple/ReadmangaParser.kt index 473f8b2a..423fec3f 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/ru/grouple/ReadmangaParser.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/ru/grouple/ReadmangaParser.kt @@ -10,9 +10,14 @@ internal class ReadmangaParser( context: MangaLoaderContext, ) : GroupleParser(context, MangaSource.READMANGA_RU, 1) { - override val configKeyDomain = ConfigKey.Domain( - "readmanga.live", - "readmanga.io", - "readmanga.me", - ) + override val configKeyDomain = ConfigKey.Domain(*domains) + + companion object { + + val domains = arrayOf( + "readmanga.live", + "readmanga.io", + "readmanga.me", + ) + } } diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/ru/grouple/SeiMangaParser.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/ru/grouple/SeiMangaParser.kt new file mode 100644 index 00000000..173c699c --- /dev/null +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/ru/grouple/SeiMangaParser.kt @@ -0,0 +1,21 @@ +package org.koitharu.kotatsu.parsers.site.ru.grouple + +import org.koitharu.kotatsu.parsers.MangaLoaderContext +import org.koitharu.kotatsu.parsers.MangaSourceParser +import org.koitharu.kotatsu.parsers.config.ConfigKey +import org.koitharu.kotatsu.parsers.model.MangaSource + +@MangaSourceParser("SEIMANGA", "SeiManga", "ru") +internal class SeiMangaParser( + context: MangaLoaderContext, +) : GroupleParser(context, MangaSource.SEIMANGA, 21) { + + override val configKeyDomain = ConfigKey.Domain(*domains) + + companion object { + + val domains = arrayOf( + "seimanga.me", + ) + } +} diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/ru/grouple/SelfMangaParser.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/ru/grouple/SelfMangaParser.kt index a37884bd..6bd59bc5 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/ru/grouple/SelfMangaParser.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/ru/grouple/SelfMangaParser.kt @@ -11,6 +11,12 @@ internal class SelfMangaParser( context: MangaLoaderContext, ) : GroupleParser(context, MangaSource.SELFMANGA, 3) { - override val configKeyDomain = ConfigKey.Domain("selfmanga.live") + override val configKeyDomain = ConfigKey.Domain(*domains) + companion object { + + val domains = arrayOf( + "selfmanga.live", + ) + } }