From e1cabf0d2aec66dc79d2f283558854feb68452ac Mon Sep 17 00:00:00 2001 From: Mike <51273546+SnakeDoc83@users.noreply.github.com> Date: Tue, 18 Aug 2020 00:17:48 -0400 Subject: [PATCH] NewToki - fix pages (#4156) --- src/ko/newtoki/build.gradle | 2 +- .../tachiyomi/extension/ko/newtoki/NewToki.kt | 21 ++++------------ .../extension/ko/newtoki/NewTokiFactory.kt | 24 +++++++++++++++---- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/ko/newtoki/build.gradle b/src/ko/newtoki/build.gradle index f795e43c4..93a1d88a3 100644 --- a/src/ko/newtoki/build.gradle +++ b/src/ko/newtoki/build.gradle @@ -5,7 +5,7 @@ ext { extName = 'NewToki' pkgNameSuffix = 'ko.newtoki' extClass = '.NewTokiFactory' - extVersionCode = 11 + extVersionCode = 12 libVersion = '1.2' } diff --git a/src/ko/newtoki/src/eu/kanade/tachiyomi/extension/ko/newtoki/NewToki.kt b/src/ko/newtoki/src/eu/kanade/tachiyomi/extension/ko/newtoki/NewToki.kt index 8b6a660cf..b45dbe169 100644 --- a/src/ko/newtoki/src/eu/kanade/tachiyomi/extension/ko/newtoki/NewToki.kt +++ b/src/ko/newtoki/src/eu/kanade/tachiyomi/extension/ko/newtoki/NewToki.kt @@ -155,7 +155,7 @@ open class NewToki(override val name: String, private val defaultBaseUrl: String calendar.timeInMillis } else { - SimpleDateFormat("yyyy.MM.dd").parse(date).time + SimpleDateFormat("yyyy.MM.dd").parse(date)?.time ?: 0 } } catch (e: Exception) { e.printStackTrace() @@ -164,22 +164,9 @@ open class NewToki(override val name: String, private val defaultBaseUrl: String } override fun pageListParse(document: Document): List { - val pages = mutableListOf() - try { - document.select(".view-padding img") - .map { - val origin = it.attr("data-original") - if (origin.isNullOrEmpty()) it.attr("content") else origin - } - .forEach { - val url = if (it.contains("://")) it else baseUrl + it - pages.add(Page(pages.size, "", url)) - } - } catch (e: Exception) { - e.printStackTrace() - } - - return pages + return document.select("article > div > div > img") + .filterNot { it.attr("data-original").contains("blank.gif") } + .mapIndexed { i, img -> Page(i, "", img.attr("abs:data-original")) } } override fun latestUpdatesSelector() = popularMangaSelector() diff --git a/src/ko/newtoki/src/eu/kanade/tachiyomi/extension/ko/newtoki/NewTokiFactory.kt b/src/ko/newtoki/src/eu/kanade/tachiyomi/extension/ko/newtoki/NewTokiFactory.kt index 6b4c03602..df115b96c 100644 --- a/src/ko/newtoki/src/eu/kanade/tachiyomi/extension/ko/newtoki/NewTokiFactory.kt +++ b/src/ko/newtoki/src/eu/kanade/tachiyomi/extension/ko/newtoki/NewTokiFactory.kt @@ -5,18 +5,20 @@ import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.SourceFactory import eu.kanade.tachiyomi.source.model.Filter import eu.kanade.tachiyomi.source.model.FilterList +import eu.kanade.tachiyomi.source.model.Page import java.text.SimpleDateFormat import java.util.Date import java.util.Locale import okhttp3.HttpUrl import okhttp3.Request +import org.jsoup.Jsoup +import org.jsoup.nodes.Document /** - * Source changes domain names approximately once every 10 days (e.g. newtoki31.net to newtoki32.net) - * The domain name was newtoki32 on 2019-11-14, this should increment that by 1 for every 10 days that pass - * If that rate holds and the code is correct, this should be accurate for a good while + * Source changes domain names every few days (e.g. newtoki31.net to newtoki32.net) + * The domain name was newtoki32 on 2019-11-14, this attempts to match the rate at which the domain changes */ -private val domainNumber = 32 + ((Date().time - SimpleDateFormat("yyyy-MM-dd", Locale.US).parse("2019-11-14").time) / 864000000) +private val domainNumber = 32 + ((Date().time - SimpleDateFormat("yyyy-MM-dd", Locale.US).parse("2019-11-14")!!.time) / 595000000) class NewTokiFactory : SourceFactory { override fun createSources(): List = listOf( @@ -47,6 +49,20 @@ class NewTokiWebtoon : NewToki("NewToki (Webtoon)", "https://newtoki$domainNumbe return GET(url.toString()) } + private val htmlDataRegex = Regex("""html_data\+='([^']+)'""") + + override fun pageListParse(document: Document): List { + val script = document.select("script:containsData(html_data)").firstOrNull()?.data() ?: throw Exception("script not found") + + return htmlDataRegex.findAll(script).map { it.groupValues[1] } + .asIterable() + .flatMap { it.split(".") } + .joinToString("") { it.toIntOrNull(16)?.toChar()?.toString() ?: "" } + .let { Jsoup.parse(it) } + .select("img[alt]") + .mapIndexed { i, img -> Page(i, "", img.attr("abs:data-original")) } + } + private class SearchTypeList : Filter.Select("Type", arrayOf("전체", "일반웹툰", "성인웹툰", "BL/GL", "완결웹툰")) override fun getFilterList() = FilterList(