NHentai - fix shortened titles ()

This commit is contained in:
Mike 2020-07-26 21:32:19 -04:00 committed by GitHub
parent a48ba550fd
commit 14ce7017e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 10 deletions
src/all/nhentai
build.gradle
src/eu/kanade/tachiyomi/extension/all/nhentai

@ -5,7 +5,7 @@ ext {
extName = 'NHentai' extName = 'NHentai'
pkgNameSuffix = 'all.nhentai' pkgNameSuffix = 'all.nhentai'
extClass = '.NHFactory' extClass = '.NHFactory'
extVersionCode = 26 extVersionCode = 27
libVersion = '1.2' libVersion = '1.2'
} }

@ -57,6 +57,9 @@ open class NHentai(
else -> false else -> false
} }
private val shortenTitleRegex = Regex("""(\[[^]]*]|[({][^)}]*[)}])""")
private fun String.shortenTitle() = this.replace(shortenTitleRegex, "").trim()
override fun setupPreferenceScreen(screen: androidx.preference.PreferenceScreen) { override fun setupPreferenceScreen(screen: androidx.preference.PreferenceScreen) {
val serverPref = androidx.preference.ListPreference(screen.context).apply { val serverPref = androidx.preference.ListPreference(screen.context).apply {
key = TITLE_PREF key = TITLE_PREF
@ -110,7 +113,7 @@ open class NHentai(
override fun latestUpdatesFromElement(element: Element) = SManga.create().apply { override fun latestUpdatesFromElement(element: Element) = SManga.create().apply {
setUrlWithoutDomain(element.select("a").attr("href")) setUrlWithoutDomain(element.select("a").attr("href"))
title = element.select("a > div").text().replace("\"", "").let { title = element.select("a > div").text().replace("\"", "").let {
if (displayFullTitle) it.trim() else it.substringAfter("]").substringBefore("[").trim() if (displayFullTitle) it.trim() else it.shortenTitle()
} }
thumbnail_url = element.select(".cover img").first().let { img -> thumbnail_url = element.select(".cover img").first().let { img ->
if (img.hasAttr("data-src")) img.attr("abs:data-src") else img.attr("abs:src") if (img.hasAttr("data-src")) img.attr("abs:data-src") else img.attr("abs:src")
@ -151,12 +154,12 @@ open class NHentai(
} }
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
val filters = if (filters.isEmpty()) getFilterList() else filters val filterList = if (filters.isEmpty()) getFilterList() else filters
val advQuery = combineQuery(filters) val advQuery = combineQuery(filterList)
val favoriteFilter = filters.findInstance<FavoriteFilter>() val favoriteFilter = filterList.findInstance<FavoriteFilter>()
val uploadedFilter = filters.findInstance<UploadedFilter>() val isOkayToSort = filterList.findInstance<UploadedFilter>()?.state?.isBlank() ?: true
if (favoriteFilter != null && favoriteFilter.state) { if (favoriteFilter?.state == true) {
val url = HttpUrl.parse("$baseUrl/favorites")!!.newBuilder() val url = HttpUrl.parse("$baseUrl/favorites")!!.newBuilder()
.addQueryParameter("q", "$query $advQuery") .addQueryParameter("q", "$query $advQuery")
.addQueryParameter("page", page.toString()) .addQueryParameter("page", page.toString())
@ -167,8 +170,8 @@ open class NHentai(
.addQueryParameter("q", "$query +$nhLang $advQuery") .addQueryParameter("q", "$query +$nhLang $advQuery")
.addQueryParameter("page", page.toString()) .addQueryParameter("page", page.toString())
if (uploadedFilter?.state?.isBlank() == true) { if (isOkayToSort) {
filters.findInstance<SortFilter>()?.let { f -> filterList.findInstance<SortFilter>()?.let { f ->
url.addQueryParameter("sort", f.toUriPart()) url.addQueryParameter("sort", f.toUriPart())
} }
} }
@ -227,7 +230,7 @@ open class NHentai(
val fullTitle = document.select("#info > h1").text().replace("\"", "").trim() val fullTitle = document.select("#info > h1").text().replace("\"", "").trim()
return SManga.create().apply { return SManga.create().apply {
title = if (displayFullTitle) fullTitle else fullTitle.substringAfter("]").substringBefore("[").trim() title = if (displayFullTitle) fullTitle else fullTitle.shortenTitle()
thumbnail_url = document.select("#cover > a > img").attr("data-src") thumbnail_url = document.select("#cover > a > img").attr("data-src")
status = SManga.COMPLETED status = SManga.COMPLETED
artist = getArtists(document) artist = getArtists(document)