From 7235c83998a34e809c02c17fcf03cd497a147185 Mon Sep 17 00:00:00 2001 From: ObserverOfTime Date: Sat, 25 Apr 2020 21:36:49 +0300 Subject: [PATCH] Move Decadence Scans to Madara (#2822) --- src/all/madara/build.gradle | 2 +- .../extension/all/madara/MadaraFactory.kt | 5 +- src/all/mangadventure/build.gradle | 2 +- .../all/mangadventure/MangAdventure.kt | 9 ++-- .../mangadventure/MangAdventureActivity.kt | 1 - .../mangadventure/MangAdventureExtensions.kt | 47 ++++++++++++------- .../all/mangadventure/MangAdventureFactory.kt | 9 +--- 7 files changed, 41 insertions(+), 34 deletions(-) diff --git a/src/all/madara/build.gradle b/src/all/madara/build.gradle index c6f172d8b..90cfe34c1 100644 --- a/src/all/madara/build.gradle +++ b/src/all/madara/build.gradle @@ -5,7 +5,7 @@ ext { appName = 'Tachiyomi: Madara (multiple sources)' pkgNameSuffix = "all.madara" extClass = '.MadaraFactory' - extVersionCode = 75 + extVersionCode = 76 libVersion = '1.2' } diff --git a/src/all/madara/src/eu/kanade/tachiyomi/extension/all/madara/MadaraFactory.kt b/src/all/madara/src/eu/kanade/tachiyomi/extension/all/madara/MadaraFactory.kt index 997588b1e..1c5718dd4 100644 --- a/src/all/madara/src/eu/kanade/tachiyomi/extension/all/madara/MadaraFactory.kt +++ b/src/all/madara/src/eu/kanade/tachiyomi/extension/all/madara/MadaraFactory.kt @@ -105,7 +105,8 @@ class MadaraFactory : SourceFactory { ZinManga(), ZManga(), MangaGecesi(), - MangaWT() + MangaWT(), + DecadenceScans() ) } @@ -573,3 +574,5 @@ class MangaGecesi : Madara("Manga Gecesi", "https://mangagecesi.com", "tr") { } class MangaWT : Madara("MangaWT", "https://mangawt.com", "tr") + +class DecadenceScans : Madara("Decadence Scans", "https://reader.decadencescans.com", "en") diff --git a/src/all/mangadventure/build.gradle b/src/all/mangadventure/build.gradle index 76f8ce443..a299e599a 100644 --- a/src/all/mangadventure/build.gradle +++ b/src/all/mangadventure/build.gradle @@ -5,7 +5,7 @@ ext { appName = 'Tachiyomi: MangAdventure' pkgNameSuffix = 'all.mangadventure' extClass = '.MangAdventureFactory' - extVersionCode = 6 + extVersionCode = 7 libVersion = '1.2' } diff --git a/src/all/mangadventure/src/eu/kanade/tachiyomi/extension/all/mangadventure/MangAdventure.kt b/src/all/mangadventure/src/eu/kanade/tachiyomi/extension/all/mangadventure/MangAdventure.kt index 034b1cfe0..46417953c 100644 --- a/src/all/mangadventure/src/eu/kanade/tachiyomi/extension/all/mangadventure/MangAdventure.kt +++ b/src/all/mangadventure/src/eu/kanade/tachiyomi/extension/all/mangadventure/MangAdventure.kt @@ -91,6 +91,7 @@ abstract class MangAdventure( is CategoryList -> cat.addAll(it.state.mapNotNull { c -> Uri.encode(c.optString()) }) + else -> Unit } } return GET("$uri&categories=${cat.joinToString(",")}", headers) @@ -133,9 +134,7 @@ abstract class MangAdventure( override fun pageListParse(response: Response) = JSONObject(response.asString()).run { val url = getString("url") - // Workaround for a bug in MangAdventure < 0.6.3 val root = getString("pages_root") - .replace("://media/series", "://reader") val arr = getJSONArray("pages_list") (0 until arr.length()).map { Page(it, "$url${it + 1}", "$root${arr.getString(it)}") @@ -237,7 +236,7 @@ abstract class MangAdventure( */ inner class Status : Filter.Select("Status", STATUSES) { /** Returns the [state] as a string. */ - fun string() = values[state].toLowerCase() + fun string() = values[state].toLowerCase(Locale(lang)) } /** @@ -249,8 +248,8 @@ abstract class MangAdventure( inner class Category(name: String) : Filter.TriState(name) { /** Returns the [state] as a string, or null if [isIgnored]. */ fun optString() = when (state) { - STATE_INCLUDE -> name.toLowerCase() - STATE_EXCLUDE -> "-" + name.toLowerCase() + STATE_INCLUDE -> name.toLowerCase(Locale(lang)) + STATE_EXCLUDE -> "-" + name.toLowerCase(Locale(lang)) else -> null } } diff --git a/src/all/mangadventure/src/eu/kanade/tachiyomi/extension/all/mangadventure/MangAdventureActivity.kt b/src/all/mangadventure/src/eu/kanade/tachiyomi/extension/all/mangadventure/MangAdventureActivity.kt index 471365d7c..2d4043a8a 100644 --- a/src/all/mangadventure/src/eu/kanade/tachiyomi/extension/all/mangadventure/MangAdventureActivity.kt +++ b/src/all/mangadventure/src/eu/kanade/tachiyomi/extension/all/mangadventure/MangAdventureActivity.kt @@ -12,7 +12,6 @@ import kotlin.system.exitProcess * intents and redirects them to the main Tachiyomi process. */ class MangAdventureActivity : Activity() { - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) intent?.data?.pathSegments?.takeIf { it.size > 1 }?.let { diff --git a/src/all/mangadventure/src/eu/kanade/tachiyomi/extension/all/mangadventure/MangAdventureExtensions.kt b/src/all/mangadventure/src/eu/kanade/tachiyomi/extension/all/mangadventure/MangAdventureExtensions.kt index 12235e416..a209de128 100644 --- a/src/all/mangadventure/src/eu/kanade/tachiyomi/extension/all/mangadventure/MangAdventureExtensions.kt +++ b/src/all/mangadventure/src/eu/kanade/tachiyomi/extension/all/mangadventure/MangAdventureExtensions.kt @@ -11,31 +11,42 @@ import org.json.JSONObject /** Returns the body of a response as a `String`. */ fun Response.asString(): String = body()!!.string() +/** + * Formats the number according to [fmt]. + * + * @param fmt A [DecimalFormat] string. + * @return A string representation of the number. + */ +fun Number.format(fmt: String): String = DecimalFormat(fmt).format(this) + /** * Joins each value of a given [field] of the array using [sep]. * - * @param field - * When its type is [Int], it is treated as the index of a [JSONArray]. + * @param field The index of a [JSONArray]. * When its type is [String], it is treated as the key of a [JSONObject]. * @param sep The separator used to join the array. - * @param T Must be either [Int] or [String]. - * @return The joined string, or null if the array is empty. - * @throws IllegalArgumentException when [field] is of an invalid type. + * @return The joined string, or `null` if the array is empty. */ -fun JSONArray.joinField(field: T, sep: String = ", "): String? { - require(field is Int || field is String) { - "field must be a String or Int" - } - return length().takeIf { it != 0 }?.let { len -> - (0 until len).joinToString(sep) { - when (field) { - is Int -> getJSONArray(it).getString(field) - is String -> getJSONObject(it).getString(field) - else -> "" // this is here to appease the compiler - } +fun JSONArray.joinField(field: Int, sep: String = ", ") = + length().takeIf { it != 0 }?.run { + (0 until this).joinToString(sep) { + getJSONArray(it).getString(field) + } + } + +/** + * Joins each value of a given [field] of the array using [sep]. + * + * @param field The key of a [JSONObject]. + * @param sep The separator used to join the array. + * @return The joined string, or `null` if the array is empty. + */ +fun JSONArray.joinField(field: String, sep: String = ", ") = + length().takeIf { it != 0 }?.run { + (0 until this).joinToString(sep) { + getJSONObject(it).getString(field) } } -} /** The slug of a manga. */ val SManga.slug: String @@ -74,7 +85,7 @@ fun SChapter.fromJSON(obj: JSONObject) = apply { scanlator = obj.getJSONArray("groups")?.joinField("name", " & ") name = obj.optString("full_title", buildString { obj.optInt("volume").let { if (it != 0) append("Vol. $it, ") } - append("Ch. ${DecimalFormat("#.#").format(chapter_number)}: ") + append("Ch. ${chapter_number.format("#.#")}: ") append(obj.getString("title")) }) if (obj.getBoolean("final")) name += " [END]" diff --git a/src/all/mangadventure/src/eu/kanade/tachiyomi/extension/all/mangadventure/MangAdventureFactory.kt b/src/all/mangadventure/src/eu/kanade/tachiyomi/extension/all/mangadventure/MangAdventureFactory.kt index b104fe911..d6c66a404 100644 --- a/src/all/mangadventure/src/eu/kanade/tachiyomi/extension/all/mangadventure/MangAdventureFactory.kt +++ b/src/all/mangadventure/src/eu/kanade/tachiyomi/extension/all/mangadventure/MangAdventureFactory.kt @@ -2,10 +2,10 @@ package eu.kanade.tachiyomi.extension.all.mangadventure import eu.kanade.tachiyomi.source.SourceFactory +/** [MangAdventure] source factory. */ class MangAdventureFactory : SourceFactory { override fun createSources() = listOf( - ArcRelight(), - DecadenceScans() + ArcRelight() ) /** Arc-Relight source. */ @@ -29,9 +29,4 @@ class MangAdventureFactory : SourceFactory { "Tragedy" ) ) - - /** Decadence Scans source. */ - class DecadenceScans : MangAdventure( - "Decadence Scans", "https://reader.decadencescans.com" - ) }