[mangarock] Add null check for authors, convert hardcoded JSON string… (#977)
* [mangarock] Add null check for authors, convert hardcoded JSON strings to maps * dammit
This commit is contained in:
parent
48ac7ffcf9
commit
9560a68fdc
@ -5,8 +5,12 @@ ext {
|
||||
appName = 'Tachiyomi: Manga Rock'
|
||||
pkgNameSuffix = 'en.mangarock'
|
||||
extClass = '.MangaRock'
|
||||
extVersionCode = 5
|
||||
extVersionCode = 6
|
||||
libVersion = '1.0'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly 'com.google.code.gson:gson:2.8.2'
|
||||
}
|
||||
|
||||
apply from: "$rootDir/common.gradle"
|
||||
|
@ -1,5 +1,6 @@
|
||||
package eu.kanade.tachiyomi.extension.en.mangarock
|
||||
|
||||
import com.google.gson.GsonBuilder
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.network.POST
|
||||
import eu.kanade.tachiyomi.source.model.*
|
||||
@ -58,6 +59,7 @@ class MangaRock : HttpSource() {
|
||||
|
||||
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
|
||||
val jsonType = MediaType.parse("application/jsonType; charset=utf-8")
|
||||
val gson = GsonBuilder().create()
|
||||
|
||||
// Filter
|
||||
if (query.isBlank()) {
|
||||
@ -91,12 +93,12 @@ class MangaRock : HttpSource() {
|
||||
}
|
||||
}
|
||||
|
||||
val body = RequestBody.create(jsonType, "{\"status\":\"$status\",\"genres\":{$genres},\"rank\":\"$rank\",\"order\":\"$orderBy\"}")
|
||||
val body = RequestBody.create(jsonType, gson.toJson(mapOf("status" to status, "genres" to genres, "rank" to rank, "order" to orderBy)))
|
||||
return POST("$baseUrl/mrs_filter", headers, body)
|
||||
}
|
||||
|
||||
// Regular search
|
||||
val body = RequestBody.create(jsonType, "{\"type\":\"series\", \"keywords\":\"$query\"}")
|
||||
val body = RequestBody.create(jsonType, gson.toJson(mapOf("type" to "series", "keywords" to query)))
|
||||
return POST("$baseUrl/mrs_search", headers, body)
|
||||
}
|
||||
|
||||
@ -143,7 +145,7 @@ class MangaRock : HttpSource() {
|
||||
}
|
||||
|
||||
private fun sortByRank(arr: List<JSONObject>): List<JSONObject> {
|
||||
return arr.sortedBy({ it.getInt("rank") })
|
||||
return arr.sortedBy { it.getInt("rank") }
|
||||
}
|
||||
|
||||
override fun mangaDetailsParse(response: Response) = SManga.create().apply {
|
||||
@ -153,18 +155,23 @@ class MangaRock : HttpSource() {
|
||||
title = obj.getString("name")
|
||||
description = obj.getString("description")
|
||||
|
||||
val people = obj.getJSONArray("authors")
|
||||
val authors = ArrayList<String>()
|
||||
val artists = ArrayList<String>()
|
||||
for (i in 0 until people.length()) {
|
||||
val person = people.getJSONObject(i)
|
||||
when (person.getString("role")) {
|
||||
"art" -> artists.add(person.getString("name"))
|
||||
"story" -> authors.add(person.getString("name"))
|
||||
if (obj.isNull("authors")) {
|
||||
artist = ""
|
||||
author = ""
|
||||
} else {
|
||||
val people = obj.getJSONArray("authors")
|
||||
val authors = ArrayList<String>()
|
||||
val artists = ArrayList<String>()
|
||||
for (i in 0 until people.length()) {
|
||||
val person = people.getJSONObject(i)
|
||||
when (person.getString("role")) {
|
||||
"art" -> artists.add(person.getString("name"))
|
||||
"story" -> authors.add(person.getString("name"))
|
||||
}
|
||||
}
|
||||
artist = artists.sorted().joinToString(", ")
|
||||
author = authors.sorted().joinToString(", ")
|
||||
}
|
||||
artist = artists.sorted().joinToString(", ")
|
||||
author = authors.sorted().joinToString(", ")
|
||||
|
||||
val categories = obj.getJSONArray("rich_categories")
|
||||
val genres = ArrayList<String>(categories.length())
|
||||
|
Loading…
x
Reference in New Issue
Block a user