From 2ef94affe46ddda079b1d25e19e97d8ecbdbb50c Mon Sep 17 00:00:00 2001 From: Alessandro Jean Date: Mon, 28 Sep 2020 00:03:55 -0300 Subject: [PATCH] Add Toonei. (#4444) Add Toonei --- src/pt/mangasproject/build.gradle | 2 +- .../pt/mangasproject/MangasProject.kt | 37 ++++++++----------- .../pt/mangasproject/MangasProjectFactory.kt | 14 ++++++- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/src/pt/mangasproject/build.gradle b/src/pt/mangasproject/build.gradle index 9db9952bd..ef3dc7a9a 100644 --- a/src/pt/mangasproject/build.gradle +++ b/src/pt/mangasproject/build.gradle @@ -5,7 +5,7 @@ ext { extName = 'mangásPROJECT' pkgNameSuffix = 'pt.mangasproject' extClass = '.MangasProjectFactory' - extVersionCode = 13 + extVersionCode = 14 libVersion = '1.2' } diff --git a/src/pt/mangasproject/src/eu/kanade/tachiyomi/extension/pt/mangasproject/MangasProject.kt b/src/pt/mangasproject/src/eu/kanade/tachiyomi/extension/pt/mangasproject/MangasProject.kt index dbd073e08..8306d1ff6 100644 --- a/src/pt/mangasproject/src/eu/kanade/tachiyomi/extension/pt/mangasproject/MangasProject.kt +++ b/src/pt/mangasproject/src/eu/kanade/tachiyomi/extension/pt/mangasproject/MangasProject.kt @@ -17,10 +17,10 @@ import eu.kanade.tachiyomi.util.asJsoup import okhttp3.FormBody import okhttp3.Headers import okhttp3.HttpUrl -import okhttp3.Interceptor import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.Response +import org.jsoup.nodes.Document import org.jsoup.nodes.Element import rx.Observable import java.text.ParseException @@ -42,7 +42,6 @@ abstract class MangasProject( .connectTimeout(1, TimeUnit.MINUTES) .readTimeout(1, TimeUnit.MINUTES) .writeTimeout(1, TimeUnit.MINUTES) - .addInterceptor { pageListIntercept(it) } .build() override fun headersBuilder(): Headers.Builder = Headers.Builder() @@ -265,31 +264,25 @@ abstract class MangasProject( return GET("$baseUrl/leitor/pages/$id.json?key=$token", newHeaders) } - private fun pageListIntercept(chain: Interceptor.Chain): Response { - val request = chain.request() - val result = chain.proceed(request) - - if (!request.url().toString().contains("capitulo-")) - return result - - val document = result.asJsoup() - val token = document.select("script[src*=\"reader.\"]").firstOrNull() - ?.attr("abs:src") - ?.let { HttpUrl.parse(it)!!.queryParameter("token") } - ?: throw Exception(TOKEN_NOT_FOUND) - - return chain.proceed(pageListApiRequest(request.url().toString(), token)) - } - override fun pageListParse(response: Response): List { - val result = response.asJsonObject() - val chapterUrl = response.request().header("Referer")!! + val document = response.asJsoup() + val readerToken = getReaderToken(document) ?: throw Exception(TOKEN_NOT_FOUND) + val chapterUrl = response.request().url().toString() - return result["images"].array + val apiRequest = pageListApiRequest(chapterUrl, readerToken) + val apiResponse = client.newCall(apiRequest).execute().asJsonObject() + + return apiResponse["images"].array .filter { it.string.startsWith("http") } .mapIndexed { i, obj -> Page(i, chapterUrl, obj.string) } } + protected open fun getReaderToken(document: Document): String? { + return document.select("script[src*=\"reader.\"]").firstOrNull() + ?.attr("abs:src") + ?.let { HttpUrl.parse(it)!!.queryParameter("token") } + } + override fun fetchImageUrl(page: Page): Observable = Observable.just(page.imageUrl!!) override fun imageUrlParse(response: Response): String = "" @@ -314,7 +307,7 @@ abstract class MangasProject( companion object { private const val ACCEPT_JSON = "application/json, text/javascript, */*; q=0.01" - private const val USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36" + private const val USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36" private val JSON_PARSER by lazy { JsonParser() } diff --git a/src/pt/mangasproject/src/eu/kanade/tachiyomi/extension/pt/mangasproject/MangasProjectFactory.kt b/src/pt/mangasproject/src/eu/kanade/tachiyomi/extension/pt/mangasproject/MangasProjectFactory.kt index a0d3f126d..6e7edea5e 100644 --- a/src/pt/mangasproject/src/eu/kanade/tachiyomi/extension/pt/mangasproject/MangasProjectFactory.kt +++ b/src/pt/mangasproject/src/eu/kanade/tachiyomi/extension/pt/mangasproject/MangasProjectFactory.kt @@ -8,11 +8,13 @@ import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.MangasPage import okhttp3.Request import okhttp3.Response +import org.jsoup.nodes.Document class MangasProjectFactory : SourceFactory { override fun createSources(): List = listOf( LeitorNet(), - MangaLivre() + MangaLivre(), + Toonei() ) } @@ -82,3 +84,13 @@ class MangaLivre : MangasProject("Mangá Livre", "https://mangalivre.net") { private const val DEFAULT_TYPE = "manga" } } + +class Toonei : MangasProject("Toonei", "https://toonei.com") { + + override fun getReaderToken(document: Document): String? { + return document.select("script:containsData(window.PAGES_KEY)").firstOrNull() + ?.data() + ?.substringAfter("\"") + ?.substringBefore("\";") + } +}