[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
This commit is contained in:
happywillow0 2019-12-19 10:51:36 -05:00 committed by arkon
parent ac6f534b06
commit abb3f69a33
2 changed files with 60 additions and 27 deletions

View File

@ -5,7 +5,7 @@ ext {
appName = 'Tachiyomi: LectorManga' appName = 'Tachiyomi: LectorManga'
pkgNameSuffix = 'es.lectormanga' pkgNameSuffix = 'es.lectormanga'
extClass = '.LectorManga' extClass = '.LectorManga'
extVersionCode = 2 extVersionCode = 3
libVersion = '1.2' libVersion = '1.2'
} }

View File

@ -10,11 +10,7 @@ import eu.kanade.tachiyomi.source.ConfigurableSource
import eu.kanade.tachiyomi.source.model.* import eu.kanade.tachiyomi.source.model.*
import eu.kanade.tachiyomi.source.online.ParsedHttpSource import eu.kanade.tachiyomi.source.online.ParsedHttpSource
import eu.kanade.tachiyomi.util.asJsoup import eu.kanade.tachiyomi.util.asJsoup
import okhttp3.Headers import okhttp3.*
import okhttp3.HttpUrl
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
import org.jsoup.nodes.Document import org.jsoup.nodes.Document
import org.jsoup.nodes.Element import org.jsoup.nodes.Element
import uy.kohesive.injekt.Injekt 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") .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() val req = Request.Builder()
.headers(headersBuilder() .headers(headers)
.add("Cache-mode", "no-cache") .url(url)
.build()) .post(formBody)
.url(url) .build()
.build()
return client.newCall(req) return client.newCall(req)
.execute() .execute()
.request() .body()!!
.url() .string()
.toString()
} }
private val preferences: SharedPreferences by lazy { private val preferences: SharedPreferences by lazy {
@ -190,25 +184,31 @@ class LectorManga : ConfigurableSource, ParsedHttpSource() {
override fun searchMangaNextPageSelector() = popularMangaNextPageSelector() override fun searchMangaNextPageSelector() = popularMangaNextPageSelector()
private val scriptselector = "disqus_config"
override fun chapterListParse(response: Response): List<SChapter> { override fun chapterListParse(response: Response): List<SChapter> {
val document = response.asJsoup() 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 // One-shot
if (document.select("#chapters").isEmpty()) { 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 // Regular list of chapters
val chapters = mutableListOf<SChapter>() val chapters = mutableListOf<SChapter>()
val dupselect = getduppref()!! val dupselect = getduppref()!!
val chapterNames = document.select("#chapters h4.text-truncate") 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") val chapterInfos = document.select("#chapters .chapter-list")
chapterNames.forEachIndexed { index, _ -> chapterNames.forEachIndexed { index, _ ->
val scanlator = chapterInfos[index].select("li") val scanlator = chapterInfos[index].select("li")
if (dupselect=="one") { 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 { } 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 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 oneShotChapterListSelector() = "div.chapter-list-element > ul.list-group li.list-group-item"
private fun oneShotChapterFromElement(element: Element) = SChapter.create().apply { private fun oneShotChapterFromElement(element: Element, chapterurl: String, chapteridselector: String) = SChapter.create().apply {
setUrlWithoutDomain(element.select("div.row > .text-right > a").attr("href")) val button = element.select("div.row > .text-right > [$chapteridselector]") //button
url = "$chapterurl#${button.attr(chapteridselector)}"
name = "One Shot" name = "One Shot"
scanlator = element.select("div.col-md-6.text-truncate")?.text() 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 date_upload = element.select("span.badge.badge-primary.p-2").first()?.text()?.let { parseChapterDate(it) } ?: 0
} }
private fun regularChapterFromElement(chapterName: String, info: Element): SChapter { private fun regularChapterFromElement(chapterName: String, info: Element, number: Float, chapterurl: String, chapteridselector: String): SChapter {
//val number = name.substringBefore("|").substringAfter("Capítulo").trim().toFloat()
val chapter = SChapter.create() 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.name = chapterName
chapter.scanlator = info.select("div.col-md-6.text-truncate")?.text() 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.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 return chapter
} }
private fun parseChapterDate(date: String): Long = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).parse(date).time private fun parseChapterDate(date: String): Long = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).parse(date).time
override fun pageListRequest(chapter: SChapter): Request { 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 // 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<Page> = mutableListOf<Page>().apply { override fun pageListParse(document: Document): List<Page> = mutableListOf<Page>().apply {