Fix NyaHentai source implementation (#6099)
* enh: Add NyaHentai source support * upd: Change library version * bug: Fix integration * upd: Update version code * upd: Filter search to english chapters
This commit is contained in:
parent
c29c8cced6
commit
743d41a018
|
@ -5,7 +5,7 @@ ext {
|
||||||
extName = 'NyaHentai'
|
extName = 'NyaHentai'
|
||||||
pkgNameSuffix = 'en.nyahentai'
|
pkgNameSuffix = 'en.nyahentai'
|
||||||
extClass = '.NyaHentai'
|
extClass = '.NyaHentai'
|
||||||
extVersionCode = 2
|
extVersionCode = 3
|
||||||
libVersion = '1.2'
|
libVersion = '1.2'
|
||||||
containsNsfw = true
|
containsNsfw = true
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,10 +18,15 @@ import org.jsoup.nodes.Element
|
||||||
|
|
||||||
@Nsfw
|
@Nsfw
|
||||||
class NyaHentai : ParsedHttpSource() {
|
class NyaHentai : ParsedHttpSource() {
|
||||||
|
companion object {
|
||||||
|
const val TAG = "NyaHentai"
|
||||||
|
}
|
||||||
|
|
||||||
override val name = "NyaHentai (en)"
|
override val name = "NyaHentai (en)"
|
||||||
|
|
||||||
override val baseUrl = "https://nyahentai.com/language/english/"
|
override val baseUrl = "https://nyahentai.com"
|
||||||
|
|
||||||
|
val languageUrl = "$baseUrl/language/english"
|
||||||
|
|
||||||
override val lang = "en"
|
override val lang = "en"
|
||||||
|
|
||||||
|
@ -33,9 +38,9 @@ class NyaHentai : ParsedHttpSource() {
|
||||||
|
|
||||||
override fun latestUpdatesRequest(page: Int): Request {
|
override fun latestUpdatesRequest(page: Int): Request {
|
||||||
return if (page == 1) {
|
return if (page == 1) {
|
||||||
GET(baseUrl, headers)
|
GET(languageUrl, headers)
|
||||||
} else {
|
} else {
|
||||||
GET("$baseUrl/browse/page/$page", headers)
|
GET("$languageUrl/page/$page", headers)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,30 +48,32 @@ class NyaHentai : ParsedHttpSource() {
|
||||||
val manga = SManga.create()
|
val manga = SManga.create()
|
||||||
|
|
||||||
manga.setUrlWithoutDomain(element.attr("href"))
|
manga.setUrlWithoutDomain(element.attr("href"))
|
||||||
manga.title = element.select("div.title").text()
|
manga.title = element.select("div.caption").text()
|
||||||
manga.thumbnail_url = element.select("img.card-img-top").attr("abs:data-src")
|
manga.thumbnail_url = element.select("img.lazyload").attr("abs:data-src")
|
||||||
|
|
||||||
return manga
|
return manga
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun latestUpdatesNextPageSelector() = "section.pagination a[rel=next]"
|
override fun latestUpdatesNextPageSelector() = "section.pagination a[rel=next]"
|
||||||
|
|
||||||
|
private fun parseTAG(tag: String): String = tag.replace("\\((.*)\\)".toRegex(), "").trim()
|
||||||
|
|
||||||
override fun mangaDetailsParse(document: Document): SManga {
|
override fun mangaDetailsParse(document: Document): SManga {
|
||||||
val infoElement = document.select("div#bigcontainer.container")
|
val infoElement = document.select("div#bigcontainer.container")
|
||||||
val manga = SManga.create()
|
val manga = SManga.create()
|
||||||
val genres = mutableListOf<String>()
|
val genres = mutableListOf<String>()
|
||||||
|
|
||||||
document.select("div:contains(Tags) a").forEach { element ->
|
infoElement.select("div.tag-container:contains(Tags) a").forEach { element ->
|
||||||
val genre = element.text()
|
val genre = parseTAG(element.text())
|
||||||
genres.add(genre)
|
genres.add(genre)
|
||||||
}
|
}
|
||||||
|
|
||||||
manga.title = infoElement.select("h1").text()
|
manga.title = infoElement.select("h1").text()
|
||||||
manga.author = ""
|
manga.author = ""
|
||||||
manga.artist = infoElement.select("div:contains(Artists) a").text()
|
manga.artist = parseTAG(infoElement.select("div.tag-container:contains(Artists) a").text())
|
||||||
manga.status = SManga.COMPLETED
|
manga.status = SManga.COMPLETED
|
||||||
manga.genre = genres.joinToString(", ")
|
manga.genre = genres.joinToString(", ")
|
||||||
manga.thumbnail_url = document.select("div.cover a img").attr("abs:src")
|
manga.thumbnail_url = infoElement.select("div#cover a img.lazyload").attr("abs:data-src")
|
||||||
|
|
||||||
manga.description = getDesc(document)
|
manga.description = getDesc(document)
|
||||||
|
|
||||||
|
@ -76,7 +83,8 @@ class NyaHentai : ParsedHttpSource() {
|
||||||
private fun getDesc(document: Document): String {
|
private fun getDesc(document: Document): String {
|
||||||
val infoElement = document.select("div#bigcontainer.container")
|
val infoElement = document.select("div#bigcontainer.container")
|
||||||
|
|
||||||
val pages = infoElement.select("div:contains(pages)")?.text()?.replace(" pages", "")
|
val pages =
|
||||||
|
infoElement.select("div#info > div:contains(pages)")?.text()?.replace(" pages", "")
|
||||||
|
|
||||||
val multiDescriptions = listOf(
|
val multiDescriptions = listOf(
|
||||||
"Parodies",
|
"Parodies",
|
||||||
|
@ -84,7 +92,10 @@ class NyaHentai : ParsedHttpSource() {
|
||||||
"Groups",
|
"Groups",
|
||||||
"Languages",
|
"Languages",
|
||||||
"Categories"
|
"Categories"
|
||||||
).map { it to infoElement.select("div:contains($it) a").map { v -> v.text() } }
|
).map {
|
||||||
|
it to infoElement.select("div.tag-container:contains($it) a")
|
||||||
|
.map { v -> parseTAG(v.text()) }
|
||||||
|
}
|
||||||
.filter { !it.second.isNullOrEmpty() }
|
.filter { !it.second.isNullOrEmpty() }
|
||||||
.map { "${it.first}: ${it.second.joinToString()}" }
|
.map { "${it.first}: ${it.second.joinToString()}" }
|
||||||
|
|
||||||
|
@ -105,13 +116,12 @@ class NyaHentai : ParsedHttpSource() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun pageListRequest(chapter: SChapter): Request = GET(
|
override fun pageListRequest(chapter: SChapter): Request = GET("$baseUrl${chapter.url}list/1/")
|
||||||
"$baseUrl${chapter.url}list/1/"
|
|
||||||
)
|
|
||||||
|
|
||||||
override fun chapterListSelector(): String = throw UnsupportedOperationException("Not used")
|
override fun chapterListSelector(): String = throw UnsupportedOperationException("Not used")
|
||||||
|
|
||||||
override fun chapterFromElement(element: Element): SChapter = throw UnsupportedOperationException("Not used")
|
override fun chapterFromElement(element: Element): SChapter =
|
||||||
|
throw UnsupportedOperationException("Not used")
|
||||||
|
|
||||||
override fun pageListParse(document: Document): List<Page> {
|
override fun pageListParse(document: Document): List<Page> {
|
||||||
val pages = mutableListOf<Page>()
|
val pages = mutableListOf<Page>()
|
||||||
|
@ -125,18 +135,20 @@ class NyaHentai : ParsedHttpSource() {
|
||||||
val id = match?.groups?.get(2)?.value
|
val id = match?.groups?.get(2)?.value
|
||||||
val ext = match?.groups?.get(4)?.value
|
val ext = match?.groups?.get(4)?.value
|
||||||
|
|
||||||
val total: Int = (document.select(".num-pages").text()).toInt()
|
val total: Int = (document.select("#pagination-page-top .num-pages").text()).toInt()
|
||||||
|
|
||||||
for (i in 1..total) {
|
for (i in 1..total) {
|
||||||
pages.add(Page(i, "", "$base/galleries/$id/$i.jpg"))
|
pages.add(Page(i, "", "$base/galleries/$id/$i.$ext"))
|
||||||
}
|
}
|
||||||
|
|
||||||
return pages
|
return pages
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun imageUrlParse(document: Document): String = throw UnsupportedOperationException("Not used")
|
override fun imageUrlParse(document: Document): String =
|
||||||
|
throw UnsupportedOperationException("Not used")
|
||||||
|
|
||||||
override fun popularMangaRequest(page: Int): Request = GET("$baseUrl/popular/page/$page", headers)
|
override fun popularMangaRequest(page: Int): Request =
|
||||||
|
GET("$languageUrl/popular/page/$page", headers)
|
||||||
|
|
||||||
override fun popularMangaFromElement(element: Element) = latestUpdatesFromElement(element)
|
override fun popularMangaFromElement(element: Element) = latestUpdatesFromElement(element)
|
||||||
|
|
||||||
|
@ -148,7 +160,8 @@ class NyaHentai : ParsedHttpSource() {
|
||||||
|
|
||||||
// TODO: Additional filter options, specifically the type[] parameter
|
// TODO: Additional filter options, specifically the type[] parameter
|
||||||
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
|
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
|
||||||
var url = "$baseUrl/search/q_$query/page/$page"
|
// todo: remove "english" from the search query in the future
|
||||||
|
var url = "$baseUrl/search/q_$query english/page/$page"
|
||||||
|
|
||||||
if (query.isBlank()) {
|
if (query.isBlank()) {
|
||||||
filters.forEach { filter ->
|
filters.forEach { filter ->
|
||||||
|
|
Loading…
Reference in New Issue