From 98604a69cb8d7d5160d99a5e5b2550f303f41618 Mon Sep 17 00:00:00 2001 From: morcefaster <51055657+morcefaster@users.noreply.github.com> Date: Wed, 11 Mar 2020 17:04:28 +0200 Subject: [PATCH] Japscan not loading images dirty fix (#2315) (#2404) Japscan not loading images dirty fix (#2315) --- src/fr/japscan/build.gradle | 2 +- .../tachiyomi/extension/fr/japscan/Japscan.kt | 72 ++++++++++++++++++- 2 files changed, 70 insertions(+), 4 deletions(-) diff --git a/src/fr/japscan/build.gradle b/src/fr/japscan/build.gradle index 5784631a7..1da3d4397 100644 --- a/src/fr/japscan/build.gradle +++ b/src/fr/japscan/build.gradle @@ -5,7 +5,7 @@ ext { appName = 'Tachiyomi: Japscan' pkgNameSuffix = 'fr.japscan' extClass = '.Japscan' - extVersionCode = 16 + extVersionCode = 18 libVersion = '1.2' } diff --git a/src/fr/japscan/src/eu/kanade/tachiyomi/extension/fr/japscan/Japscan.kt b/src/fr/japscan/src/eu/kanade/tachiyomi/extension/fr/japscan/Japscan.kt index 0ca54be5b..2744c9685 100644 --- a/src/fr/japscan/src/eu/kanade/tachiyomi/extension/fr/japscan/Japscan.kt +++ b/src/fr/japscan/src/eu/kanade/tachiyomi/extension/fr/japscan/Japscan.kt @@ -30,6 +30,24 @@ class Japscan : ParsedHttpSource() { override val supportsLatest = true + val keysheetChapterUrl1 = "https://www.japscan.co/lecture-en-ligne/bloody-kiss/volume-1/" + val keysheetChapterUrl2= "https://www.japscan.co/lecture-en-ligne/1-nen-a-gumi-no-monster/1/" + + var keysheet = "0123456789abcdefghijklmnopqrstuvwxyz" + + val realpage_bk_2 = "221518b2f9a20842e4c5379223a5881255d2e522c32277923242520284a542f28085b952e422b1e5a97216b262e5e6621535a22/552c5c112f3e2c4f2e122f025517294925042f322d54513e25822c7e2ev0274751116a4266386a0d56w2506a578b562f6exd2e6/65f435e996fs95fw1160125x715062eve104e33va38454bu632x1315b4fxa10244e2c438932ta38v1158d4e323cx237x933u435/1038xa1" + val realpage_bk_4 = "a336f98370e3d9130516d873045639a35633468374c3389353f36313759623633176406345c3e2e60033e713c37687239616b3f6732612a3d4437/5738213e1d642b3d5a3f113d4e3b666c423e973a8d3bja3a50662772597a4270196akc6b74609a613277l1337d6c0776ge60k3220735l85410640/33a25325d2a927b446al56al36fi8672e4dl120113dj7205543ja455354i847lc436955lf26315739529643h744j6249c5e4e40l34el14ci74822/49l12" + val realpage_bk_14 = "4033163017801660626355d0118326c0c3202380719055b0e070e020a2e3d0c04883e750d2a029f397704470f0e3a4208303f0b370a37930816022/f0097038e3a9a0e2c0781021d0f303a120f6d075b05nd0e27379d48204b164f8a36od374a3c6f3e0b4fpa0841357f44kc3co798740c8c02p924853/e7b0398052d996e491534p331p331m8319616p6958d01n8922c1cn2122827m915pb1e372ep29a0e2d0c24681el51dna926f291714p71fpe1am2189/01fpb9" + val realpage_bk_29 = "e952450996d945591172e4b9e0528549828912293089e469a939a939c172c9d997b276f991c9a842566973f96922e359c222f9b21/932984980e931e908d98742f819f179a7a9d0c972e2a07975794419az6931c248032173809377523a028322b51279a3fbf903e2d6/03dw72bae8a6399bd1f7f26bf8d7196za85140fz00d121ey504b0092d14b581971e9b1e5508x408z8815213080eb60ab30ay30c87/0cbd8" + val realpage_monster_1="d7b023a0f83391903313f630b090311054d04910118397b0c140003368b3e3d343e0a390a76032c0d990f16387104953d110405378d030/4388f0d7a052f05820e853203377a04760e06034a0c5b019c05p805223198472d41174f863aqe394f3e6c32014ar30642387f41m13dqe9/f8a0f7700rf95890era9a9e26211a1a29062dqb12ra1fp319p993r11fq31bp9936115pd1421214819pb9c8410p396qb1e2d14qe1ap99a8/603rc9" + val realPageUrls = listOf( + realpage_bk_2, + realpage_bk_4, + realpage_bk_14, + realpage_bk_29, + realpage_monster_1 + ) + override val client: OkHttpClient = network.cloudflareClient.newBuilder().addInterceptor { chain -> val indicator = "&decodeImage" @@ -57,6 +75,17 @@ class Japscan : ParsedHttpSource() { } } + fun loadKeysheetChapters() { + var response = client.newCall(GET(keysheetChapterUrl1, headers)).execute() + var doc = response.asJsoup() + response = client.newCall(GET(keysheetChapterUrl2, headers)).execute() + var doc2 = response.asJsoup() + + // 「MULTI-DOCUMENT DRIFTING!!」 + createKeysheet(doc, doc2) + } + + //Popular override fun popularMangaRequest(page: Int): Request { return GET("$baseUrl/mangas/", headers) @@ -87,7 +116,7 @@ class Japscan : ParsedHttpSource() { } return manga } - + //Latest override fun latestUpdatesRequest(page: Int): Request { return GET(baseUrl, headers) @@ -195,19 +224,56 @@ class Japscan : ParsedHttpSource() { } } + fun createKeysheet(doc: Document, doc2: Document) { + val pageUrls = mutableListOf() + + var pages = doc.select("select#pages").first()?.select("option")!!; // if this is null we're done + for (i in listOf(1,3,13,28)) { + pageUrls.add(pages[i].attr("data-img").substring("https://c.japscan.co/".length, pages[i].attr("data-img").length - 4)) + } + pages = doc2.select("select#pages").first()?.select("option")!!; // if this is null we're done + for (i in listOf(0)) { + pageUrls.add(pages[i].attr("data-img").substring("https://c.japscan.co/".length, pages[i].attr("data-img").length - 4)) + } + + + var az = "0123456789abcdefghijklmnopqrstuvwxyz".toCharArray() + var ks = "0123456789abcdefghijklmnopqrstuvwxyz".toCharArray() + + for (i in 0 until realPageUrls.count()) + for (j in 0 until realPageUrls[i].length) { + if(realPageUrls[i][j] != pageUrls[i][j]) { + ks[az.indexOf(pageUrls[i][j])] = realPageUrls[i][j] + + } + } + keysheet = ks.joinToString("") + } + override fun pageListParse(document: Document): List { + loadKeysheetChapters() val pages = mutableListOf() var imagePath = "(.*\\/).*".toRegex().find(document.select("#image").attr("data-src"))?.groupValues?.get(1) val imageScrambled = if (!document.select("script[src^='/js/iYFbYi_U']").isNullOrEmpty()) "&decodeImage" else "" document.select("select#pages").first()?.select("option")?.forEach { if (it.attr("data-img").startsWith("http")) imagePath = "" - pages.add(Page(pages.size, "", "$imagePath${it.attr("data-img")}$imageScrambled")) + pages.add(Page(pages.size, "", decodeImageUrl("$imagePath${it.attr("data-img")}")+"$imageScrambled")) } return pages } + private fun decodeImageUrl(url: String): String { + val az = "0123456789abcdefghijklmnopqrstuvwxyz" + // skip https://, cut after next slash and before extension + var urlBase = url.substring(0, url.indexOf('/', 10)+1) + var extension = url.substring(url.length - 4, url.length) + var encodedPart = url.substring(url.indexOf('/', 10)+1, url.length-4) + + return urlBase+encodedPart.map { if (az.indexOf(it) < 0) it else keysheet[az.indexOf(it)]}.joinToString("")+extension + } + override fun imageUrlParse(document: Document): String = "" private fun decodeImage(img: InputStream): ByteArray { @@ -254,7 +320,7 @@ class Japscan : ParsedHttpSource() { result.compress(Bitmap.CompressFormat.PNG, 100, output) return output.toByteArray() } - + //Filters private class TextField(name: String, val key: String) : Filter.Text(name) private class PageList(pages: Array): Filter.Select("Page #", arrayOf(0,*pages))