Fix Batoto empty results

pull/123/head
Koitharu 4 years ago
parent 564f052a2f
commit d7f60fa95a
No known key found for this signature in database
GPG Key ID: 8E861F8CE6E7CE27

@ -62,12 +62,7 @@ class BatoToRepository(loaderContext: MangaLoaderContext) : RemoteMangaRepositor
append("&page=") append("&page=")
append(page) append(page)
} }
val body = loaderContext.httpGet(url).parseHtml().body() return parseList(url, page)
val activePage = getActivePage(body)
if (activePage != page) {
return emptyList()
}
return parseList(body.getElementById("series-list") ?: parseFailed("Cannot find root"))
} }
override suspend fun getDetails(manga: Manga): Manga { override suspend fun getDetails(manga: Manga): Manga {
@ -170,12 +165,7 @@ class BatoToRepository(loaderContext: MangaLoaderContext) : RemoteMangaRepositor
append("&page=") append("&page=")
append(page) append(page)
} }
val body = loaderContext.httpGet(url).parseHtml().body() return parseList(url, page)
val activePage = getActivePage(body)
if (activePage != page) {
return emptyList()
}
return parseList(body.getElementById("series-list") ?: parseFailed("Cannot find root"))
} }
private fun getActivePage(body: Element): Int = body.select("nav ul.pagination > li.page-item.active") private fun getActivePage(body: Element): Int = body.select("nav ul.pagination > li.page-item.active")
@ -183,26 +173,37 @@ class BatoToRepository(loaderContext: MangaLoaderContext) : RemoteMangaRepositor
?.text() ?.text()
?.toIntOrNull() ?: parseFailed("Cannot determine current page") ?.toIntOrNull() ?: parseFailed("Cannot determine current page")
private fun parseList(root: Element) = root.children().map { div -> private suspend fun parseList(url: String, page: Int): List<Manga> {
val a = div.selectFirst("a") ?: parseFailed() val body = loaderContext.httpGet(url).parseHtml().body()
val href = a.relUrl("href") if (body.selectFirst(".browse-no-matches") != null) {
val title = div.selectFirst(".item-title")?.text() ?: parseFailed("Title not found") return emptyList()
Manga( }
id = generateUid(href), val activePage = getActivePage(body)
title = title, if (activePage != page) {
altTitle = div.selectFirst(".item-alias")?.text()?.takeUnless { it == title }, return emptyList()
url = href, }
publicUrl = a.absUrl("href"), val root = body.getElementById("series-list") ?: parseFailed("Cannot find root")
rating = Manga.NO_RATING, return root.children().map { div ->
isNsfw = false, val a = div.selectFirst("a") ?: parseFailed()
coverUrl = div.selectFirst("img[src]")?.absUrl("src").orEmpty(), val href = a.relUrl("href")
largeCoverUrl = null, val title = div.selectFirst(".item-title")?.text() ?: parseFailed("Title not found")
description = null, Manga(
tags = div.selectFirst(".item-genre")?.parseTags().orEmpty(), id = generateUid(href),
state = null, title = title,
author = null, altTitle = div.selectFirst(".item-alias")?.text()?.takeUnless { it == title },
source = source, url = href,
) publicUrl = a.absUrl("href"),
rating = Manga.NO_RATING,
isNsfw = false,
coverUrl = div.selectFirst("img[src]")?.absUrl("src").orEmpty(),
largeCoverUrl = null,
description = null,
tags = div.selectFirst(".item-genre")?.parseTags().orEmpty(),
state = null,
author = null,
source = source,
)
}
} }
private fun Element.parseTags() = children().mapToSet { span -> private fun Element.parseTags() = children().mapToSet { span ->

Loading…
Cancel
Save