From 6d8c4fb8b1124b2e87595f42c4ea292559818419 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 20 Mar 2021 10:22:11 -0400 Subject: [PATCH] Fix Bangumi search null image errors --- .../kanade/tachiyomi/data/track/bangumi/BangumiApi.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiApi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiApi.kt index b9bb187af..ecf45fdfc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiApi.kt @@ -13,6 +13,7 @@ import eu.kanade.tachiyomi.util.lang.withIOContext import kotlinx.serialization.decodeFromString import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.contentOrNull import kotlinx.serialization.json.int import kotlinx.serialization.json.jsonArray import kotlinx.serialization.json.jsonObject @@ -91,10 +92,17 @@ class BangumiApi(private val client: OkHttpClient, interceptor: BangumiIntercept } private fun jsonToSearch(obj: JsonObject): TrackSearch { + val coverUrl = if (obj["images"] is JsonObject) { + obj["images"]?.jsonObject?.get("common")?.jsonPrimitive?.contentOrNull ?: "" + } else { + // Sometimes JsonNull + "" + } + return TrackSearch.create(TrackManager.BANGUMI).apply { media_id = obj["id"]!!.jsonPrimitive.int title = obj["name_cn"]!!.jsonPrimitive.content - cover_url = obj["images"]!!.jsonObject["common"]!!.jsonPrimitive.content + cover_url = coverUrl summary = obj["name"]!!.jsonPrimitive.content tracking_url = obj["url"]!!.jsonPrimitive.content }