diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/BatoToParser.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/BatoToParser.kt index 127c455f..e4e1f417 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/BatoToParser.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/BatoToParser.kt @@ -103,8 +103,7 @@ internal class BatoToParser(context: MangaLoaderContext) : PagedMangaParser( chapters = root.selectFirst(".episode-list") ?.selectFirst(".main") ?.children() - ?.reversed() - ?.mapChapters { i, div -> + ?.mapChapters(reversed = true) { i, div -> div.parseChapter(i) }.orEmpty(), ) diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/BlogTruyenParser.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/BlogTruyenParser.kt index 27ce2241..2167845f 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/BlogTruyenParser.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/BlogTruyenParser.kt @@ -75,7 +75,7 @@ class BlogTruyenParser(context: MangaLoaderContext) : private fun parseChapterList(doc: Document): List { val chapterList = doc.select("#list-chapters > p") - return chapterList.asReversed().mapChapters { index, element -> + return chapterList.mapChapters(reversed = true) { index, element -> val titleElement = element.selectFirst("span.title > a") ?: return@mapChapters null val name = titleElement.text() val relativeUrl = titleElement.attrAsRelativeUrl("href") diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/Manhwa18Parser.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/Manhwa18Parser.kt index 93d1e214..51673a03 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/Manhwa18Parser.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/Manhwa18Parser.kt @@ -56,7 +56,7 @@ class Manhwa18Parser(context: MangaLoaderContext) : description = docs.selectFirst(".series-summary .summary-content")?.html(), tags = tags.orEmpty(), state = state, - chapters = docs.select(".card-body > .list-chapters > a").asReversed().mapChapters { index, element -> + chapters = docs.select(".card-body > .list-chapters > a").mapChapters(reversed = true) { index, element -> // attrAsRelativeUrl only return page url without the '/' val chapterUrl = element.attrAsAbsoluteUrlOrNull("href")?.toRelativeUrl(domain) ?: return@mapChapters null diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/NetTruyenParser.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/NetTruyenParser.kt index 6b89233e..85aa6beb 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/NetTruyenParser.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/NetTruyenParser.kt @@ -35,7 +35,7 @@ class NetTruyenParser(context: MangaLoaderContext) : ?.toFloatOrNull() ?: 0f val chapterElements = doc.getElementById("nt_listchapter")?.select("ul > li") ?: doc.parseFailed() - val chapters = chapterElements.asReversed().mapChapters { index, element -> + val chapters = chapterElements.mapChapters(reversed = true) { index, element -> val a = element.selectFirst("div.chapter > a") ?: return@mapChapters null val relativeUrl = a.attrAsRelativeUrlOrNull("href") ?: return@mapChapters null val timeText = element.selectFirst("div.col-xs-4.text-center.no-wrap.small")?.text() diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/NineMangaParser.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/NineMangaParser.kt index f3b2f6b8..12c40dc3 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/NineMangaParser.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/NineMangaParser.kt @@ -110,7 +110,7 @@ internal abstract class NineMangaParser( description = infoRoot.getElementsByAttributeValue("itemprop", "description").first() ?.html()?.substringAfter(""), chapters = root.selectFirst("div.chapterbox")?.select("ul.sub_vol_ul > li") - ?.asReversed()?.mapChapters { i, li -> + ?.mapChapters(reversed = true) { i, li -> val a = li.selectFirst("a.chapter_list_a") val href = a?.attrAsRelativeUrlOrNull("href") ?.replace("%20", " ") ?: li.parseFailed("Link not found") diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/TruyentranhLHParser.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/TruyentranhLHParser.kt index 9c97582a..f3d28e9b 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/TruyentranhLHParser.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/TruyentranhLHParser.kt @@ -53,7 +53,7 @@ class TruyentranhLHParser(context: MangaLoaderContext) : state = state, rating = rating ?: RATING_UNKNOWN, description = infoHeaderEl?.selectFirst(".series-summary .summary-content")?.html(), - chapters = docs.select("ul.list-chapters.at-series > a").reversed().mapChapters { index, element -> + chapters = docs.select("ul.list-chapters.at-series > a").mapChapters(reversed = true) { index, element -> MangaChapter( id = generateUid(element.attrAsRelativeUrl("href")), name = element.selectFirst(".chapter-name")?.text()?.trim().orEmpty(), diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/UnionMangasParser.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/UnionMangasParser.kt index 491923a4..b71af6f3 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/UnionMangasParser.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/UnionMangasParser.kt @@ -90,7 +90,7 @@ class UnionMangasParser(context: MangaLoaderContext) : PagedMangaParser(context, it.toMangaTag() } ?: manga.tags, isNsfw = root.selectFirst(".alert-danger")?.html()?.contains("18 anos") == true, - chapters = root.select("div.row.capitulos").asReversed().mapChapters { i, div -> + chapters = root.select("div.row.capitulos").mapChapters(reversed = true) { i, div -> val a = div.selectFirstOrThrow("a") val href = a.attrAsRelativeUrl("href") val title = a.text() diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/grouple/GroupleParser.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/grouple/GroupleParser.kt index 4910deea..81c81b4a 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/grouple/GroupleParser.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/grouple/GroupleParser.kt @@ -174,7 +174,7 @@ internal abstract class GroupleParser( author = root.selectFirst("a.person-link")?.text() ?: manga.author, isNsfw = root.select(".alert-warning").any { it.ownText().contains(NSFW_ALERT) }, chapters = root.selectFirst("div.chapters-link")?.selectFirst("table") - ?.select("tr:has(td > a)")?.asReversed()?.mapChapters { i, tr -> + ?.select("tr:has(td > a)")?.mapChapters(reversed = true) { i, tr -> val a = tr.selectFirst("a.chapter-link") ?: return@mapChapters null val href = a.attrAsRelativeUrl("href") var translators = "" diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/madara/Hentai4Free.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/madara/Hentai4Free.kt index bec398fb..45b0de08 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/madara/Hentai4Free.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/madara/Hentai4Free.kt @@ -48,7 +48,7 @@ internal class Hentai4Free(context: MangaLoaderContext) : ).parseHtml() val ul = doc2.body().selectFirstOrThrow("ul") val dateFormat = SimpleDateFormat(datePattern, Locale.US) - return ul.select("li").asReversed().mapChapters { i, li -> + return ul.select("li").mapChapters(reversed = true) { i, li -> val a = li.selectFirst("a") val href = a?.attrAsRelativeUrlOrNull("href") ?: li.parseFailed("Link is missing") MangaChapter( diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/madara/Madara5Parser.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/madara/Madara5Parser.kt index 5c699324..6b7f23d6 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/madara/Madara5Parser.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/madara/Madara5Parser.kt @@ -127,7 +127,7 @@ abstract class Madara5Parser @InternalParsersApi constructor( private suspend fun loadChapters(mangaId: Long): List { val dateFormat = SimpleDateFormat(datePattern, sourceLocale) val doc = webClient.httpGet("https://${domain}/ajax-list-chapter?mangaID=$mangaId").parseHtml() - return doc.select("li.wp-manga-chapter").asReversed().mapChapters { i, li -> + return doc.select("li.wp-manga-chapter").mapChapters(reversed = true) { i, li -> val a = li.selectFirstOrThrow("a") val href = a.attrAsRelativeUrl("href") MangaChapter( diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/madara/Madara6Parser.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/madara/Madara6Parser.kt index a476644b..3eb178fd 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/madara/Madara6Parser.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/madara/Madara6Parser.kt @@ -47,7 +47,7 @@ internal abstract class Madara6Parser( val url = mangaUrl.toAbsoluteUrl(domain).removeSuffix('/') + "/ajax/chapters/" val dateFormat = SimpleDateFormat(datePattern, sourceLocale) val doc = webClient.httpPost(url, emptyMap()).parseHtml() - return doc.select("li.wp-manga-chapter").asReversed().mapChapters { i, li -> + return doc.select("li.wp-manga-chapter").mapChapters(reversed = true) { i, li -> val a = li.selectFirstOrThrow("a") val href = a.attrAsRelativeUrl("href") MangaChapter( diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/madara/MadaraParser.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/madara/MadaraParser.kt index 2dd1da08..9d75fba8 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/madara/MadaraParser.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/madara/MadaraParser.kt @@ -154,7 +154,7 @@ internal abstract class MadaraParser( val root2 = doc.body().selectFirstOrThrow("div.content-area") .selectFirstOrThrow("div.c-page") val dateFormat = SimpleDateFormat(datePattern, sourceLocale) - return root2.select("li").asReversed().mapChapters { i, li -> + return root2.select("li").mapChapters(reversed = true) { i, li -> val a = li.selectFirst("a") val href = a?.attrAsRelativeUrlOrNull("href") ?: li.parseFailed("Link is missing") MangaChapter( diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/madara/MangaDistrict.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/madara/MangaDistrict.kt index 75439adc..6a97a0d7 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/madara/MangaDistrict.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/madara/MangaDistrict.kt @@ -28,7 +28,7 @@ internal class MangaDistrict(context: MangaLoaderContext) : ).parseHtml() val ul = doc2.body().selectFirstOrThrow("ul") val dateFormat = SimpleDateFormat(datePattern, Locale.US) - return ul.select("li").asReversed().mapChapters { i, li -> + return ul.select("li").mapChapters(reversed = true) { i, li -> val a = li.selectFirst("a") val href = a?.attrAsRelativeUrlOrNull("href") ?: li.parseFailed("Link is missing") MangaChapter( diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/madara/NeatManga.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/madara/NeatManga.kt index 691938fc..ca4f5cda 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/madara/NeatManga.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/madara/NeatManga.kt @@ -53,7 +53,7 @@ internal class NeatManga(context: MangaLoaderContext) : MadaraParser(context, Ma ).parseHtml() val ul = doc2.body().selectFirstOrThrow("ul") val dateFormat = SimpleDateFormat(datePattern, Locale.US) - return ul.select("li").asReversed().mapChapters { i, li -> + return ul.select("li").mapChapters(reversed = true) { i, li -> val a = li.selectFirst("a") val href = a?.attrAsRelativeUrlOrNull("href") ?: li.parseFailed("Link is missing") MangaChapter( diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/mangareader/MangaReaderParser.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/mangareader/MangaReaderParser.kt index 6199f401..376d232e 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/mangareader/MangaReaderParser.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/mangareader/MangaReaderParser.kt @@ -38,7 +38,7 @@ internal abstract class MangaReaderParser( override suspend fun getDetails(manga: Manga): Manga { val docs = webClient.httpGet(manga.url.toAbsoluteUrl(domain)).parseHtml() - val chapters = docs.select("#chapterlist > ul > li").reversed().mapChapters { index, element -> + val chapters = docs.select("#chapterlist > ul > li").mapChapters(reversed = true) { index, element -> val url = element.selectFirst("a")?.attrAsRelativeUrl("href") ?: return@mapChapters null MangaChapter( id = generateUid(url), diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/multichan/ChanParser.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/multichan/ChanParser.kt index 082cfb5b..d89a4a87 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/multichan/ChanParser.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/multichan/ChanParser.kt @@ -92,7 +92,7 @@ internal abstract class ChanParser( return manga.copy( description = root.getElementById("description")?.html()?.substringBeforeLast(" + chapters = root.select("table.table_cha tr:gt(1)").mapChapters(reversed = true) { i, tr -> val href = tr?.selectFirst("a")?.attrAsRelativeUrlOrNull("href") ?: return@mapChapters null MangaChapter( diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/multichan/YaoiChanParser.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/multichan/YaoiChanParser.kt index 52b537ba..6e680678 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/multichan/YaoiChanParser.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/multichan/YaoiChanParser.kt @@ -11,29 +11,29 @@ import org.koitharu.kotatsu.parsers.util.* @MangaSourceParser("YAOICHAN", "Яой-тян", "ru") internal class YaoiChanParser(context: MangaLoaderContext) : ChanParser(context, MangaSource.YAOICHAN) { - override val configKeyDomain = ConfigKey.Domain("yaoi-chan.me", null) + override val configKeyDomain = ConfigKey.Domain("yaoi-chan.me", null) - override suspend fun getDetails(manga: Manga): Manga { - val doc = webClient.httpGet(manga.url.toAbsoluteUrl(domain)).parseHtml() - val root = doc.body().requireElementById("dle-content") - return manga.copy( - description = root.getElementById("description")?.html()?.substringBeforeLast(" - table.select("div.manga") - }.mapNotNull { it.selectFirst("a") }.reversed().mapChapters { i, a -> - val href = a.attrAsRelativeUrl("href") - MangaChapter( - id = generateUid(href), - name = a.text().trim(), - number = i + 1, - url = href, - uploadDate = 0L, - source = source, - scanlator = null, - branch = null, - ) - }, - ) - } + override suspend fun getDetails(manga: Manga): Manga { + val doc = webClient.httpGet(manga.url.toAbsoluteUrl(domain)).parseHtml() + val root = doc.body().requireElementById("dle-content") + return manga.copy( + description = root.getElementById("description")?.html()?.substringBeforeLast(" + table.select("div.manga") + }.mapNotNull { it.selectFirst("a") }.mapChapters(reversed = true) { i, a -> + val href = a.attrAsRelativeUrl("href") + MangaChapter( + id = generateUid(href), + name = a.text().trim(), + number = i + 1, + url = href, + uploadDate = 0L, + source = source, + scanlator = null, + branch = null, + ) + }, + ) + } } diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/util/Chapters.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/util/Chapters.kt index f506fbec..289080ec 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/util/Chapters.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/util/Chapters.kt @@ -4,20 +4,18 @@ import org.koitharu.kotatsu.parsers.InternalParsersApi import org.koitharu.kotatsu.parsers.model.MangaChapter @InternalParsersApi -inline fun Iterable.mapChapters( +inline fun List.mapChapters( reversed: Boolean = false, transform: (index: Int, T) -> MangaChapter?, ): List { val builder = ChaptersListBuilder(collectionSize()) var index = 0 - for (item in this) { + val elements = if (reversed) this.asReversed() else this + for (item in elements) { if (builder.add(transform(index, item))) { index++ } } - if (reversed) { - builder.reverse() - } return builder.toList() }