Fix TMO error. (#1175)

Fix TMO error #1166
This commit is contained in:
Edgar Mejía 2019-06-09 18:35:47 -06:00 committed by Eugene
parent bc861636fd
commit 5fda10228b
3 changed files with 155 additions and 110 deletions

View File

@ -23,4 +23,8 @@ public class Duktape implements Closeable {
throw new RuntimeException("Stub!");
}
public synchronized <T> T get(final String name, final Class<T> type) {
throw new RuntimeException("Stub!");
}
}

View File

@ -5,12 +5,13 @@ ext {
appName = 'Tachiyomi: TuMangaOnline'
pkgNameSuffix = 'es.tumangaonline'
extClass = '.TuMangaOnline'
extVersionCode = 4
extVersionCode = 5
libVersion = '1.2'
}
dependencies {
implementation project(':lib-ratelimit')
compileOnly project(':duktape-stub')
}
apply from: "$rootDir/common.gradle"

View File

@ -11,6 +11,7 @@ import org.jsoup.nodes.Element
import java.text.SimpleDateFormat
import java.util.*
import java.util.concurrent.TimeUnit
import com.squareup.duktape.Duktape
class TuMangaOnline : ParsedHttpSource() {
@ -200,16 +201,51 @@ class TuMangaOnline : ParsedHttpSource() {
private fun parseChapterDate(date: String): Long = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).parse(date).time
override fun pageListRequest(chapter: SChapter): Request {
val url = getBuilder(baseUrl + chapter.url)
val url = getBuilder(baseUrl + chapter.url).substringBeforeLast("/") + "/cascade"
// Get /cascade instead of /paginate to get all pages at once
return GET(url.substringBeforeLast("/") + "/cascade", headers)
return GET(url, headers)
}
override fun pageListParse(document: Document): List<Page> = mutableListOf<Page>().apply {
document.select("div#viewer-container > div.viewer-image-container > img.viewer-image")?.forEach {
add(Page(size, "", it.attr("src")))
override fun pageListParse(response: Response): List<Page> {
val pages = mutableListOf<Page>()
val body = response.body()!!.string()
var images = ""
val script = """
function chapterInit(data) {
pipe = "|";
idsR = /img_[^\.^;]+\.src\s*=\s*"([^"]+)/gm;
idData = ""
do {
m = idsR.exec(data);
if (m) {
idData = idData + pipe + m[1] ;
}
} while (m);
return idData;
}
"""
Duktape.create().use {
it.evaluate(script)
val chapterInit = it.get("chapterInit", JSIn::class.java)
images = chapterInit.call(true, body)
}
images.split("|").forEachIndexed { index, element ->
if (element.isNotEmpty()) {
pages.add(Page(index, baseUrl, element))
}
}
return pages
}
override fun pageListParse(document: Document) = throw UnsupportedOperationException("Not used")
override fun imageUrlRequest(page: Page): Request {
return GET(page.url, headers)
}
override fun imageUrlParse(document: Document) = throw UnsupportedOperationException("Not used")
@ -334,4 +370,8 @@ class TuMangaOnline : ParsedHttpSource() {
fun toUriPart() = vals[state].second
}
internal interface JSIn {
fun call(b: Boolean, data: String): String
}
}