Ganma: cleanup for chapter list and preferences (#12371)

This commit is contained in:
stevenyomi 2022-06-30 03:37:19 +08:00 committed by GitHub
parent 7bc4e3f647
commit fbb06aadb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 33 deletions

View File

@ -6,7 +6,7 @@ ext {
extName = 'GANMA!'
pkgNameSuffix = 'ja.ganma'
extClass = '.GanmaFactory'
extVersionCode = 1
extVersionCode = 2
}
apply from: "$rootDir/common.gradle"

View File

@ -75,7 +75,7 @@ open class Ganma : HttpSource(), ConfigurableSource {
override fun fetchMangaDetails(manga: SManga): Observable<SManga> =
client.newCall(realMangaDetailsRequest(manga)).asObservableSuccess()
.map { mangaDetailsParse(it).apply { initialized = true } }
.map { mangaDetailsParse(it) }
override fun mangaDetailsParse(response: Response): SManga =
response.parseAs<Magazine>().toSMangaDetails()
@ -117,10 +117,6 @@ open class Ganma : HttpSource(), ConfigurableSource {
key = METADATA_PREF
title = "Metadata (Debug)"
setDefaultValue("")
setOnPreferenceChangeListener { _, newValue ->
preferences.edit().putString(METADATA_PREF, newValue as String).apply()
true
}
}.let { screen.addPreference(it) }
}
}

View File

@ -8,8 +8,6 @@ import eu.kanade.tachiyomi.network.POST
import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.model.SManga
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.jsonPrimitive
import okhttp3.Cookie
import okhttp3.CookieJar
import okhttp3.FormBody
@ -57,9 +55,9 @@ class GanmaApp(private val metadata: Metadata) : Ganma() {
var field2 = preferences.getString(TOKEN_FIELD2_PREF, "")!!
if (field1.isEmpty() || field2.isEmpty()) {
val response = client.newCall(POST(metadata.baseUrl + metadata.tokenUrl, appHeaders)).execute()
val token: JsonObject = response.parseAs()
field1 = token[metadata.tokenField1]!!.jsonPrimitive.content
field2 = token[metadata.tokenField2]!!.jsonPrimitive.content
val token: Map<String, String> = response.parseAs()
field1 = token[metadata.tokenField1]!!
field2 = token[metadata.tokenField2]!!
}
val requestBody = FormBody.Builder().apply {
add(metadata.tokenField1, field1)
@ -89,7 +87,7 @@ class GanmaApp(private val metadata: Metadata) : Ganma() {
super.setupPreferenceScreen(screen)
SwitchPreferenceCompat(screen.context).apply {
title = "Clear session"
setOnPreferenceClickListener {
setOnPreferenceChangeListener { _, _ ->
clearSession(clearToken = false)
Toast.makeText(screen.context, "Session cleared", Toast.LENGTH_SHORT).show()
false
@ -97,7 +95,7 @@ class GanmaApp(private val metadata: Metadata) : Ganma() {
}.let { screen.addPreference(it) }
SwitchPreferenceCompat(screen.context).apply {
title = "Clear token"
setOnPreferenceClickListener {
setOnPreferenceChangeListener { _, _ ->
clearSession(clearToken = true)
Toast.makeText(screen.context, "Token cleared", Toast.LENGTH_SHORT).show()
false

View File

@ -4,13 +4,15 @@ import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.model.SManga
import kotlinx.serialization.Serializable
import java.text.DateFormat.getDateTimeInstance
import java.util.Date
@Serializable
data class Result<T>(val root: T)
class Result<T>(val root: T)
// Manga
@Serializable
data class Magazine(
class Magazine(
val id: String,
val alias: String? = null,
val title: String,
@ -38,6 +40,7 @@ data class Magazine(
!flagsText.isNullOrEmpty() -> SManga.ONGOING
else -> SManga.UNKNOWN
}
initialized = true
}
private fun generateDescription(flagsText: String?): String {
@ -48,12 +51,20 @@ data class Magazine(
return result.joinToString("\n\n")
}
fun getSChapterList() = items.map {
SChapter.create().apply {
url = "${alias!!}#$id/${it.id ?: it.storyId}"
val prefix = if (it.kind == "free") "" else "🔒 "
name = if (it.subtitle != null) "$prefix${it.title} ${it.subtitle}" else "$prefix${it.title}"
date_upload = it.releaseStart ?: -1
fun getSChapterList(): List<SChapter> {
val now = System.currentTimeMillis()
return items.map {
SChapter.create().apply {
url = "${alias!!}#$id/${it.id ?: it.storyId}"
name = buildString {
if (it.kind != "free") append("🔒 ")
append(it.title)
if (it.subtitle != null) append(' ').append(it.subtitle)
}
val time = it.releaseStart ?: -1
date_upload = time
if (time > now) scanlator = getDateTimeInstance().format(Date(time)) + '~'
}
}
}
}
@ -68,7 +79,7 @@ fun String.chapterDir(): Pair<String, String> =
// Chapter
@Serializable
data class Story(
class Story(
val id: String? = null,
val storyId: String? = null,
val title: String,
@ -89,19 +100,19 @@ data class Story(
}
@Serializable
data class File(val url: String)
class File(val url: String)
@Serializable
data class Author(val penName: String? = null)
class Author(val penName: String? = null)
@Serializable
data class Top(val boxes: List<Box>)
class Top(val boxes: List<Box>)
@Serializable
data class Box(val panels: List<Magazine>)
class Box(val panels: List<Magazine>)
@Serializable
data class Flags(
class Flags(
val isMonday: Boolean = false,
val isTuesday: Boolean = false,
val isWednesday: Boolean = false,
@ -142,10 +153,10 @@ data class Flags(
}
@Serializable
data class Announcement(val text: String)
class Announcement(val text: String)
@Serializable
data class Directory(
class Directory(
val baseUrl: String,
val token: String,
val files: List<String>,
@ -157,7 +168,7 @@ data class Directory(
}
@Serializable
data class AppStory(val pages: List<AppPage>) {
class AppStory(val pages: List<AppPage>) {
fun toPageList(): List<Page> {
val result = ArrayList<Page>(pages.size)
pages.forEach {
@ -171,7 +182,7 @@ data class AppStory(val pages: List<AppPage>) {
}
@Serializable
data class AppPage(
class AppPage(
val imageURL: File? = null,
val afterwordImageURL: File? = null,
)
@ -179,7 +190,7 @@ data class AppPage(
// Please keep the data private to support the site,
// otherwise they might change their APIs.
@Serializable
data class Metadata(
class Metadata(
val userAgent: String,
val baseUrl: String,
val tokenUrl: String,
@ -192,4 +203,4 @@ data class Metadata(
)
@Serializable
data class Session(val expire: Long)
class Session(val expire: Long)