From 87974b4bb4be3c96ee6967ab77023f7b88ca7d35 Mon Sep 17 00:00:00 2001 From: Zakhar Timoshenko Date: Thu, 19 May 2022 19:42:33 +0300 Subject: [PATCH] Details, pages --- .../kotatsu/parsers/site/MangaInUaParser.kt | 48 ++++++++++++++++--- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/MangaInUaParser.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/MangaInUaParser.kt index b3c4942a..299cf08b 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/MangaInUaParser.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/MangaInUaParser.kt @@ -7,6 +7,7 @@ import org.koitharu.kotatsu.parsers.config.ConfigKey import org.koitharu.kotatsu.parsers.exception.ParseException import org.koitharu.kotatsu.parsers.model.* import org.koitharu.kotatsu.parsers.util.* +import java.text.SimpleDateFormat import java.util.* @MangaSourceParser("MANGAINUA", "MANGA/in/UA", "uk") @@ -28,8 +29,8 @@ class MangaInUaParser(override val context: MangaLoaderContext) : MangaParser(Ma !query.isNullOrEmpty() -> parseFailed("Search currently unavailable") // TODO tags.isNullOrEmpty() -> "/mangas/page/$page".withDomain() tags.size == 1 -> "${tags.first().key}/page/$page" - tags.size > 1 -> throw IllegalArgumentException("This source supports only 1 tag") - else -> "/mangas/${page}".withDomain() + tags.size > 1 -> throw IllegalArgumentException("Це джерело підтримує вибір тільки одного жанру") + else -> "/mangas/page/${page}".withDomain() } val doc = context.httpGet(url).parseHtml() val container = doc.body().getElementById("dle-content") ?: parseFailed("Container not found") @@ -54,7 +55,7 @@ class MangaInUaParser(override val context: MangaLoaderContext) : MangaParser(Ma item.selectFirst("div.card__category")?.select("a")?.mapToSet { MangaTag( title = it.ownText(), - key = it.attr("href").removeSuffix("/").substringAfterLast('/'), + key = it.attr("href").removeSuffix("/"), source = source, ) } @@ -67,11 +68,46 @@ class MangaInUaParser(override val context: MangaLoaderContext) : MangaParser(Ma } override suspend fun getDetails(manga: Manga): Manga { - TODO("Not yet implemented") + val doc = context.httpGet(manga.url.withDomain()).parseHtml() + val root = + doc.body().getElementById("dle-content") ?: parseFailed("Cannot find root") + val dateFormat = SimpleDateFormat("dd.MM.yyyy", Locale.US) + return manga.copy( + description = root.selectFirst("div.item__full-description")?.text(), + largeCoverUrl = root.selectFirst("div.item__full-sidebar--poster")?.selectFirst("img")?.attrAsAbsoluteUrl("src").orEmpty(), + chapters = root.select("div.linkstocomics").mapIndexedNotNull { i, item -> + val href = item?.selectFirst("a")?.attr("href") + ?: return@mapIndexedNotNull null + MangaChapter( + id = generateUid(href), + name = item.selectFirst("a")?.text().orEmpty(), + number = i + 1, + url = href, + scanlator = null, + branch = null, + uploadDate = dateFormat.tryParse(item.selectFirst("div.ltcright")?.text()), + source = source, + ) + }, + ) } override suspend fun getPages(chapter: MangaChapter): List { - TODO("Not yet implemented") + val fullUrl = chapter.url.withDomain() + val doc = context.httpGet(fullUrl).parseHtml() + val root = doc.body().getElementById("comics") + ?: throw ParseException("Root not found") + return root.select("ul.xfieldimagegallery").map { ul -> + val img = ul.selectFirst("img") ?: parseFailed("Page image not found") + val url = img.attrAsAbsoluteUrl("data-src") + MangaPage( + id = generateUid(url), + url = url, + preview = null, + referer = fullUrl, + source = source, + ) + } } override suspend fun getTags(): Set { @@ -82,7 +118,7 @@ class MangaInUaParser(override val context: MangaLoaderContext) : MangaParser(Ma val a = li.selectFirst("a") ?: throw ParseException("a is null") MangaTag( title = a.ownText(), - key = a.attr("href").removeSuffix("/").substringAfterLast('/'), + key = a.attr("href").removeSuffix("/"), source = source, ) }