diff --git a/src/en/mangakatana/build.gradle b/src/en/mangakatana/build.gradle index e1fa5411e..fac1fce74 100644 --- a/src/en/mangakatana/build.gradle +++ b/src/en/mangakatana/build.gradle @@ -5,7 +5,7 @@ ext { appName = 'Tachiyomi: MangaKatana' pkgNameSuffix = 'en.mangakatana' extClass = '.MangaKatana' - extVersionCode = 1 + extVersionCode = 2 libVersion = '1.2' } diff --git a/src/en/mangakatana/src/eu/kanade/tachiyomi/extension/en/mangakatana/MangaKatana.kt b/src/en/mangakatana/src/eu/kanade/tachiyomi/extension/en/mangakatana/MangaKatana.kt index 26090f116..f9ed265e4 100644 --- a/src/en/mangakatana/src/eu/kanade/tachiyomi/extension/en/mangakatana/MangaKatana.kt +++ b/src/en/mangakatana/src/eu/kanade/tachiyomi/extension/en/mangakatana/MangaKatana.kt @@ -6,8 +6,12 @@ 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.lang.Exception import java.text.SimpleDateFormat import java.util.Locale +import okhttp3.MediaType +import okhttp3.OkHttpClient +import okhttp3.ResponseBody import org.jsoup.nodes.Document import org.jsoup.nodes.Element @@ -20,7 +24,19 @@ class MangaKatana : ParsedHttpSource() { override val supportsLatest = true - override val client = network.cloudflareClient + override val client: OkHttpClient = network.cloudflareClient.newBuilder().addNetworkInterceptor { chain -> + val originalResponse = chain.proceed(chain.request()) + if (originalResponse.headers("Content-Type").contains("application/octet-stream")) { + val orgBody = originalResponse.body()!!.bytes() + val extension = chain.request().url().toString().substringAfterLast(".") + val newBody = ResponseBody.create(MediaType.parse("image/$extension"), orgBody) + originalResponse.newBuilder() + .body(newBody) + .build() + } else { + originalResponse + } + }.build() override fun latestUpdatesSelector() = "div#book_list > div.item" @@ -29,7 +45,7 @@ class MangaKatana : ParsedHttpSource() { override fun latestUpdatesFromElement(element: Element) = SManga.create().apply { setUrlWithoutDomain(element.select("div.text > h3 > a").attr("href")) title = element.select("div.text > h3 > a").text() - thumbnail_url = element.select("img").attr("abs:data-src") + thumbnail_url = element.select("img").attr("abs:src") } override fun latestUpdatesNextPageSelector() = ".next.page-numbers" @@ -55,7 +71,7 @@ class MangaKatana : ParsedHttpSource() { description = document.select(".summary > p").text() status = parseStatus(document.select(".value.status").text()) genre = document.select(".genres > a").joinToString { it.text() } - thumbnail_url = document.select(".cover > img").attr("abs:data-src") + thumbnail_url = document.select("div.media div.cover img").attr("abs:src") } private fun parseStatus(status: String) = when { @@ -69,7 +85,7 @@ class MangaKatana : ParsedHttpSource() { override fun chapterFromElement(element: Element) = SChapter.create().apply { setUrlWithoutDomain(element.select("a").attr("href")) name = element.select("a").text() - date_upload = dateFormat.parse(element.select(".update_time").text()).time ?: 0 + date_upload = dateFormat.parse(element.select(".update_time").text()).time } companion object { @@ -79,18 +95,14 @@ class MangaKatana : ParsedHttpSource() { } override fun pageListParse(document: Document): List { - val html = document.toString() - - // Thanks to https://github.com/manga-py/manga-py - val regex = Regex("var\\s+\\w+\\s?=\\s?(\\[['\"].+?['\"]).?\\]\\s?;") - val match = regex.find(html)?.destructured?.toList()?.get(0)?.removePrefix("[") - - return match!!.split(",").mapIndexed { i, string -> - Page(i, "", string.reversed().replace("\"", "").replace("'", "")) + // image URLs are in an array with each URL being reversed (e.g. 1.jpg becomes gpj.1) + val script = document.select("script:containsData(var ytaw)").firstOrNull()?.data() + ?: throw Exception("Image array not found") + val regex = Regex("""'(.[^']*ptth)'""") + return regex.findAll(script).toList().mapIndexed { i, mr -> + Page(i, "", mr.groupValues[1].reversed()) } } override fun imageUrlParse(document: Document): String = throw UnsupportedOperationException("Not Used") - - override fun getFilterList() = FilterList() }