From d3e6595dc38cb59c8fb6177cf8dd679641eade72 Mon Sep 17 00:00:00 2001 From: AwkwardPeak7 <48650614+AwkwardPeak7@users.noreply.github.com> Date: Mon, 31 Jul 2023 19:01:32 +0500 Subject: [PATCH] Temple Scan: fix chapter list and add latest (#17323) * Temple Scan: fix chapter list and add latest * bump * small change --- src/en/templescan/build.gradle | 2 +- .../extension/en/templescan/TempleScan.kt | 46 +++++++++++++------ 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/en/templescan/build.gradle b/src/en/templescan/build.gradle index 84d9cbb84..303636911 100644 --- a/src/en/templescan/build.gradle +++ b/src/en/templescan/build.gradle @@ -6,7 +6,7 @@ ext { extName = 'Temple Scan' pkgNameSuffix = 'en.templescan' extClass = '.TempleScan' - extVersionCode = 32 + extVersionCode = 33 } apply from: "$rootDir/common.gradle" diff --git a/src/en/templescan/src/eu/kanade/tachiyomi/extension/en/templescan/TempleScan.kt b/src/en/templescan/src/eu/kanade/tachiyomi/extension/en/templescan/TempleScan.kt index 60d08af61..5e82ea62c 100644 --- a/src/en/templescan/src/eu/kanade/tachiyomi/extension/en/templescan/TempleScan.kt +++ b/src/en/templescan/src/eu/kanade/tachiyomi/extension/en/templescan/TempleScan.kt @@ -14,6 +14,7 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.decodeFromString import kotlinx.serialization.json.Json import okhttp3.Response +import org.jsoup.nodes.Document import rx.Observable import uy.kohesive.injekt.injectLazy import java.util.Calendar @@ -27,7 +28,7 @@ class TempleScan : HttpSource() { override val baseUrl = "https://templescan.net" - override val supportsLatest = false + override val supportsLatest = true override val versionId = 2 @@ -37,7 +38,7 @@ class TempleScan : HttpSource() { private val json: Json by injectLazy() - private val seriesCache: List by lazy { + private val homeDocument: Document by lazy { val response = client.newCall(GET(baseUrl, headers)).execute() if (response.isSuccessful.not()) { @@ -45,12 +46,15 @@ class TempleScan : HttpSource() { throw Exception("Http Error ${response.code}") } - response.asJsoup() - .selectFirst("script:containsData(proyectos)") + response.use { it.asJsoup() } + } + + private val seriesCache: List by lazy { + homeDocument.selectFirst("script:containsData(proyectos)") ?.data() ?.let { proyectosRegex.find(it)?.groupValues?.get(1) } ?.let(json::decodeFromString) - ?: throw Exception(SeriesCacheFailureException) + ?: throw Exception("Unable to extract series information") } private lateinit var filteredSeriesCache: List @@ -82,6 +86,23 @@ class TempleScan : HttpSource() { return Observable.just(mangasPage) } + override fun fetchLatestUpdates(page: Int): Observable { + val slugs = homeDocument.select("section:contains(new release) figure") + .mapNotNull { element -> + element.selectFirst("a")?.attr("abs:href") + ?.substringAfter("/comic/") + ?.substringBefore("/") + } + + val entries = slugs.mapNotNull { slug -> + seriesCache.firstOrNull { it.slug == slug }?.toSManga() + } + + val mangasPage = MangasPage(entries, false) + + return Observable.just(mangasPage) + } + override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable { if (query.startsWith(SEARCH_PREFIX)) { val url = "/comic/${query.substringAfter(SEARCH_PREFIX)}" @@ -117,11 +138,11 @@ class TempleScan : HttpSource() { override fun chapterListParse(response: Response): List { val elements = response.asJsoup() - .select("div.contenedor-capitulo-miniatura a") + .select("div.contenedor-capitulo-miniatura") return elements.map { element -> SChapter.create().apply { - setUrlWithoutDomain(element.attr("href")) + setUrlWithoutDomain(element.select("a").attr("href")) name = element.select("div[id=name]").text() date_upload = element.select("time").text().let { runCatching { it.parseRelativeDate() }.getOrDefault(0L) @@ -149,11 +170,7 @@ class TempleScan : HttpSource() { var parsedDate = 0L - val relativeDate = try { - this.split(" ")[0].trim().toInt() - } catch (e: NumberFormatException) { - return 0L - } + val relativeDate = this.split(" ")[0].trim().toInt() when { "second" in this -> { @@ -182,8 +199,9 @@ class TempleScan : HttpSource() { } companion object { - private val proyectosRegex = Regex("""proyectos\s*=\s*([^\;]+)""") - private const val SeriesCacheFailureException = "Unable to extract series information" + private val proyectosRegex by lazy { + Regex("""proyectos\s*=\s*([^;]+)""") + } private const val limit = 20 const val SEARCH_PREFIX = "slug:"