feat: Show average scores in tracker search results

Closes #8280
This commit is contained in:
arkon 2023-12-03 16:52:07 -05:00 committed by Claudemirovsky
parent 303dd2ef44
commit c94774eba3
No known key found for this signature in database
GPG key ID: 82AE76162407356E
11 changed files with 44 additions and 13 deletions

View file

@ -182,6 +182,7 @@ fun AnimeTrackerSearch(
status = it.publishing_status.toLowerCase(Locale.current).capitalize(
Locale.current,
),
score = it.score,
description = it.summary.trim(),
selected = it == selected,
onClick = { onSelectedChange(it) },

View file

@ -197,9 +197,8 @@ fun MangaTrackerSearch(
Locale.current,
),
startDate = it.start_date,
status = it.publishing_status.toLowerCase(Locale.current).capitalize(
Locale.current,
),
status = it.publishing_status.toLowerCase(Locale.current).capitalize(Locale.current),
score = it.score,
description = it.summary.trim(),
selected = it == selected,
onClick = { onSelectedChange(it) },
@ -225,6 +224,7 @@ fun SearchResultItem(
type: String,
startDate: String,
status: String,
score: Float,
description: String,
selected: Boolean,
onClick: () -> Unit,
@ -286,6 +286,12 @@ fun SearchResultItem(
text = status,
)
}
if (score != -1f) {
SearchResultItemDetails(
title = stringResource(MR.strings.score),
text = score.toString(),
)
}
}
}
if (description.isNotBlank()) {

View file

@ -250,6 +250,7 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) {
|month
|day
|}
|averageScore
|}
|}
|}
@ -303,6 +304,7 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) {
|month
|day
|}
|averageScore
|}
|}
|}
@ -533,6 +535,7 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) {
struct["status"]!!.jsonPrimitive.contentOrNull ?: "",
parseDate(struct, "startDate"),
struct["chapters"]!!.jsonPrimitive.intOrNull ?: 0,
struct["averageScore"]?.jsonPrimitive?.intOrNull ?: -1,
)
}
@ -546,6 +549,7 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) {
struct["status"]!!.jsonPrimitive.contentOrNull ?: "",
parseDate(struct, "startDate"),
struct["episodes"]!!.jsonPrimitive.intOrNull ?: 0,
struct["averageScore"]?.jsonPrimitive?.intOrNull ?: -1,
)
}

View file

