Cubari release_date fix + volume null fix (#8163)

* Fix for Cubari API response not containing chapter release_date

Cubari API responses don't contain release_date information when the Cubari source is Imgur.
The minor change made with this commit makes the existence of the release_date json property for the parsing process optional.

* Fix for Cubari volume "null" and cleaned up chapter name generation

If the volume is set to null in the json, it's now recognized as not specified.
Also cleaned up the chapter name concatenation.
This commit is contained in:
E3FxGaming 2021-07-18 12:29:43 +02:00 committed by GitHub
parent 5a8287c1fa
commit b87a5935b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 9 deletions

View File

@ -6,7 +6,7 @@ ext {
extName = 'Cubari' extName = 'Cubari'
pkgNameSuffix = "all.cubari" pkgNameSuffix = "all.cubari"
extClass = '.CubariFactory' extClass = '.CubariFactory'
extVersionCode = 8 extVersionCode = 9
libVersion = '1.2' libVersion = '1.2'
} }

View File

@ -255,6 +255,8 @@ open class Cubari(override val lang: String) : HttpSource() {
// ------------- Helpers and whatnot --------------- // ------------- Helpers and whatnot ---------------
private val volumeNotSpecifiedTerms = setOf("Uncategorized", "null")
private fun parseChapterList(payload: String, manga: SManga): List<SChapter> { private fun parseChapterList(payload: String, manga: SManga): List<SChapter> {
val jsonObj = json.parseToJsonElement(payload).jsonObject val jsonObj = json.parseToJsonElement(payload).jsonObject
val groups = jsonObj["groups"]!!.jsonObject val groups = jsonObj["groups"]!!.jsonObject
@ -268,18 +270,21 @@ open class Cubari(override val lang: String) : HttpSource() {
val chapterNum = chapterEntry.key val chapterNum = chapterEntry.key
val chapterObj = chapterEntry.value.jsonObject val chapterObj = chapterEntry.value.jsonObject
val chapterGroups = chapterObj["groups"]!!.jsonObject val chapterGroups = chapterObj["groups"]!!.jsonObject
val volume = chapterObj["volume"]!!.jsonPrimitive.content val volume = chapterObj["volume"]!!.jsonPrimitive.content.let {
if (volumeNotSpecifiedTerms.contains(it)) null else it
}
val title = chapterObj["title"]!!.jsonPrimitive.content
chapterGroups.entries.map { groupEntry -> chapterGroups.entries.map { groupEntry ->
val groupNum = groupEntry.key val groupNum = groupEntry.key
val releaseDate = chapterObj["release_date"]?.jsonObject?.get(groupNum)
SChapter.create().apply { SChapter.create().apply {
scanlator = groups[groupNum]!!.jsonPrimitive.content scanlator = groups[groupNum]!!.jsonPrimitive.content
chapter_number = chapterNum.toFloatOrNull() ?: -1f chapter_number = chapterNum.toFloatOrNull() ?: -1f
if (chapterObj["release_date"]!!.jsonObject[groupNum] != null) { if (releaseDate != null) {
val temp = chapterObj["release_date"]!!.jsonObject[groupNum]!!.jsonPrimitive.double date_upload = releaseDate.jsonPrimitive.double.toLong() * 1000
date_upload = temp.toLong() * 1000
} else { } else {
val currentTimeMillis = System.currentTimeMillis() val currentTimeMillis = System.currentTimeMillis()
@ -290,13 +295,12 @@ open class Cubari(override val lang: String) : HttpSource() {
date_upload = seriesPrefs.getLong(chapterNum, currentTimeMillis) date_upload = seriesPrefs.getLong(chapterNum, currentTimeMillis)
} }
name = if (volume.isNotEmpty() && volume != "Uncategorized") { name = if (volume != null) {
// Output "Vol. 1 Ch. 1 - Chapter Name" // Output "Vol. 1 Ch. 1 - Chapter Name"
"Vol. " + chapterObj["volume"]!!.jsonPrimitive.content + " Ch. " + "Vol. $volume Ch. $chapterNum - $title"
chapterNum + " - " + chapterObj["title"]!!.jsonPrimitive.content
} else { } else {
// Output "Ch. 1 - Chapter Name" // Output "Ch. 1 - Chapter Name"
"Ch. " + chapterNum + " - " + chapterObj["title"]!!.jsonPrimitive.content "Ch. $chapterNum - $title"
} }
url = if (chapterGroups[groupNum] is JsonArray) { url = if (chapterGroups[groupNum] is JsonArray) {