TMO / Lector Update (#2141)

TMO / Lector Update
This commit is contained in:
happywillow0 2020-01-30 14:47:09 -05:00 committed by GitHub
parent 9180b53728
commit c3e6ab3e73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 71 additions and 38 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 = 4 extVersionCode = 5
libVersion = '1.2' libVersion = '1.2'
} }

View File

@ -16,7 +16,7 @@ import org.jsoup.nodes.Element
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Locale import java.util.*
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
/** /**
@ -42,23 +42,26 @@ class LectorManga : ConfigurableSource, ParsedHttpSource() {
.followRedirects(true) .followRedirects(true)
.build()!! .build()!!
private val userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36"
override fun headersBuilder(): Headers.Builder { override fun headersBuilder(): Headers.Builder {
return Headers.Builder() return Headers.Builder()
.add("Referer", baseUrl) .add("User-Agent", userAgent)
.add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) Gecko/20100101 Firefox/60") .add("Referer", "$baseUrl/")
} }
private fun getBuilder(url: String, headers: Headers, formBody: FormBody): String { private fun getBuilder(url: String, headers: Headers, formBody: FormBody?, method: String): String {
val req = Request.Builder() val req = Request.Builder()
.headers(headers) .headers(headers)
.url(url) .url(url)
.post(formBody) .method(method,formBody)
.build() .build()
return client.newCall(req) return client.newCall(req)
.execute() .execute()
.body()!! .request()
.string() .url()
.toString()
} }
private val preferences: SharedPreferences by lazy { private val preferences: SharedPreferences by lazy {
@ -187,6 +190,8 @@ class LectorManga : ConfigurableSource, ParsedHttpSource() {
private val scriptselector = "disqus_config" private val scriptselector = "disqus_config"
override fun chapterListParse(response: Response): List<SChapter> { override fun chapterListParse(response: Response): List<SChapter> {
time1 = SimpleDateFormat("yyyy-M-d k:m:s", Locale.US).format(Date()) //Emulate when the chapter page is opened
val document = response.asJsoup() val document = response.asJsoup()
val chapterurl = response.request().url().toString() val chapterurl = response.request().url().toString()
val script = document.select("script:containsData($scriptselector)").html() val script = document.select("script:containsData($scriptselector)").html()
@ -220,8 +225,7 @@ 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, chapterurl: String, chapteridselector: String) = SChapter.create().apply { private fun oneShotChapterFromElement(element: Element, chapterurl: String, chapteridselector: String) = SChapter.create().apply {
val button = element.select("div.row > .text-right > [$chapteridselector]") //button url = "$chapterurl#${element.select("div.row > .text-right > form").attr("id")}"
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
@ -229,8 +233,7 @@ class LectorManga : ConfigurableSource, ParsedHttpSource() {
private fun regularChapterFromElement(chapterName: String, info: Element, number: Float, chapterurl: String, chapteridselector: String): SChapter { private fun regularChapterFromElement(chapterName: String, info: Element, number: Float, chapterurl: String, chapteridselector: String): SChapter {
val chapter = SChapter.create() val chapter = SChapter.create()
val button = info.select("div.row > .text-right > [$chapteridselector]") //button chapter.url = "$chapterurl#${info.select("div.row > .text-right > form").attr("id")}"
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
@ -239,40 +242,41 @@ class LectorManga : ConfigurableSource, ParsedHttpSource() {
} }
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
private var time1 = SimpleDateFormat("yyyy-M-d k:m:s", Locale.US).format(Date()) //Grab time at app launch, can be updated
override fun pageListRequest(chapter: SChapter): Request { override fun pageListRequest(chapter: SChapter): Request {
val (chapterURL, chapterID) = chapter.url.split("#") val (chapterURL, chapterID) = chapter.url.split("#")
val response = client.newCall(GET(chapterURL, headers)).execute() val response = client.newCall(GET(chapterURL, headers)).execute() //Get chapter page for current token
val document = response.asJsoup() val document = response.asJsoup()
val csrftoken = document.select("meta[name=csrf-token]").attr("content") val geturl = document.select("form#$chapterID").attr("action") //Get redirect URL
val script = document.select("script:containsData($scriptselector)").html() val token = document.select("form#$chapterID input").attr("value") //Get token
val functionID = script.substringAfter("addEventListener").substringAfter("{").substringBefore("(").trim().removePrefix("_") val method = document.select("form#$chapterID").attr("method") //Check POST or GET
val function = script.substringAfter("function _$functionID(").substringBefore("});") val time2 = SimpleDateFormat("yyyy-M-d k:m:s", Locale.US).format(Date()) //Get time of chapter request
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() val getHeaders = headersBuilder()
.add("User-Agent", userAgent)
.add("Referer", chapterURL) .add("Referer", chapterURL)
.add("Content-Type","application/x-www-form-urlencoded; charset=UTF-8") .add("Content-Type", "application/x-www-form-urlencoded")
.add("X-CSRF-TOKEN",csrftoken)
.add("X-Requested-With","XMLHttpRequest")
.add(functionID,functionID)
.build() .build()
val formBody = FormBody.Builder() val formBody = when (method) {
.add(paramManga, mangaID) "GET" -> null
.add(paramChapter, chapterID) "POST" -> FormBody.Builder()
.build() .add("_token", token)
.add("time", time1)
.add("time2", time2)
.build()
else -> throw UnsupportedOperationException("Unknown method. Open GitHub issue")
}
val newurl = getBuilder(goto,redirectheaders,formBody) val newurl = getBuilder(geturl,getHeaders,formBody,method)
val url = if (newurl.contains("paginated")) { val url = if (newurl.contains("paginated")) {
newurl.substringBefore("paginated") + "cascade" newurl.substringBefore("paginated") + "cascade"
} else newurl } else newurl
val headers = headersBuilder() val headers = headersBuilder()
.add("Referer",newurl) .add("User-Agent", userAgent)
.add("Referer", "$baseUrl/library/manga/")
.build() .build()
// Get /cascade instead of /paginate to get all pages at once // Get /cascade instead of /paginate to get all pages at once

View File

@ -5,7 +5,7 @@ ext {
appName = 'Tachiyomi: TuMangaOnline' appName = 'Tachiyomi: TuMangaOnline'
pkgNameSuffix = 'es.tumangaonline' pkgNameSuffix = 'es.tumangaonline'
extClass = '.TuMangaOnline' extClass = '.TuMangaOnline'
extVersionCode = 20 extVersionCode = 21
libVersion = '1.2' libVersion = '1.2'
} }

View File

@ -200,6 +200,8 @@ class TuMangaOnline : ConfigurableSource, ParsedHttpSource() {
private val scriptselector = "addEventListener" private val scriptselector = "addEventListener"
override fun chapterListParse(response: Response): List<SChapter> { override fun chapterListParse(response: Response): List<SChapter> {
time1 = SimpleDateFormat("yyyy-M-d k:m:s", Locale.US).format(Date()) //Emulate when the chapter pate is opened
val document = response.asJsoup() val document = response.asJsoup()
val chapterurl = response.request().url().toString() val chapterurl = response.request().url().toString()
val script = document.select("script:containsData($scriptselector)").html() val script = document.select("script:containsData($scriptselector)").html()
@ -233,7 +235,7 @@ class TuMangaOnline : 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, chapterurl: String, chapteridselector: String) = 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")) url = "$chapterurl#${element.select("div.row > .text-right > form").attr("id")}"
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
@ -242,7 +244,7 @@ class TuMangaOnline : ConfigurableSource, ParsedHttpSource() {
private fun regularChapterListSelector() = "div.chapters > ul.list-group li.p-0.list-group-item" private fun regularChapterListSelector() = "div.chapters > ul.list-group li.p-0.list-group-item"
private fun regularChapterFromElement(element: Element, chname: String, number: Float, chapterurl: String, chapteridselector: String) = SChapter.create().apply { private fun regularChapterFromElement(element: Element, chname: String, number: Float, chapterurl: String, chapteridselector: String) = SChapter.create().apply {
setUrlWithoutDomain(element.select("div.row > .text-right > a").attr("href")) url = "$chapterurl#${element.select("div.row > .text-right > form").attr("id")}"
name = chname name = chname
chapter_number = number chapter_number = number
scanlator = element.select("div.col-md-6.text-truncate")?.text() scanlator = element.select("div.col-md-6.text-truncate")?.text()
@ -250,13 +252,40 @@ class TuMangaOnline : ConfigurableSource, ParsedHttpSource() {
} }
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
private var time1 = SimpleDateFormat("yyyy-M-d k:m:s", Locale.US).format(Date()) //Grab time at app launch, can be updated
override fun pageListRequest(chapter: SChapter): Request { override fun pageListRequest(chapter: SChapter): Request {
val (chapterURL, chapterID) = chapter.url.split("#")
val response = client.newCall(GET(chapterURL, headers)).execute() //Get chapter page for current token
val document = response.asJsoup()
val geturl = document.select("form#$chapterID").attr("action") //Get redirect URL
val token = document.select("form#$chapterID input").attr("value") //Get token
val method = document.select("form#$chapterID").attr("method") //Check POST or GET
val time2 = SimpleDateFormat("yyyy-M-d k:m:s", Locale.US).format(Date()) //Get time of chapter request
val getHeaders = headersBuilder()
.add("User-Agent", userAgent)
.add("Referer", chapterURL)
.add("Content-Type", "application/x-www-form-urlencoded")
.build()
val formBody = when (method) {
"GET" -> null
"POST" -> FormBody.Builder()
.add("_token", token)
.add("time", time1)
.add("time2", time2)
.build()
else -> throw UnsupportedOperationException("Unknown method. Open GitHub issue")
}
val url = getBuilder(geturl,getHeaders,formBody,method).substringBeforeLast("/") + "/${getPageMethod()}"
val headers = headersBuilder() val headers = headersBuilder()
.add("User-Agent", userAgent) .add("User-Agent", userAgent)
.add("Referer", "$baseUrl/library/manga/") .add("Referer", chapterURL)
.build() .build()
val url = getBuilder(baseUrl + chapter.url,headers,null,"GET").substringBeforeLast("/") + "/${getPageMethod()}"
return GET(url, headers) return GET(url, headers)
} }