Move Decadence Scans to Madara (#2822)

This commit is contained in:
ObserverOfTime 2020-04-25 21:36:49 +03:00 committed by GitHub
parent 7b8e61b72f
commit 7235c83998
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 41 additions and 34 deletions

View File

@ -5,7 +5,7 @@ ext {
appName = 'Tachiyomi: Madara (multiple sources)' appName = 'Tachiyomi: Madara (multiple sources)'
pkgNameSuffix = "all.madara" pkgNameSuffix = "all.madara"
extClass = '.MadaraFactory' extClass = '.MadaraFactory'
extVersionCode = 75 extVersionCode = 76
libVersion = '1.2' libVersion = '1.2'
} }

View File

@ -105,7 +105,8 @@ class MadaraFactory : SourceFactory {
ZinManga(), ZinManga(),
ZManga(), ZManga(),
MangaGecesi(), 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 MangaWT : Madara("MangaWT", "https://mangawt.com", "tr")
class DecadenceScans : Madara("Decadence Scans", "https://reader.decadencescans.com", "en")

View File

@ -5,7 +5,7 @@ ext {
appName = 'Tachiyomi: MangAdventure' appName = 'Tachiyomi: MangAdventure'
pkgNameSuffix = 'all.mangadventure' pkgNameSuffix = 'all.mangadventure'
extClass = '.MangAdventureFactory' extClass = '.MangAdventureFactory'
extVersionCode = 6 extVersionCode = 7
libVersion = '1.2' libVersion = '1.2'
} }

View File

@ -91,6 +91,7 @@ abstract class MangAdventure(
is CategoryList -> cat.addAll(it.state.mapNotNull { c -> is CategoryList -> cat.addAll(it.state.mapNotNull { c ->
Uri.encode(c.optString()) Uri.encode(c.optString())
}) })
else -> Unit
} }
} }
return GET("$uri&categories=${cat.joinToString(",")}", headers) return GET("$uri&categories=${cat.joinToString(",")}", headers)
@ -133,9 +134,7 @@ abstract class MangAdventure(
override fun pageListParse(response: Response) = override fun pageListParse(response: Response) =
JSONObject(response.asString()).run { JSONObject(response.asString()).run {
val url = getString("url") val url = getString("url")
// Workaround for a bug in MangAdventure < 0.6.3
val root = getString("pages_root") val root = getString("pages_root")
.replace("://media/series", "://reader")
val arr = getJSONArray("pages_list") val arr = getJSONArray("pages_list")
(0 until arr.length()).map { (0 until arr.length()).map {
Page(it, "$url${it + 1}", "$root${arr.getString(it)}") Page(it, "$url${it + 1}", "$root${arr.getString(it)}")
@ -237,7 +236,7 @@ abstract class MangAdventure(
*/ */
inner class Status : Filter.Select<String>("Status", STATUSES) { inner class Status : Filter.Select<String>("Status", STATUSES) {
/** Returns the [state] as a string. */ /** 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) { inner class Category(name: String) : Filter.TriState(name) {
/** Returns the [state] as a string, or null if [isIgnored]. */ /** Returns the [state] as a string, or null if [isIgnored]. */
fun optString() = when (state) { fun optString() = when (state) {
STATE_INCLUDE -> name.toLowerCase() STATE_INCLUDE -> name.toLowerCase(Locale(lang))
STATE_EXCLUDE -> "-" + name.toLowerCase() STATE_EXCLUDE -> "-" + name.toLowerCase(Locale(lang))
else -> null else -> null
} }
} }

View File

@ -12,7 +12,6 @@ import kotlin.system.exitProcess
* intents and redirects them to the main Tachiyomi process. * intents and redirects them to the main Tachiyomi process.
*/ */
class MangAdventureActivity : Activity() { class MangAdventureActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
intent?.data?.pathSegments?.takeIf { it.size > 1 }?.let { intent?.data?.pathSegments?.takeIf { it.size > 1 }?.let {

View File

@ -11,31 +11,42 @@ import org.json.JSONObject
/** Returns the body of a response as a `String`. */ /** Returns the body of a response as a `String`. */
fun Response.asString(): String = body()!!.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]. * Joins each value of a given [field] of the array using [sep].
* *
* @param field * @param field The index of a [JSONArray].
* When its type is [Int], it is treated as the index of a [JSONArray].
* When its type is [String], it is treated as the key of a [JSONObject]. * When its type is [String], it is treated as the key of a [JSONObject].
* @param sep The separator used to join the array. * @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.
* @return The joined string, or null if the array is empty.
* @throws IllegalArgumentException when [field] is of an invalid type.
*/ */
fun <T> JSONArray.joinField(field: T, sep: String = ", "): String? { fun JSONArray.joinField(field: Int, sep: String = ", ") =
require(field is Int || field is String) { length().takeIf { it != 0 }?.run {
"field must be a String or Int" (0 until this).joinToString(sep) {
} getJSONArray(it).getString(field)
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
} }
} }
/**
* 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. */ /** The slug of a manga. */
val SManga.slug: String val SManga.slug: String
@ -74,7 +85,7 @@ fun SChapter.fromJSON(obj: JSONObject) = apply {
scanlator = obj.getJSONArray("groups")?.joinField("name", " & ") scanlator = obj.getJSONArray("groups")?.joinField("name", " & ")
name = obj.optString("full_title", buildString { name = obj.optString("full_title", buildString {
obj.optInt("volume").let { if (it != 0) append("Vol. $it, ") } 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")) append(obj.getString("title"))
}) })
if (obj.getBoolean("final")) name += " [END]" if (obj.getBoolean("final")) name += " [END]"

View File

@ -2,10 +2,10 @@ package eu.kanade.tachiyomi.extension.all.mangadventure
import eu.kanade.tachiyomi.source.SourceFactory import eu.kanade.tachiyomi.source.SourceFactory
/** [MangAdventure] source factory. */
class MangAdventureFactory : SourceFactory { class MangAdventureFactory : SourceFactory {
override fun createSources() = listOf( override fun createSources() = listOf(
ArcRelight(), ArcRelight()
DecadenceScans()
) )
/** Arc-Relight source. */ /** Arc-Relight source. */
@ -29,9 +29,4 @@ class MangAdventureFactory : SourceFactory {
"Tragedy" "Tragedy"
) )
) )
/** Decadence Scans source. */
class DecadenceScans : MangAdventure(
"Decadence Scans", "https://reader.decadencescans.com"
)
} }