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
This commit is contained in:
AbdullahM0hamed 2020-07-15 23:25:09 +01:00 committed by GitHub
parent 4c2505faa2
commit f93fbabbdd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 2 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = 'Webtoons'
pkgNameSuffix = 'all.webtoons'
extClass = '.WebtoonsFactory'
extVersionCode = 17
extVersionCode = 18
libVersion = '1.2'
}

View File

@ -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<Page> {
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))
}
}
}