Skip to content

Commit 9146607

Browse files
authored
Mangapoisk: fix title parsing (#17523)
* fix title parsing * optimization * mixed content warning * apply suggestions * hide manga instead of error * hide all variants * add hasNextPage and move title parsing * hasNextPage for both cases * simplify selector
1 parent 29ae3ce commit 9146607

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

src/ru/mangapoisk/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ plugins {
66

77
keiyoushi {
88
name = "MangaPoisk"
9-
versionCode = 15
10-
contentWarning = ContentWarning.NSFW
9+
versionCode = 16
10+
contentWarning = ContentWarning.MIXED
1111
libVersion = "1.4"
1212

1313
source {

src/ru/mangapoisk/src/eu/kanade/tachiyomi/extension/ru/mangapoisk/MangaPoisk.kt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,32 @@ abstract class MangaPoisk : HttpSource() {
7474
val document = response.asJsoup()
7575
val isSearch = response.request.url.queryParameter("q") != null
7676
val selector = if (isSearch) "article.card" else ".manga-card"
77+
val hasNextPage = if (isSearch) {
78+
document.selectFirst("ul.pagination li a[aria-label*=Вперёд]:not([aria-disabled=true])") != null
79+
} else {
80+
document.selectFirst("ul li:contains(Вперёд) a") != null
81+
}
7782

7883
val mangas = document.select(selector).mapNotNull { element ->
7984
val urlElement = if (isSearch) element.selectFirst("a.card-about") else element.selectFirst("a")
8085
if (urlElement == null) return@mapNotNull null
86+
val titleParsed = if (isSearch) {
87+
element.selectFirst("div.post-description p.card-title")?.text()?.takeIf { it.isNotBlank() }
88+
?: element.selectFirst("a > h2.entry-title")?.text()?.takeIf { it.isNotBlank() }
89+
?: return@mapNotNull null
90+
} else {
91+
urlElement.attr("title").takeIf { it.isNotBlank() }
92+
?: return@mapNotNull null
93+
}.substringBefore("/")
8194

8295
SManga.create().apply {
8396
thumbnail_url = element.selectFirst("a > img")?.let { getImage(it) } ?: ""
8497
setUrlWithoutDomain(urlElement.attr("href"))
85-
86-
title = if (isSearch) {
87-
element.selectFirst("a > h2.entry-title")?.text()?.substringBefore("/") ?: ""
88-
} else {
89-
urlElement.attr("title").substringBefore("/")
90-
}
98+
title = titleParsed
9199
}
92100
}
93101

94-
return MangasPage(mangas, mangas.isNotEmpty())
102+
return MangasPage(mangas, hasNextPage)
95103
}
96104

97105
private fun getImage(element: Element): String {

0 commit comments

Comments
 (0)