ソースを参照

Fix Some Bangumi Track Bug (#4726)

mutsumi 4 年 前
コミット
cc6ae9d1a8

+ 4 - 3
app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Bangumi.kt

@@ -45,8 +45,10 @@ class Bangumi(private val context: Context, id: Int) : TrackService(id) {
         return if (remoteTrack != null && statusTrack != null) {
             track.copyPersonalFrom(remoteTrack)
             track.library_id = remoteTrack.library_id
-            track.status = remoteTrack.status
-            track.last_chapter_read = remoteTrack.last_chapter_read
+            track.status = statusTrack.status
+            track.score = statusTrack.score
+            track.last_chapter_read = statusTrack.last_chapter_read
+            track.total_chapters = remoteTrack.total_chapters
             refresh(track)
         } else {
             // Set default fields if it's not found in the list
@@ -66,7 +68,6 @@ class Bangumi(private val context: Context, id: Int) : TrackService(id) {
         track.copyPersonalFrom(remoteStatusTrack!!)
         api.findLibManga(track)?.let { remoteTrack ->
             track.total_chapters = remoteTrack.total_chapters
-            track.status = remoteTrack.status
         }
         return track
     }

+ 18 - 5
app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiApi.kt

@@ -47,6 +47,7 @@ class BangumiApi(private val client: OkHttpClient, interceptor: BangumiIntercept
         return withIOContext {
             // read status update
             val sbody = FormBody.Builder()
+                .add("rating", track.score.toInt().toString())
                 .add("status", track.toBangumiStatus())
                 .build()
             authClient.newCall(POST("$apiUrl/collection/${track.media_id}/update", body = sbody))
@@ -98,13 +99,18 @@ class BangumiApi(private val client: OkHttpClient, interceptor: BangumiIntercept
             // Sometimes JsonNull
             ""
         }
-
+        val totalChapters = if (obj["eps_count"] != null) {
+            obj["eps_count"]!!.jsonPrimitive.int
+        } else {
+            0
+        }
         return TrackSearch.create(TrackManager.BANGUMI).apply {
             media_id = obj["id"]!!.jsonPrimitive.int
             title = obj["name_cn"]!!.jsonPrimitive.content
             cover_url = coverUrl
             summary = obj["name"]!!.jsonPrimitive.content
             tracking_url = obj["url"]!!.jsonPrimitive.content
+            total_chapters = totalChapters
         }
     }
 
@@ -127,14 +133,21 @@ class BangumiApi(private val client: OkHttpClient, interceptor: BangumiIntercept
                 .build()
 
             // TODO: get user readed chapter here
-            authClient.newCall(requestUserRead)
-                .await()
-                .parseAs<Collection>()
-                .let {
+            var response = authClient.newCall(requestUserRead).await()
+            var responseBody = response.body?.string().orEmpty()
+            if (responseBody.isEmpty()) {
+                throw Exception("Null Response")
+            }
+            if (responseBody.contains("\"code\":400")) {
+                null
+            } else {
+                json.decodeFromString<Collection>(responseBody).let {
                     track.status = it.status?.id!!
                     track.last_chapter_read = it.ep_status!!
+                    track.score = it.rating!!
                     track
                 }
+            }
         }
     }
 

+ 1 - 1
app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Collection.kt

@@ -8,7 +8,7 @@ data class Collection(
     val comment: String? = "",
     val ep_status: Int? = 0,
     val lasttouch: Int? = 0,
-    val rating: Int? = 0,
+    val rating: Float? = 0f,
     val status: Status? = Status(),
     val tag: List<String?>? = listOf(),
     val user: User? = User(),