@ -21,6 +21,7 @@ data class ALManga(
val publishing_status: String,
val start_date_fuzzy: Long,
val total_chapters: Int,
val average_score: Int,
) {
fun toTrack() = MangaTrackSearch.create(TrackerManager.ANILIST).apply {
@ -29,6 +30,7 @@ data class ALManga(
total_chapters = this@ALManga.total_chapters
cover_url = image_url_lge
summary = description?.htmlDecode() ?: ""
score = average_score.toFloat()
tracking_url = AnilistApi.mangaUrl(media_id)
publishing_status = this@ALManga.publishing_status
publishing_type = format
@ -52,6 +54,7 @@ data class ALAnime(
val publishing_status: String,
val start_date_fuzzy: Long,
val total_episodes: Int,
val average_score: Int,
) {
fun toTrack() = AnimeTrackSearch.create(TrackerManager.ANILIST).apply {
@ -60,6 +63,7 @@ data class ALAnime(
total_episodes = this@ALAnime.total_episodes
cover_url = image_url_lge
summary = description?.htmlDecode() ?: ""
score = average_score.toFloat()
tracking_url = AnilistApi.animeUrl(media_id)
publishing_status = this@ALAnime.publishing_status
publishing_type = format

View file

@ -13,6 +13,7 @@ import eu.kanade.tachiyomi.network.parseAs
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.contentOrNull
import kotlinx.serialization.json.floatOrNull
import kotlinx.serialization.json.int
import kotlinx.serialization.json.jsonArray
import kotlinx.serialization.json.jsonObject
@ -177,11 +178,13 @@ class BangumiApi(
} else {
0
}
val rating = obj["rating"]?.jsonObject?.get("score")?.jsonPrimitive?.floatOrNull ?: -1f
return MangaTrackSearch.create(trackId).apply {
media_id = obj["id"]!!.jsonPrimitive.long
title = obj["name_cn"]!!.jsonPrimitive.content
cover_url = coverUrl
summary = obj["name"]!!.jsonPrimitive.content
score = rating
tracking_url = obj["url"]!!.jsonPrimitive.content
total_chapters = totalChapters
}
@ -199,10 +202,13 @@ class BangumiApi(
} else {
0
}
val rating = obj["rating"]?.jsonObject?.get("score")?.jsonPrimitive?.floatOrNull ?: -1f
return AnimeTrackSearch.create(trackId).apply {
media_id = obj["id"]!!.jsonPrimitive.long
title = obj["name_cn"]!!.jsonPrimitive.content
cover_url = coverUrl
score = rating
summary = obj["name"]!!.jsonPrimitive.content
tracking_url = obj["url"]!!.jsonPrimitive.content
total_episodes = totalChapters

View file

@ -483,13 +483,14 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor)
"https://AWQO5J657S-dsn.algolia.net/1/indexes/production_media/query/"
private const val algoliaAppId = "AWQO5J657S"
private const val algoliaFilter =
"&facetFilters=%5B%22kind%3Amanga%22%5D&attributesToRetrieve=%5B%22synopsis%22%2C%22canonicalTitle%22%2C" +
"%22chapterCount%22%2C%22posterImage%22%2C%22" +
"startDate%22%2C%22subtype%22%2C%22endDate%22%2C%20%22id%22%5D"
"&facetFilters=%5B%22kind%3Amanga%22%5D&attributesToRetrieve=" +
"%5B%22synopsis%22%2C%22averageRating%22%2C%22canonicalTitle%22%2C%22chapterCount%22%2C%22" +
"posterImage%22%2C%22startDate%22%2C%22subtype%22%2C%22endDate%22%2C%20%22id%22%5D"
private const val algoliaFilterAnime =
"&facetFilters=%5B%22kind%3Aanime%22%5D&attributesToRetrieve=%5B%22synopsis%22%2C%22canonicalTitle%22%2C" +
"%22episodeCount%22%2C%22posterImage%22%2C%22" +
"startDate%22%2C%22subtype%22%2C%22endDate%22%2C%20%22id%22%5D"
"&facetFilters=%5B%22kind%3Aanime%22%5D&attributesToRetrieve=" +
"%5B%22synopsis%22%2C%22averageRating%22%2C%22canonicalTitle%22%2C%22episodeCount%22%2C%22" +
"posterImage%22%2C%22startDate%22%2C%22subtype%22%2C%22endDate%22%2C%20%22id%22%5D"
fun mangaUrl(remoteId: Long): String {
return baseMangaUrl + remoteId

View file

@ -30,6 +30,7 @@ class KitsuSearchManga(obj: JsonObject) {
null
}
private val synopsis = obj["synopsis"]?.jsonPrimitive?.contentOrNull
private val rating = obj["averageRating"]?.jsonPrimitive?.contentOrNull?.toFloatOrNull()
private var startDate = obj["startDate"]?.jsonPrimitive?.contentOrNull?.let {
val outputDf = SimpleDateFormat("yyyy-MM-dd", Locale.US)
outputDf.format(Date(it.toLong() * 1000))
@ -44,6 +45,7 @@ class KitsuSearchManga(obj: JsonObject) {
cover_url = original ?: ""
summary = synopsis ?: ""
tracking_url = KitsuApi.mangaUrl(media_id)
score = rating ?: -1f
publishing_status = if (endDate == null) {
"Publishing"
} else {
@ -66,6 +68,7 @@ class KitsuSearchAnime(obj: JsonObject) {
null
}
private val synopsis = obj["synopsis"]?.jsonPrimitive?.contentOrNull
private val rating = obj["averageRating"]?.jsonPrimitive?.contentOrNull?.toFloatOrNull()
private var startDate = obj["startDate"]?.jsonPrimitive?.contentOrNull?.let {
val outputDf = SimpleDateFormat("yyyy-MM-dd", Locale.US)
outputDf.format(Date(it.toLong() * 1000))
@ -80,6 +83,7 @@ class KitsuSearchAnime(obj: JsonObject) {
cover_url = original ?: ""
summary = synopsis ?: ""
tracking_url = KitsuApi.animeUrl(media_id)
score = rating ?: -1f
publishing_status = if (endDate == null) {
"Publishing"
} else {

View file

@ -20,7 +20,7 @@ class AnimeTrackSearch : AnimeTrack {
override var total_episodes: Int = 0
override var score: Float = 0f
override var score: Float = -1f
override var status: Int = 0

View file

@ -20,7 +20,7 @@ class MangaTrackSearch : MangaTrack {
override var total_chapters: Int = 0
override var score: Float = 0f
override var score: Float = -1f
override var status: Int = 0

View file

@ -18,6 +18,7 @@ import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.boolean
import kotlinx.serialization.json.contentOrNull
import kotlinx.serialization.json.float
import kotlinx.serialization.json.floatOrNull
import kotlinx.serialization.json.int
import kotlinx.serialization.json.jsonArray
import kotlinx.serialization.json.jsonObject
@ -130,7 +131,7 @@ class MyAnimeListApi(
.appendPath(id.toString())
.appendQueryParameter(
"fields",
"id,title,synopsis,num_chapters,main_picture,status,media_type,start_date",
"id,title,synopsis,num_chapters,mean,main_picture,status,media_type,start_date",
)
.build()
with(json) {
@ -144,6 +145,7 @@ class MyAnimeListApi(
title = obj["title"]!!.jsonPrimitive.content
summary = obj["synopsis"]?.jsonPrimitive?.content ?: ""
total_chapters = obj["num_chapters"]!!.jsonPrimitive.int
score = obj["mean"]?.jsonPrimitive?.floatOrNull ?: -1f
cover_url =
obj["main_picture"]?.jsonObject?.get("large")?.jsonPrimitive?.content
?: ""
@ -170,7 +172,7 @@ class MyAnimeListApi(
.appendPath(id.toString())
.appendQueryParameter(
"fields",
"id,title,synopsis,num_episodes,main_picture,status,media_type,start_date",
"id,title,synopsis,num_episodes,mean,main_picture,status,media_type,start_date",
)
.build()
with(json) {
@ -184,6 +186,7 @@ class MyAnimeListApi(
title = obj["title"]!!.jsonPrimitive.content
summary = obj["synopsis"]?.jsonPrimitive?.content ?: ""
total_episodes = obj["num_episodes"]!!.jsonPrimitive.int
score = obj["mean"]?.jsonPrimitive?.floatOrNull ?: -1f
cover_url =
obj["main_picture"]?.jsonObject?.get("large")?.jsonPrimitive?.content
?: ""

View file

@ -177,6 +177,7 @@ class ShikimoriApi(
total_chapters = obj["chapters"]!!.jsonPrimitive.int
cover_url = baseUrl + obj["image"]!!.jsonObject["preview"]!!.jsonPrimitive.content
summary = ""
score = obj["score"]!!.jsonPrimitive.float
tracking_url = baseUrl + obj["url"]!!.jsonPrimitive.content
publishing_status = obj["status"]!!.jsonPrimitive.content
publishing_type = obj["kind"]!!.jsonPrimitive.content
@ -191,6 +192,7 @@ class ShikimoriApi(
total_episodes = obj["episodes"]!!.jsonPrimitive.int
cover_url = baseUrl + obj["image"]!!.jsonObject["preview"]!!.jsonPrimitive.content
summary = ""
score = obj["score"]!!.jsonPrimitive.float
tracking_url = baseUrl + obj["url"]!!.jsonPrimitive.content
publishing_status = obj["status"]!!.jsonPrimitive.content
publishing_type = obj["kind"]!!.jsonPrimitive.content