From f93fbabbddad26c68c921002d0742327ffc8f0a3 Mon Sep 17 00:00:00 2001 From: AbdullahM0hamed <25087116+AbdullahM0hamed@users.noreply.github.com> Date: Wed, 15 Jul 2020 23:25:09 +0100 Subject: [PATCH] Add motiontoon support to webtoons (#3798) * Add support for motiontoons to webtoons * Update build.gradle * Remove unnecessary import that I added for some reason * Remove more unnecessary imports * Hope this passes --- src/all/webtoons/build.gradle | 2 +- .../extension/all/webtoons/WebtoonsDefault.kt | 23 ++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/all/webtoons/build.gradle b/src/all/webtoons/build.gradle index 749a35b94..407578edb 100644 --- a/src/all/webtoons/build.gradle +++ b/src/all/webtoons/build.gradle @@ -5,7 +5,7 @@ ext { extName = 'Webtoons' pkgNameSuffix = 'all.webtoons' extClass = '.WebtoonsFactory' - extVersionCode = 17 + extVersionCode = 18 libVersion = '1.2' } diff --git a/src/all/webtoons/src/eu/kanade/tachiyomi/extension/all/webtoons/WebtoonsDefault.kt b/src/all/webtoons/src/eu/kanade/tachiyomi/extension/all/webtoons/WebtoonsDefault.kt index d3b6726f1..80231fa63 100644 --- a/src/all/webtoons/src/eu/kanade/tachiyomi/extension/all/webtoons/WebtoonsDefault.kt +++ b/src/all/webtoons/src/eu/kanade/tachiyomi/extension/all/webtoons/WebtoonsDefault.kt @@ -8,6 +8,7 @@ import java.text.SimpleDateFormat import java.util.Locale import org.jsoup.nodes.Document import org.jsoup.nodes.Element +import org.json.JSONObject open class WebtoonsDefault( override val lang: String, @@ -40,5 +41,25 @@ open class WebtoonsDefault( override fun chapterListRequest(manga: SManga) = GET("https://m.webtoons.com" + manga.url, mobileHeaders) - override fun pageListParse(document: Document) = document.select("div#_imageList > img").mapIndexed { i, element -> Page(i, "", element.attr("data-url")) } + override fun pageListParse(document: Document): List { + val pages = document.select("div#_imageList > img").mapIndexed { i, element -> Page(i, "", element.attr("data-url")) } + + if (pages.isNotEmpty()) { return pages } + + val docString = document.toString() + + val docUrlRegex = Regex("documentURL:.*?'(.*?)'") + val motiontoonPathRegex = Regex("jpg:.*?'(.*?)\\{") + + val docUrl = docUrlRegex.find(docString)!!.destructured.toList()[0] + val motiontoonPath = motiontoonPathRegex.find(docString)!!.destructured.toList()[0] + + val motiontoonJson = JSONObject(client.newCall(GET(docUrl, headers)).execute().body()!!.string()).getJSONObject("assets").getJSONObject("image") + + val keys = motiontoonJson.keys().asSequence().toList().filter { it.contains("layer") } + + return keys.mapIndexed { i, key -> + Page(i, "", motiontoonPath + motiontoonJson.getString(key)) + } + } }