NHentai update (#1809)
This commit is contained in:
parent
6fae2f4df3
commit
f6c80ee3a4
|
@ -5,8 +5,13 @@ ext {
|
|||
appName = 'Tachiyomi: NHentai'
|
||||
pkgNameSuffix = 'all.nhentai'
|
||||
extClass = '.NHFactory'
|
||||
extVersionCode = 14
|
||||
extVersionCode = 15
|
||||
libVersion = '1.2'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly project(':preference-stub')
|
||||
compileOnly 'com.github.inorichi.injekt:injekt-core:65b0440'
|
||||
}
|
||||
|
||||
apply from: "$rootDir/common.gradle"
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package eu.kanade.tachiyomi.extension.all.nhentai
|
||||
|
||||
import android.app.Application
|
||||
import android.content.SharedPreferences
|
||||
import android.support.v7.preference.ListPreference
|
||||
import android.support.v7.preference.PreferenceScreen
|
||||
import eu.kanade.tachiyomi.extension.BuildConfig
|
||||
import eu.kanade.tachiyomi.extension.all.nhentai.NHUtils.Companion.getArtists
|
||||
import eu.kanade.tachiyomi.extension.all.nhentai.NHUtils.Companion.getGroups
|
||||
|
@ -7,6 +11,7 @@ import eu.kanade.tachiyomi.extension.all.nhentai.NHUtils.Companion.getTags
|
|||
import eu.kanade.tachiyomi.extension.all.nhentai.NHUtils.Companion.getTime
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.network.asObservableSuccess
|
||||
import eu.kanade.tachiyomi.source.ConfigurableSource
|
||||
import eu.kanade.tachiyomi.source.model.Filter
|
||||
import eu.kanade.tachiyomi.source.model.FilterList
|
||||
import eu.kanade.tachiyomi.source.model.MangasPage
|
||||
|
@ -23,11 +28,13 @@ import okhttp3.Response
|
|||
import org.jsoup.nodes.Document
|
||||
import org.jsoup.nodes.Element
|
||||
import rx.Observable
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
|
||||
open class NHentai(
|
||||
override val lang: String,
|
||||
private val nhLang: String
|
||||
) : ParsedHttpSource() {
|
||||
) : ConfigurableSource, ParsedHttpSource() {
|
||||
|
||||
final override val baseUrl = "https://nhentai.net"
|
||||
|
||||
|
@ -41,16 +48,50 @@ open class NHentai(
|
|||
add("User-Agent", "Tachiyomi/${BuildConfig.VERSION_NAME} ${System.getProperty("http.agent")}")
|
||||
}
|
||||
|
||||
private val preferences: SharedPreferences by lazy {
|
||||
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
||||
}
|
||||
|
||||
private var displayFullTitle: Boolean = when(preferences.getString(TITLE_PREF, "full")){
|
||||
"full" -> true
|
||||
else -> false
|
||||
}
|
||||
|
||||
override fun setupPreferenceScreen(screen: PreferenceScreen) {
|
||||
val serverPref = ListPreference(screen.context).apply {
|
||||
key = TITLE_PREF
|
||||
title = TITLE_PREF
|
||||
entries = arrayOf("Full Title", "Short Title")
|
||||
entryValues = arrayOf("full", "short")
|
||||
summary = "%s"
|
||||
|
||||
setOnPreferenceChangeListener { _, newValue ->
|
||||
displayFullTitle = when(newValue){
|
||||
"full" -> true
|
||||
else -> false
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
if(!preferences.contains(TITLE_PREF))
|
||||
preferences.edit().putString(TITLE_PREF, "full").apply()
|
||||
|
||||
screen.addPreference(serverPref)
|
||||
}
|
||||
|
||||
override fun latestUpdatesRequest(page: Int) = GET("$baseUrl/language/$nhLang/?page=$page", headers)
|
||||
|
||||
override fun latestUpdatesSelector() = "#content .gallery"
|
||||
|
||||
override fun latestUpdatesFromElement(element: Element) = SManga.create().apply {
|
||||
setUrlWithoutDomain(element.select("a").attr("href"))
|
||||
title = element.select("a > div").text().replace("\"", "").trim()
|
||||
|
||||
val img = element.select(".cover img").first()
|
||||
thumbnail_url = if (img.hasAttr("data-src")) img.absUrl("data-src") else img.absUrl("src")
|
||||
title = element.select("a > div").text().replace("\"", "").let {
|
||||
if (displayFullTitle) it.trim() else it.substringAfter("]").substringBefore("[").trim()
|
||||
}
|
||||
thumbnail_url = element.select(".cover img").first().let { img ->
|
||||
if (img.hasAttr("data-src")) img.attr("abs:data-src") else img.attr("abs:src")
|
||||
}
|
||||
}
|
||||
|
||||
override fun latestUpdatesNextPageSelector() = "#content > section.pagination > a.next"
|
||||
|
@ -102,13 +143,24 @@ open class NHentai(
|
|||
|
||||
override fun searchMangaNextPageSelector() = latestUpdatesNextPageSelector()
|
||||
|
||||
override fun mangaDetailsParse(document: Document) = SManga.create().apply {
|
||||
title = document.select("#info > h1").text().replace("\"", "").trim()
|
||||
thumbnail_url = document.select("#cover > a > img").attr("data-src")
|
||||
status = SManga.COMPLETED
|
||||
artist = getArtists(document)
|
||||
author = artist
|
||||
description = getTags(document)
|
||||
override fun mangaDetailsParse(document: Document): SManga {
|
||||
val fullTitle = document.select("#info > h1").text().replace("\"", "").trim()
|
||||
|
||||
return SManga.create().apply {
|
||||
title = if (displayFullTitle) fullTitle else fullTitle.substringAfter("]").substringBefore("[").trim()
|
||||
thumbnail_url = document.select("#cover > a > img").attr("data-src")
|
||||
status = SManga.COMPLETED
|
||||
artist = getArtists(document)
|
||||
author = artist
|
||||
// Some people want these additional details in description
|
||||
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("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(getTags(document))
|
||||
}
|
||||
}
|
||||
|
||||
override fun chapterListRequest(manga: SManga): Request = GET("$baseUrl${manga.url}", headers)
|
||||
|
@ -150,6 +202,7 @@ open class NHentai(
|
|||
|
||||
companion object {
|
||||
const val PREFIX_ID_SEARCH = "id:"
|
||||
private const val TITLE_PREF = "Display manga title as:"
|
||||
}
|
||||
|
||||
private class SortFilter : Filter.Select<String>("Sort", arrayOf("Popular", "Date"))
|
||||
|
|
Loading…
Reference in New Issue