NHentai: fix tag parsing

This commit is contained in:
arkon 2020-06-09 09:15:14 -04:00
parent 9d80579eb9
commit 396c203047
3 changed files with 19 additions and 8 deletions

View File

@ -5,7 +5,7 @@ ext {
appName = 'Tachiyomi: NHentai'
pkgNameSuffix = 'all.nhentai'
extClass = '.NHFactory'
extVersionCode = 20
extVersionCode = 21
libVersion = '1.2'
}

View File

@ -6,12 +6,12 @@ import org.jsoup.nodes.Element
object NHUtils {
fun getArtists(document: Document): String {
val artists = document.select("#tags > div:nth-child(4) > span > a")
val artists = document.select("#tags > div:nth-child(4) > span > a .name")
return artists.joinToString(", ") { it.cleanTag() }
}
fun getGroups(document: Document): String? {
val groups = document.select("#tags > div:nth-child(5) > span > a")
val groups = document.select("#tags > div:nth-child(5) > span > a .name")
return if (groups.isNotEmpty()) {
groups.joinToString(", ") { it.cleanTag() }
} else {
@ -22,14 +22,21 @@ object NHUtils {
fun getTagDescription(document: Document): String {
val stringBuilder = StringBuilder()
val parodies = document.select("#tags > div:nth-child(1) > span > a")
val categories = document.select("#tags > div:nth-child(7) > span > a .name")
if (categories.isNotEmpty()) {
stringBuilder.append("Categories: ")
stringBuilder.append(categories.joinToString(", ") { it.cleanTag() })
stringBuilder.append("\n\n")
}
val parodies = document.select("#tags > div:nth-child(1) > span > a .name")
if (parodies.isNotEmpty()) {
stringBuilder.append("Parodies: ")
stringBuilder.append(parodies.joinToString(", ") { it.cleanTag() })
stringBuilder.append("\n\n")
}
val characters = document.select("#tags > div:nth-child(2) > span > a")
val characters = document.select("#tags > div:nth-child(2) > span > a .name")
if (characters.isNotEmpty()) {
stringBuilder.append("Characters: ")
stringBuilder.append(characters.joinToString(", ") { it.cleanTag() })
@ -39,10 +46,14 @@ object NHUtils {
}
fun getTags(document: Document): String {
val tags = document.select("#tags > div:nth-child(3) > span > a")
val tags = document.select("#tags > div:nth-child(3) > span > a .name")
return tags.map { it.cleanTag() }.sorted().joinToString(", ")
}
fun getNumPages(document: Document): String {
return document.select("#tags > div:nth-child(8) > span > a .name").first().cleanTag()
}
fun getTime(document: Document): Long {
val timeString = document.toString().substringAfter("datetime=\"").substringBefore("\">").replace("T", " ")

View File

@ -7,6 +7,7 @@ import android.support.v7.preference.PreferenceScreen
import eu.kanade.tachiyomi.extension.BuildConfig
import eu.kanade.tachiyomi.extension.all.nhentai.NHUtils.getArtists
import eu.kanade.tachiyomi.extension.all.nhentai.NHUtils.getGroups
import eu.kanade.tachiyomi.extension.all.nhentai.NHUtils.getNumPages
import eu.kanade.tachiyomi.extension.all.nhentai.NHUtils.getTagDescription
import eu.kanade.tachiyomi.extension.all.nhentai.NHUtils.getTags
import eu.kanade.tachiyomi.extension.all.nhentai.NHUtils.getTime
@ -200,9 +201,8 @@ open class NHentai(
description = "Full English and Japanese titles:\n"
.plus("$fullTitle\n")
.plus("${document.select("div#info h2").text()}\n\n")
.plus("Length: ${document.select("div#info div:contains(pages)").text()}\n")
.plus("Pages: ${getNumPages(document)}\n")
.plus("Favorited by: ${document.select("div#info i.fa-heart + span span").text().removeSurrounding("(", ")")}\n")
.plus("Categories: ${document.select("div.field-name:contains(Categories) span.tags a").first()?.ownText()}\n\n")
.plus(getTagDescription(document))
genre = getTags(document)
}