JapanRead: fix wrong chapter loaded (#6456)
* JapanRead: fix wrong chapter loaded * JapanRead: Update version number
This commit is contained in:
parent
a3b9c284de
commit
e97c7bc8ab
|
@ -5,7 +5,7 @@ ext {
|
||||||
extName = 'Japanread'
|
extName = 'Japanread'
|
||||||
pkgNameSuffix = 'fr.japanread'
|
pkgNameSuffix = 'fr.japanread'
|
||||||
extClass = '.Japanread'
|
extClass = '.Japanread'
|
||||||
extVersionCode = 2
|
extVersionCode = 3
|
||||||
libVersion = '1.2'
|
libVersion = '1.2'
|
||||||
containsNsfw = true
|
containsNsfw = true
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@ 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 okhttp3.Request
|
import okhttp3.Request
|
||||||
import okhttp3.Response
|
|
||||||
import org.jsoup.nodes.Document
|
import org.jsoup.nodes.Document
|
||||||
import org.jsoup.nodes.Element
|
import org.jsoup.nodes.Element
|
||||||
import java.util.Calendar
|
import java.util.Calendar
|
||||||
|
@ -95,9 +94,12 @@ class Japanread : ParsedHttpSource() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Chapters
|
private fun apiHeaders() = headersBuilder().apply {
|
||||||
override fun chapterListSelector() = "#chapters div[data-row=\"chapter\"]"
|
add("Referer", baseUrl)
|
||||||
|
add("x-requested-with", "XMLHttpRequest")
|
||||||
|
}.build()
|
||||||
|
|
||||||
|
// Chapters
|
||||||
// Subtract relative date
|
// Subtract relative date
|
||||||
private fun parseRelativeDate(date: String): Long {
|
private fun parseRelativeDate(date: String): Long {
|
||||||
val trimmedDate = date.substringAfter("Il y a").trim().split(" ")
|
val trimmedDate = date.substringAfter("Il y a").trim().split(" ")
|
||||||
|
@ -117,6 +119,7 @@ class Japanread : ParsedHttpSource() {
|
||||||
return calendar.timeInMillis
|
return calendar.timeInMillis
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun chapterListSelector() = "#chapters div[data-row=\"chapter\"]"
|
||||||
override fun chapterFromElement(element: Element): SChapter {
|
override fun chapterFromElement(element: Element): SChapter {
|
||||||
return SChapter.create().apply {
|
return SChapter.create().apply {
|
||||||
name = element.select("div.col-lg-5 a").text()
|
name = element.select("div.col-lg-5 a").text()
|
||||||
|
@ -126,17 +129,62 @@ class Japanread : ParsedHttpSource() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pages
|
// Alternative way through API in case jSoup doesn't work anymore
|
||||||
override fun pageListRequest(chapter: SChapter): Request {
|
// It gives precise timestamp, but we are not using it
|
||||||
val chapterId = chapter.url.substringAfterLast("/")
|
// since the API wrongly returns null for the scanlation group
|
||||||
val pageHeaders = headersBuilder().apply {
|
/*private fun getChapterName(jsonElement: JsonElement): String {
|
||||||
add("x-requested-with", "XMLHttpRequest")
|
var name = ""
|
||||||
}.build()
|
|
||||||
return GET("$baseUrl/api/?id=$chapterId&type=chapter", pageHeaders)
|
if (jsonElement["volume"].asString != "") {
|
||||||
|
name += "Tome " + jsonElement["volume"].asString + " "
|
||||||
|
}
|
||||||
|
if (jsonElement["chapter"].asString != "") {
|
||||||
|
name += "Ch " + jsonElement["chapter"].asString + " "
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun pageListParse(response: Response): List<Page> {
|
if (jsonElement["title"].asString != "") {
|
||||||
val jsonData = response.body()!!.string()
|
if (name != "") {
|
||||||
|
name += " - "
|
||||||
|
}
|
||||||
|
name += jsonElement["title"].asString
|
||||||
|
}
|
||||||
|
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
override fun chapterListParse(response: Response): List<SChapter> {
|
||||||
|
val document = response.asJsoup()
|
||||||
|
val mangaId = document.select("div[data-avg]").attr("data-avg")
|
||||||
|
|
||||||
|
client.newCall(GET(baseUrl + document.select("#chapters div[data-row=chapter]").first().select("div.col-lg-5 a").attr("href"), headers)).execute()
|
||||||
|
|
||||||
|
val apiResponse = client.newCall(GET("$baseUrl/api/?id=$mangaId&type=manga", apiHeaders())).execute()
|
||||||
|
|
||||||
|
val jsonData = apiResponse.body()!!.string()
|
||||||
|
val json = JsonParser().parse(jsonData).asJsonObject
|
||||||
|
|
||||||
|
return json["chapter"].obj.entrySet()
|
||||||
|
.map {
|
||||||
|
SChapter.create().apply {
|
||||||
|
name = getChapterName(it.value.obj)
|
||||||
|
url = "$baseUrl/api/?id=${it.key}&type=chapter"
|
||||||
|
date_upload = it.value.obj["timestamp"].asLong * 1000
|
||||||
|
// scanlator = element.select(".chapter-list-group a").joinToString { it.text() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.sortedByDescending { it.date_upload }
|
||||||
|
}
|
||||||
|
override fun chapterListSelector() = throw UnsupportedOperationException("Not Used")
|
||||||
|
override fun chapterFromElement(element: Element): SChapter = throw UnsupportedOperationException("Not Used")*/
|
||||||
|
|
||||||
|
// Pages
|
||||||
|
override fun pageListRequest(chapter: SChapter): Request = GET("$baseUrl${chapter.url}", headers)
|
||||||
|
|
||||||
|
override fun pageListParse(document: Document): List<Page> {
|
||||||
|
val chapterId = document.select("meta[data-chapter-id]").attr("data-chapter-id")
|
||||||
|
|
||||||
|
val apiResponse = client.newCall(GET("$baseUrl/api/?id=$chapterId&type=chapter", apiHeaders())).execute()
|
||||||
|
|
||||||
|
val jsonData = apiResponse.body()!!.string()
|
||||||
val json = JsonParser().parse(jsonData).asJsonObject
|
val json = JsonParser().parse(jsonData).asJsonObject
|
||||||
|
|
||||||
val baseImagesUrl = json["baseImagesUrl"].string
|
val baseImagesUrl = json["baseImagesUrl"].string
|
||||||
|
@ -147,10 +195,7 @@ class Japanread : ParsedHttpSource() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun pageListParse(document: Document): List<Page> = throw UnsupportedOperationException("Not Used")
|
|
||||||
|
|
||||||
override fun imageUrlParse(document: Document): String = throw UnsupportedOperationException("Not Used")
|
override fun imageUrlParse(document: Document): String = throw UnsupportedOperationException("Not Used")
|
||||||
|
|
||||||
override fun imageRequest(page: Page): Request {
|
override fun imageRequest(page: Page): Request {
|
||||||
return GET(page.imageUrl!!, headers)
|
return GET(page.imageUrl!!, headers)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue