From af807266b828ecd2fed7d7736660719a83d699d7 Mon Sep 17 00:00:00 2001 From: Jason Lam Date: Mon, 8 Jun 2020 17:56:33 -0400 Subject: [PATCH] Madokami cleanup (#3450) * more descriptive error message pointing user to details page * Minor code quality improvements, cleared out unusued latestUpdate functions * bump up ext ver --- src/en/madokami/build.gradle | 2 +- .../extension/en/madokami/Madokami.kt | 37 +++++++++++-------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/en/madokami/build.gradle b/src/en/madokami/build.gradle index 9d0652089..005eb2efd 100644 --- a/src/en/madokami/build.gradle +++ b/src/en/madokami/build.gradle @@ -5,7 +5,7 @@ ext { appName = 'Tachiyomi: Madokami' pkgNameSuffix = 'en.madokami' extClass = '.Madokami' - extVersionCode = 3 + extVersionCode = 4 libVersion = '1.2' } diff --git a/src/en/madokami/src/eu/kanade/tachiyomi/extension/en/madokami/Madokami.kt b/src/en/madokami/src/eu/kanade/tachiyomi/extension/en/madokami/Madokami.kt index 4f79a1217..d6bc11cd0 100644 --- a/src/en/madokami/src/eu/kanade/tachiyomi/extension/en/madokami/Madokami.kt +++ b/src/en/madokami/src/eu/kanade/tachiyomi/extension/en/madokami/Madokami.kt @@ -15,6 +15,7 @@ import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.ParsedHttpSource +import java.io.IOException import java.net.URLDecoder import java.net.URLEncoder import java.text.SimpleDateFormat @@ -22,6 +23,7 @@ import java.util.Calendar import java.util.Locale import okhttp3.Credentials import okhttp3.HttpUrl +import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.Response import org.jsoup.nodes.Document @@ -48,38 +50,41 @@ class Madokami : ConfigurableSource, ParsedHttpSource() { return request.newBuilder().header("Authorization", credential).build() } - override fun latestUpdatesSelector() = "table.mobile-files-table tbody tr td:nth-child(1) a:nth-child(1)" + override val client: OkHttpClient = super.client.newBuilder().addInterceptor { chain -> + val response = chain.proceed(chain.request()) + if (response.code() == 401) throw IOException("You are currently logged out.\nGo to Extensions > Details to input your credentials.") + response + }.build() - override fun latestUpdatesFromElement(element: Element): SManga { + override fun latestUpdatesSelector() = "" + override fun latestUpdatesFromElement(element: Element): SManga = throw Exception("Unsupported!") + override fun latestUpdatesNextPageSelector(): String? = null + override fun latestUpdatesRequest(page: Int) = throw Exception("Unsupported!") + + override fun popularMangaSelector(): String = "table.mobile-files-table tbody tr td:nth-child(1) a:nth-child(1)" + + override fun popularMangaFromElement(element: Element): SManga { val manga = SManga.create() manga.setUrlWithoutDomain(element.attr("href")) manga.title = URLDecoder.decode(element.attr("href").split("/").last(), "UTF-8").trimStart('!') return manga } - override fun latestUpdatesNextPageSelector(): String? = null + override fun popularMangaNextPageSelector(): String? = null - override fun latestUpdatesRequest(page: Int) = authenticate(GET("$baseUrl/recent", headers)) - - override fun popularMangaSelector(): String = latestUpdatesSelector() - - override fun popularMangaFromElement(element: Element): SManga = latestUpdatesFromElement(element) - - override fun popularMangaNextPageSelector(): String? = latestUpdatesNextPageSelector() - - override fun popularMangaRequest(page: Int): Request = latestUpdatesRequest(page) + override fun popularMangaRequest(page: Int): Request = authenticate(GET("$baseUrl/recent", headers)) override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request = authenticate(GET("$baseUrl/search?q=$query", headers)) override fun searchMangaSelector() = "div.container table tbody tr td:nth-child(1) a:nth-child(1)" - override fun searchMangaFromElement(element: Element): SManga = latestUpdatesFromElement(element) + override fun searchMangaFromElement(element: Element): SManga = popularMangaFromElement(element) - override fun searchMangaNextPageSelector(): String? = latestUpdatesNextPageSelector() + override fun searchMangaNextPageSelector(): String? = null override fun mangaDetailsRequest(manga: SManga): Request { val url = HttpUrl.parse(baseUrl + manga.url)!! - if (url.pathSize() > 5 && url.pathSegments()[0] == "Manga" && url.pathSegments()[1] != "Non-English") { + if (url.pathSize() > 5 && url.pathSegments()[0] == "Manga" && url.pathSegments()[1].length == 1) { return authenticate(GET(url.newBuilder().removePathSegment(5).build().url().toExternalForm(), headers)) } if (url.pathSize() > 2 && url.pathSegments()[0] == "Raws") { @@ -151,7 +156,7 @@ class Madokami : ConfigurableSource, ParsedHttpSource() { val element = document.select("div#reader") val path = element.attr("data-path") val files = gson.fromJson(element.attr("data-files")) - val pages = ArrayList() + val pages = mutableListOf() for ((index, file) in files.withIndex()) { val url = HttpUrl.Builder() .scheme("https")