From abb3f69a3325a740d1312ac6650471731e2116aa Mon Sep 17 00:00:00 2001 From: happywillow0 <45346080+happywillow0@users.noreply.github.com> Date: Thu, 19 Dec 2019 10:51:36 -0500 Subject: [PATCH] [Ready] Reader Manga / TMO sister update (#1784) * Update build.gradle * Update LectorManga.kt Update Chapter List URL and Page List request based on new TuMangaOnline code * Update LectorManga.kt * Update * Update * Update * Fix * Simplify --- src/es/lectormanga/build.gradle | 2 +- .../extension/es/lectormanga/LectorManga.kt | 85 +++++++++++++------ 2 files changed, 60 insertions(+), 27 deletions(-) diff --git a/src/es/lectormanga/build.gradle b/src/es/lectormanga/build.gradle index ebde03bbb..aa5c253d3 100755 --- a/src/es/lectormanga/build.gradle +++ b/src/es/lectormanga/build.gradle @@ -5,7 +5,7 @@ ext { appName = 'Tachiyomi: LectorManga' pkgNameSuffix = 'es.lectormanga' extClass = '.LectorManga' - extVersionCode = 2 + extVersionCode = 3 libVersion = '1.2' } diff --git a/src/es/lectormanga/src/eu/kanade/tachiyomi/extension/es/lectormanga/LectorManga.kt b/src/es/lectormanga/src/eu/kanade/tachiyomi/extension/es/lectormanga/LectorManga.kt index 7f9203675..ba2832019 100755 --- a/src/es/lectormanga/src/eu/kanade/tachiyomi/extension/es/lectormanga/LectorManga.kt +++ b/src/es/lectormanga/src/eu/kanade/tachiyomi/extension/es/lectormanga/LectorManga.kt @@ -10,11 +10,7 @@ import eu.kanade.tachiyomi.source.ConfigurableSource import eu.kanade.tachiyomi.source.model.* import eu.kanade.tachiyomi.source.online.ParsedHttpSource import eu.kanade.tachiyomi.util.asJsoup -import okhttp3.Headers -import okhttp3.HttpUrl -import okhttp3.OkHttpClient -import okhttp3.Request -import okhttp3.Response +import okhttp3.* import org.jsoup.nodes.Document import org.jsoup.nodes.Element import uy.kohesive.injekt.Injekt @@ -52,19 +48,17 @@ class LectorManga : ConfigurableSource, ParsedHttpSource() { .add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) Gecko/20100101 Firefox/60") } - private fun getBuilder(url: String): String { + private fun getBuilder(url: String, headers: Headers, formBody: FormBody): String { val req = Request.Builder() - .headers(headersBuilder() - .add("Cache-mode", "no-cache") - .build()) - .url(url) - .build() + .headers(headers) + .url(url) + .post(formBody) + .build() return client.newCall(req) - .execute() - .request() - .url() - .toString() + .execute() + .body()!! + .string() } private val preferences: SharedPreferences by lazy { @@ -190,25 +184,31 @@ class LectorManga : ConfigurableSource, ParsedHttpSource() { override fun searchMangaNextPageSelector() = popularMangaNextPageSelector() + private val scriptselector = "disqus_config" + override fun chapterListParse(response: Response): List { val document = response.asJsoup() + val chapterurl = response.request().url().toString() + val script = document.select("script:containsData($scriptselector)").html() + val chapteridselector = script.substringAfter("getAttribute(\"").substringBefore("\"") // One-shot if (document.select("#chapters").isEmpty()) { - return document.select(oneShotChapterListSelector()).map { oneShotChapterFromElement(it) } + return document.select(oneShotChapterListSelector()).map { oneShotChapterFromElement(it, chapterurl, chapteridselector) } } // Regular list of chapters val chapters = mutableListOf() val dupselect = getduppref()!! val chapterNames = document.select("#chapters h4.text-truncate") + val chapterNumbers = chapterNames.map { it.text().substringAfter("Capítulo").substringBefore("|").trim().toFloat() } val chapterInfos = document.select("#chapters .chapter-list") chapterNames.forEachIndexed { index, _ -> val scanlator = chapterInfos[index].select("li") if (dupselect=="one") { - scanlator.last { chapters.add(regularChapterFromElement(chapterNames[index].text(), it)) } + scanlator.last { chapters.add(regularChapterFromElement(chapterNames[index].text(), it , chapterNumbers[index], chapterurl, chapteridselector)) } } else { - scanlator.forEach { chapters.add(regularChapterFromElement(chapterNames[index].text(), it)) } + scanlator.forEach { chapters.add(regularChapterFromElement(chapterNames[index].text(), it ,chapterNumbers[index], chapterurl, chapteridselector)) } } } return chapters @@ -219,31 +219,64 @@ class LectorManga : ConfigurableSource, ParsedHttpSource() { private fun oneShotChapterListSelector() = "div.chapter-list-element > ul.list-group li.list-group-item" - private fun oneShotChapterFromElement(element: Element) = SChapter.create().apply { - setUrlWithoutDomain(element.select("div.row > .text-right > a").attr("href")) + private fun oneShotChapterFromElement(element: Element, chapterurl: String, chapteridselector: String) = SChapter.create().apply { + val button = element.select("div.row > .text-right > [$chapteridselector]") //button + url = "$chapterurl#${button.attr(chapteridselector)}" name = "One Shot" scanlator = element.select("div.col-md-6.text-truncate")?.text() date_upload = element.select("span.badge.badge-primary.p-2").first()?.text()?.let { parseChapterDate(it) } ?: 0 } - private fun regularChapterFromElement(chapterName: String, info: Element): SChapter { - //val number = name.substringBefore("|").substringAfter("Capítulo").trim().toFloat() + private fun regularChapterFromElement(chapterName: String, info: Element, number: Float, chapterurl: String, chapteridselector: String): SChapter { val chapter = SChapter.create() - chapter.setUrlWithoutDomain(info.select("div.row > .text-right > a").attr("href")) + val button = info.select("div.row > .text-right > [$chapteridselector]") //button + chapter.url = "$chapterurl#${button.attr(chapteridselector)}" chapter.name = chapterName chapter.scanlator = info.select("div.col-md-6.text-truncate")?.text() chapter.date_upload = info.select("span.badge.badge-primary.p-2").first()?.text()?.let { parseChapterDate(it) } ?: 0 - //chapter.chapter_number = number + chapter.chapter_number = number return chapter } 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 (chapterURL, chapterID) = chapter.url.split("#") + val response = client.newCall(GET(chapterURL, headers)).execute() + val document = response.asJsoup() + val csrftoken = document.select("meta[name=csrf-token]").attr("content") + val script = document.select("script:containsData($scriptselector)").html() + val functionID = script.substringAfter("addEventListener").substringAfter("{").substringBefore("(").trim().removePrefix("_") + val function = script.substringAfter("function _$functionID(").substringBefore("});") + val goto = function.substringAfter("url: '").substringBefore("'") + val paramChapter = function.substringAfter("data").substringBefore("\":_").substringAfterLast("\"") + val paramManga = function.substringAfter("data").substringBefore("\": ").substringAfterLast("\"") + val mangaID = function.substringAfter("data").substringAfter("\": ").substringBefore(",").removeSurrounding("'") + + val redirectheaders = headersBuilder() + .add("Referer", chapterURL) + .add("Content-Type","application/x-www-form-urlencoded; charset=UTF-8") + .add("X-CSRF-TOKEN",csrftoken) + .add("X-Requested-With","XMLHttpRequest") + .add(functionID,functionID) + .build() + + val formBody = FormBody.Builder() + .add(paramManga, mangaID) + .add(paramChapter, chapterID) + .build() + + val newurl = getBuilder(goto,redirectheaders,formBody) + val url = if (newurl.contains("paginated")) { + newurl.substringBefore("paginated") + "cascade" + } else newurl + + val headers = headersBuilder() + .add("Referer",newurl) + .build() // 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 = mutableListOf().apply {