[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:
parent
ac6f534b06
commit
abb3f69a33
|
@ -5,7 +5,7 @@ ext {
|
|||
appName = 'Tachiyomi: LectorManga'
|
||||
pkgNameSuffix = 'es.lectormanga'
|
||||
extClass = '.LectorManga'
|
||||
extVersionCode = 2
|
||||
extVersionCode = 3
|
||||
libVersion = '1.2'
|
||||
}
|
||||
|
||||
|
|
|
@ -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())
|
||||
.headers(headers)
|
||||
.url(url)
|
||||
.post(formBody)
|
||||
.build()
|
||||
|
||||
return client.newCall(req)
|
||||
.execute()
|
||||
.request()
|
||||
.url()
|
||||
.toString()
|
||||
.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<SChapter> {
|
||||
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<SChapter>()
|
||||
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<Page> = mutableListOf<Page>().apply {
|
||||
|
|
Loading…
Reference in New Issue