Fix score issue with MangaUpdates

Also add custom user agent

Potentially fix #17
This commit is contained in:
AntsyLich 2024-01-18 01:28:41 +06:00
parent e34043f1fe
commit 99fd2731f5
No known key found for this signature in database
2 changed files with 24 additions and 10 deletions

View file

@ -6,6 +6,8 @@ import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.database.models.Track
import eu.kanade.tachiyomi.data.track.BaseTracker import eu.kanade.tachiyomi.data.track.BaseTracker
import eu.kanade.tachiyomi.data.track.DeletableTracker import eu.kanade.tachiyomi.data.track.DeletableTracker
import eu.kanade.tachiyomi.data.track.mangaupdates.dto.ListItem
import eu.kanade.tachiyomi.data.track.mangaupdates.dto.Rating
import eu.kanade.tachiyomi.data.track.mangaupdates.dto.copyTo import eu.kanade.tachiyomi.data.track.mangaupdates.dto.copyTo
import eu.kanade.tachiyomi.data.track.mangaupdates.dto.toTrackSearch import eu.kanade.tachiyomi.data.track.mangaupdates.dto.toTrackSearch
import eu.kanade.tachiyomi.data.track.model.TrackSearch import eu.kanade.tachiyomi.data.track.model.TrackSearch
@ -23,10 +25,16 @@ class MangaUpdates(id: Long) : BaseTracker(id, "MangaUpdates"), DeletableTracker
const val UNFINISHED_LIST = 3 const val UNFINISHED_LIST = 3
const val ON_HOLD_LIST = 4 const val ON_HOLD_LIST = 4
private val SCORE_LIST = ( private val SCORE_LIST = (0..10)
(0..9) .flatMap { decimal ->
.flatMap { i -> (0..9).map { j -> "$i.$j" } } + listOf("10.0") when (decimal) {
) 0 -> listOf("-")
10 -> listOf("10.0")
else -> (0..9).map { fraction ->
"$decimal.$fraction"
}
}
}
.toImmutableList() .toImmutableList()
} }
@ -59,7 +67,7 @@ class MangaUpdates(id: Long) : BaseTracker(id, "MangaUpdates"), DeletableTracker
override fun getScoreList(): ImmutableList<String> = SCORE_LIST override fun getScoreList(): ImmutableList<String> = SCORE_LIST
override fun indexToScore(index: Int): Float = SCORE_LIST[index].toFloat() override fun indexToScore(index: Int): Float = if (index == 0) 0f else SCORE_LIST[index].toFloat()
override fun displayScore(track: DomainTrack): String = track.score.toString() override fun displayScore(track: DomainTrack): String = track.score.toString()
@ -78,9 +86,9 @@ class MangaUpdates(id: Long) : BaseTracker(id, "MangaUpdates"), DeletableTracker
override suspend fun bind(track: Track, hasReadChapters: Boolean): Track { override suspend fun bind(track: Track, hasReadChapters: Boolean): Track {
return try { return try {
val (series, rating) = api.getSeriesListItem(track) val (series, rating) = api.getSeriesListItem(track)
series.copyTo(track) track.copyFrom(series, rating)
rating?.copyTo(track) ?: track
} catch (e: Exception) { } catch (e: Exception) {
track.score = 0f
api.addSeriesToList(track, hasReadChapters) api.addSeriesToList(track, hasReadChapters)
track track
} }
@ -95,8 +103,12 @@ class MangaUpdates(id: Long) : BaseTracker(id, "MangaUpdates"), DeletableTracker
override suspend fun refresh(track: Track): Track { override suspend fun refresh(track: Track): Track {
val (series, rating) = api.getSeriesListItem(track) val (series, rating) = api.getSeriesListItem(track)
series.copyTo(track) return track.copyFrom(series, rating)
return rating?.copyTo(track) ?: track }
private fun Track.copyFrom(item: ListItem, rating: Rating?): Track = apply {
item.copyTo(this)
score = rating?.rating ?: 0f
} }
override suspend fun login(username: String, password: String) { override suspend fun login(username: String, password: String) {
@ -106,6 +118,6 @@ class MangaUpdates(id: Long) : BaseTracker(id, "MangaUpdates"), DeletableTracker
} }
fun restoreSession(): String? { fun restoreSession(): String? {
return trackPreferences.trackPassword(this).get() return trackPreferences.trackPassword(this).get().ifBlank { null }
} }
} }

View file

@ -1,5 +1,6 @@
package eu.kanade.tachiyomi.data.track.mangaupdates package eu.kanade.tachiyomi.data.track.mangaupdates
import eu.kanade.tachiyomi.BuildConfig
import okhttp3.Interceptor import okhttp3.Interceptor
import okhttp3.Response import okhttp3.Response
import java.io.IOException import java.io.IOException
@ -18,6 +19,7 @@ class MangaUpdatesInterceptor(
// Add the authorization header to the original request. // Add the authorization header to the original request.
val authRequest = originalRequest.newBuilder() val authRequest = originalRequest.newBuilder()
.addHeader("Authorization", "Bearer $token") .addHeader("Authorization", "Bearer $token")
.header("User-Agent", "Mihon v${BuildConfig.VERSION_NAME} (${BuildConfig.APPLICATION_ID})")
.build() .build()
return chain.proceed(authRequest) return chain.proceed(authRequest)