[MangaInUa] Fix chapters parsing

Koitharu 4 years ago
parent 42124fd3fc
commit 8a3b6df91d
No known key found for this signature in database
GPG Key ID: 8E861F8CE6E7CE27

@ -81,14 +81,16 @@ class MangaInUaParser(override val context: MangaLoaderContext) : MangaParser(Ma
val root = val root =
doc.body().getElementById("dle-content") ?: parseFailed("Cannot find root") doc.body().getElementById("dle-content") ?: parseFailed("Cannot find root")
val dateFormat = SimpleDateFormat("dd.MM.yyyy", Locale.US) val dateFormat = SimpleDateFormat("dd.MM.yyyy", Locale.US)
val chaptersRoot = root.selectFirst(".linkstocomics") val chapterNodes = root.selectFirstOrThrow(".linkstocomics")
.select(".ltcitems")
.filterNot { x -> x.selectFirst(".foruserreadedbar") != null }
var prevChapterName: String? = null var prevChapterName: String? = null
var i = 0 var i = 0
return manga.copy( return manga.copy(
description = root.selectFirst("div.item__full-description")?.text(), description = root.selectFirst("div.item__full-description")?.text(),
largeCoverUrl = root.selectFirst("div.item__full-sidebar--poster")?.selectFirst("img") largeCoverUrl = root.selectFirst("div.item__full-sidebar--poster")?.selectFirst("img")
?.attrAsAbsoluteUrlOrNull("src"), ?.attrAsAbsoluteUrlOrNull("src"),
chapters = chaptersRoot?.select("div.ltcitems")?.mapNotNull { item -> chapters = chapterNodes.mapNotNull { item ->
val href = item?.selectFirst("a")?.attrAsRelativeUrlOrNull("href") val href = item?.selectFirst("a")?.attrAsRelativeUrlOrNull("href")
?: return@mapNotNull null ?: return@mapNotNull null
val isAlternative = item.styleValueOrNull("background") != null val isAlternative = item.styleValueOrNull("background") != null
@ -113,7 +115,7 @@ class MangaInUaParser(override val context: MangaLoaderContext) : MangaParser(Ma
uploadDate = dateFormat.tryParse(item.selectFirst("div.ltcright")?.text()), uploadDate = dateFormat.tryParse(item.selectFirst("div.ltcright")?.text()),
source = source, source = source,
) )
}.orEmpty(), },
) )
} }

@ -1,6 +1,11 @@
package org.koitharu.kotatsu.test_util package org.koitharu.kotatsu.test_util
import androidx.collection.ArraySet import androidx.collection.ArraySet
import okhttp3.HttpUrl.Companion.toHttpUrl
import org.koitharu.kotatsu.parsers.model.Manga
import org.koitharu.kotatsu.parsers.model.MangaSource
import org.koitharu.kotatsu.parsers.model.RATING_UNKNOWN
import org.koitharu.kotatsu.parsers.util.toRelativeUrl
private val PATTERN_URL_ABSOLUTE = Regex("^https?://[\\s\\S]+", setOf(RegexOption.IGNORE_CASE)) private val PATTERN_URL_ABSOLUTE = Regex("^https?://[\\s\\S]+", setOf(RegexOption.IGNORE_CASE))
private val PATTERN_URL_RELATIVE = Regex("^/[\\s\\S]+", setOf(RegexOption.IGNORE_CASE)) private val PATTERN_URL_RELATIVE = Regex("^/[\\s\\S]+", setOf(RegexOption.IGNORE_CASE))
@ -37,3 +42,27 @@ inline operator fun <T> List<T>.component6(): T = get(5)
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline operator fun <T> List<T>.component7(): T = get(6) inline operator fun <T> List<T>.component7(): T = get(6)
fun mangaOf(source: MangaSource, url: String): Manga {
val httpUrl = url.toHttpUrl()
var id = 1125899906842597L
source.name.forEach { c -> id = 31 * id + c.code }
url.forEach { c -> id = 31 * id + c.code }
return Manga(
id = id,
title = httpUrl.pathSegments.last(),
altTitle = null,
url = url.toRelativeUrl(httpUrl.host),
publicUrl = url,
rating = RATING_UNKNOWN,
isNsfw = false,
coverUrl = "",
tags = emptySet(),
state = null,
author = null,
largeCoverUrl = null,
description = null,
chapters = null,
source = source,
)
}
Loading…
Cancel
Save