mangadex fix completed status (#360)
when a manga has a last chapter indicating its finished publishing, verify the chapter exists on mangadex and if then mark completed
This commit is contained in:
parent
26ea75c18a
commit
32b76e6d8c
|
@ -5,8 +5,8 @@ ext {
|
||||||
appName = 'Tachiyomi: MangaDex'
|
appName = 'Tachiyomi: MangaDex'
|
||||||
pkgNameSuffix = "all.mangadex"
|
pkgNameSuffix = "all.mangadex"
|
||||||
extClass = '.MangadexFactory'
|
extClass = '.MangadexFactory'
|
||||||
extVersionCode = 26
|
extVersionCode = 27
|
||||||
extVersionSuffix = 26
|
extVersionSuffix = 27
|
||||||
libVersion = '1.2'
|
libVersion = '1.2'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import android.content.SharedPreferences
|
||||||
import android.support.v7.preference.ListPreference
|
import android.support.v7.preference.ListPreference
|
||||||
import android.support.v7.preference.PreferenceScreen
|
import android.support.v7.preference.PreferenceScreen
|
||||||
import com.github.salomonbrys.kotson.*
|
import com.github.salomonbrys.kotson.*
|
||||||
|
import com.google.gson.JsonElement
|
||||||
import com.google.gson.JsonObject
|
import com.google.gson.JsonObject
|
||||||
import com.google.gson.JsonParser
|
import com.google.gson.JsonParser
|
||||||
import eu.kanade.tachiyomi.network.GET
|
import eu.kanade.tachiyomi.network.GET
|
||||||
|
@ -221,6 +222,7 @@ open class Mangadex(override val lang: String, private val internalLang: String,
|
||||||
|
|
||||||
override fun mangaDetailsParse(response: Response): SManga {
|
override fun mangaDetailsParse(response: Response): SManga {
|
||||||
val manga = SManga.create()
|
val manga = SManga.create()
|
||||||
|
|
||||||
var jsonData = response.body()!!.string()
|
var jsonData = response.body()!!.string()
|
||||||
val json = JsonParser().parse(jsonData).asJsonObject
|
val json = JsonParser().parse(jsonData).asJsonObject
|
||||||
val mangaJson = json.getAsJsonObject("manga")
|
val mangaJson = json.getAsJsonObject("manga")
|
||||||
|
@ -230,7 +232,9 @@ open class Mangadex(override val lang: String, private val internalLang: String,
|
||||||
manga.author = mangaJson.get("author").string
|
manga.author = mangaJson.get("author").string
|
||||||
manga.artist = mangaJson.get("artist").string
|
manga.artist = mangaJson.get("artist").string
|
||||||
val finalChapterNumber = getFinalChapter(mangaJson)
|
val finalChapterNumber = getFinalChapter(mangaJson)
|
||||||
if (finalChapterNumber != 0.00) {
|
val chapterJson = json.getAsJsonObject("chapter")
|
||||||
|
|
||||||
|
if (isMangaCompleted(finalChapterNumber, chapterJson)) {
|
||||||
manga.status = SManga.COMPLETED
|
manga.status = SManga.COMPLETED
|
||||||
} else {
|
} else {
|
||||||
manga.status = parseStatus(mangaJson.get("status").int)
|
manga.status = parseStatus(mangaJson.get("status").int)
|
||||||
|
@ -244,6 +248,7 @@ open class Mangadex(override val lang: String, private val internalLang: String,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
manga.genre = genres.joinToString(", ")
|
manga.genre = genres.joinToString(", ")
|
||||||
|
|
||||||
return manga
|
return manga
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,6 +279,23 @@ open class Mangadex(override val lang: String, private val internalLang: String,
|
||||||
return finalChapterNumber
|
return finalChapterNumber
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun isMangaCompleted(finalChapterNumber: Double, chapterJson: JsonObject): Boolean {
|
||||||
|
|
||||||
|
val count = chapterJson.toMap().values.filter { it ->
|
||||||
|
val chapterElement = it.asJsonObject
|
||||||
|
return chapterElement.get("lang_code").string == internalLang && doesFinalChapterExist(finalChapterNumber, it)
|
||||||
|
}?.count()
|
||||||
|
|
||||||
|
return when (count) {
|
||||||
|
0 -> false
|
||||||
|
else -> true
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun doesFinalChapterExist(finalChapterNumber: Double, chapterJson: JsonElement) = finalChapterNumber != 0.00 && chapterJson.get("chapter").string.isNotEmpty() && chapterJson.get("chapter").double == finalChapterNumber
|
||||||
|
|
||||||
|
|
||||||
override fun chapterListParse(response: Response): List<SChapter> {
|
override fun chapterListParse(response: Response): List<SChapter> {
|
||||||
val now = Date().time
|
val now = Date().time
|
||||||
var jsonData = response.body()!!.string()
|
var jsonData = response.body()!!.string()
|
||||||
|
@ -311,7 +333,7 @@ open class Mangadex(override val lang: String, private val internalLang: String,
|
||||||
chapterName.add("-")
|
chapterName.add("-")
|
||||||
chapterName.add(chapterJson.get("title").string)
|
chapterName.add(chapterJson.get("title").string)
|
||||||
}
|
}
|
||||||
if (finalChapterNumber != 0.00 && chapterJson.get("chapter").string.isNotEmpty() && chapterJson.get("chapter").double == finalChapterNumber) {
|
if (doesFinalChapterExist(finalChapterNumber, chapterJson)) {
|
||||||
chapterName.add(" [END]")
|
chapterName.add(" [END]")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue