Junmeitu: fix page list parsing (#12556)
This commit is contained in:
parent
a4899a2169
commit
53cd29f87e
|
@ -1,11 +1,12 @@
|
||||||
apply plugin: 'com.android.application'
|
apply plugin: 'com.android.application'
|
||||||
apply plugin: 'kotlin-android'
|
apply plugin: 'kotlin-android'
|
||||||
|
apply plugin: 'kotlinx-serialization'
|
||||||
|
|
||||||
ext {
|
ext {
|
||||||
extName = 'Junmeitu'
|
extName = 'Junmeitu'
|
||||||
pkgNameSuffix = 'all.junmeitu'
|
pkgNameSuffix = 'all.junmeitu'
|
||||||
extClass = '.Junmeitu'
|
extClass = '.Junmeitu'
|
||||||
extVersionCode = 2
|
extVersionCode = 3
|
||||||
isNsfw = true
|
isNsfw = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,12 +12,17 @@ import eu.kanade.tachiyomi.source.model.Page
|
||||||
import eu.kanade.tachiyomi.source.model.SChapter
|
import eu.kanade.tachiyomi.source.model.SChapter
|
||||||
import eu.kanade.tachiyomi.source.model.SManga
|
import eu.kanade.tachiyomi.source.model.SManga
|
||||||
import eu.kanade.tachiyomi.source.online.ParsedHttpSource
|
import eu.kanade.tachiyomi.source.online.ParsedHttpSource
|
||||||
import eu.kanade.tachiyomi.util.asJsoup
|
import kotlinx.serialization.decodeFromString
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
|
import okhttp3.Response
|
||||||
|
import org.jsoup.Jsoup
|
||||||
import org.jsoup.nodes.Document
|
import org.jsoup.nodes.Document
|
||||||
import org.jsoup.nodes.Element
|
import org.jsoup.nodes.Element
|
||||||
|
import org.jsoup.select.Evaluator
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
|
import uy.kohesive.injekt.injectLazy
|
||||||
|
|
||||||
class Junmeitu : ConfigurableSource, ParsedHttpSource() {
|
class Junmeitu : ConfigurableSource, ParsedHttpSource() {
|
||||||
override val lang = "all"
|
override val lang = "all"
|
||||||
|
@ -25,6 +30,8 @@ class Junmeitu : ConfigurableSource, ParsedHttpSource() {
|
||||||
override val supportsLatest = true
|
override val supportsLatest = true
|
||||||
override val id = 4721197766605490540
|
override val id = 4721197766605490540
|
||||||
|
|
||||||
|
private val json: Json by injectLazy()
|
||||||
|
|
||||||
// Preference
|
// Preference
|
||||||
private val preferences: SharedPreferences by lazy {
|
private val preferences: SharedPreferences by lazy {
|
||||||
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
||||||
|
@ -40,13 +47,6 @@ class Junmeitu : ConfigurableSource, ParsedHttpSource() {
|
||||||
entryValues = MIRROR_PREF_ENTRY_VALUES
|
entryValues = MIRROR_PREF_ENTRY_VALUES
|
||||||
setDefaultValue(MIRROR_PREF_DEFAULT_VALUE)
|
setDefaultValue(MIRROR_PREF_DEFAULT_VALUE)
|
||||||
summary = "%s"
|
summary = "%s"
|
||||||
|
|
||||||
setOnPreferenceChangeListener { _, newValue ->
|
|
||||||
val selected = newValue as String
|
|
||||||
val index = findIndexOfValue(selected)
|
|
||||||
val entry = entryValues[index] as String
|
|
||||||
preferences.edit().putString("${MIRROR_PREF_KEY}_$lang", entry).commit()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
screen.addPreference(mirrorPref)
|
screen.addPreference(mirrorPref)
|
||||||
}
|
}
|
||||||
|
@ -112,11 +112,8 @@ class Junmeitu : ConfigurableSource, ParsedHttpSource() {
|
||||||
val manga = SManga.create()
|
val manga = SManga.create()
|
||||||
manga.title = document.selectFirst(".news-title,.title").text()
|
manga.title = document.selectFirst(".news-title,.title").text()
|
||||||
manga.description = document.select(".news-info,.picture-details").text() + "\n" + document.select(".introduce").text()
|
manga.description = document.select(".news-info,.picture-details").text() + "\n" + document.select(".introduce").text()
|
||||||
val genres = mutableListOf<String>()
|
manga.genre = document.select(".relation_tags > a").joinToString { it.text() }
|
||||||
document.select(".relation_tags > a").forEach {
|
manga.status = SManga.COMPLETED
|
||||||
genres.add(it.text())
|
|
||||||
}
|
|
||||||
manga.genre = genres.joinToString(", ")
|
|
||||||
return manga
|
return manga
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,39 +130,37 @@ class Junmeitu : ConfigurableSource, ParsedHttpSource() {
|
||||||
// Pages
|
// Pages
|
||||||
override fun pageListParse(document: Document): List<Page> {
|
override fun pageListParse(document: Document): List<Page> {
|
||||||
val numPages = document.select(".pages > a:nth-last-of-type(2)").text().toIntOrNull()
|
val numPages = document.select(".pages > a:nth-last-of-type(2)").text().toIntOrNull()
|
||||||
var url = document.select(".position a:last-child").first().attr("abs:href")
|
val newsBody = document.selectFirst(Evaluator.Class("news-body"))
|
||||||
val pages = mutableListOf<Page>()
|
if (newsBody == null) {
|
||||||
var count = 0
|
val baseUrl = this.baseUrl
|
||||||
if (numPages != null) {
|
val prefix = document.location().run {
|
||||||
url = url.substringBeforeLast(".")
|
val index = lastIndexOf('.') // .html
|
||||||
while (numPages != count) {
|
baseUrl + "/ajax_" + substring(baseUrl.length + 1, index) + '-'
|
||||||
count += 1
|
|
||||||
val doc = when (count) {
|
|
||||||
1 -> document
|
|
||||||
else -> client.newCall(GET("$url-$count.html")).execute().asJsoup()
|
|
||||||
}
|
|
||||||
doc.select(".pictures img,.news-body img").forEachIndexed() { index, it ->
|
|
||||||
val imgUrl = when {
|
|
||||||
it.hasAttr("data-original") -> it.attr("abs:data-original")
|
|
||||||
it.hasAttr("data-src") -> it.attr("abs:data-src")
|
|
||||||
it.hasAttr("data-lazy-src") -> it.attr("abs:data-lazy-src")
|
|
||||||
else -> it.attr("abs:src")
|
|
||||||
}
|
|
||||||
pages.add(Page(index, imgUrl, imgUrl))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
val postfix = document.selectFirst("body > script").data().run {
|
||||||
|
val script = substringAfterLast("pc_cid = ")
|
||||||
|
val categoryId = script.substringBefore(';')
|
||||||
|
val contentId = script.substringAfter("pc_id = ").substringBeforeLast(';')
|
||||||
|
".html?ajax=1&catid=$categoryId&conid=$contentId"
|
||||||
|
}
|
||||||
|
return (1..numPages!!).map { Page(it - 1, "$prefix$it$postfix") }
|
||||||
} else {
|
} else {
|
||||||
document.select(".pictures img,.news-body img").forEachIndexed() { index, it ->
|
return newsBody.select(Evaluator.Tag("img")).mapIndexed { index, it ->
|
||||||
val imgUrl = when {
|
val imgUrl = when {
|
||||||
it.hasAttr("data-original") -> it.attr("abs:data-original")
|
it.hasAttr("data-original") -> it.attr("abs:data-original")
|
||||||
it.hasAttr("data-src") -> it.attr("abs:data-src")
|
it.hasAttr("data-src") -> it.attr("abs:data-src")
|
||||||
it.hasAttr("data-lazy-src") -> it.attr("abs:data-lazy-src")
|
it.hasAttr("data-lazy-src") -> it.attr("abs:data-lazy-src")
|
||||||
else -> it.attr("abs:src")
|
else -> it.attr("abs:src")
|
||||||
}
|
}
|
||||||
pages.add(Page(index, imgUrl, imgUrl))
|
Page(index, imageUrl = imgUrl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pages
|
}
|
||||||
|
|
||||||
|
override fun imageUrlParse(response: Response): String {
|
||||||
|
val page: PageDto = json.decodeFromString(response.body!!.string())
|
||||||
|
val img = Jsoup.parseBodyFragment(page.pic).body().child(0)
|
||||||
|
return img.attr("src")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun imageUrlParse(document: Document): String = throw UnsupportedOperationException("Not used")
|
override fun imageUrlParse(document: Document): String = throw UnsupportedOperationException("Not used")
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
package eu.kanade.tachiyomi.extension.all.junmeitu
|
||||||
|
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
class PageDto(val pic: String)
|
Loading…
Reference in New Issue