Update SimklApi.kt (#961)

This commit is contained in:
self-similarity 2024-03-02 22:45:18 +00:00 committed by GitHub
parent 1a380a3239
commit 809a38507b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -440,9 +440,9 @@ class SimklApi(index: Int) : AccountManager(index), SyncAPI {
interceptor = interceptor interceptor = interceptor
).isSuccessful ).isSuccessful
} else { } else {
val statusResponse = status?.let { setStatus -> val statusResponse = this.status?.let { setStatus ->
val newStatus = val newStatus =
SimklListStatusType.values() SimklListStatusType.entries
.firstOrNull { it.value == setStatus }?.originalName .firstOrNull { it.value == setStatus }?.originalName
?: SimklListStatusType.Watching.originalName!! ?: SimklListStatusType.Watching.originalName!!
@ -479,9 +479,14 @@ class SimklApi(index: Int) : AccountManager(index), SyncAPI {
).isSuccessful ).isSuccessful
} ?: true } ?: true
// You cannot rate if you are planning to watch it.
val shouldRate =
score != null && status != SimklListStatusType.Planning.value
val realScore = if (shouldRate) score else null
val historyResponse = val historyResponse =
// Only post if there are episodes or score to upload // Only post if there are episodes or score to upload
if (addEpisodes != null || score != null) { if (addEpisodes != null || shouldRate) {
app.post( app.post(
"${this.url}/sync/history", "${this.url}/sync/history",
json = StatusRequest( json = StatusRequest(
@ -492,8 +497,8 @@ class SimklApi(index: Int) : AccountManager(index), SyncAPI {
ids, ids,
addEpisodes?.first, addEpisodes?.first,
addEpisodes?.second, addEpisodes?.second,
score, realScore,
score?.let { time }, realScore?.let { time },
) )
), movies = emptyList() ), movies = emptyList()
), ),
@ -827,7 +832,13 @@ class SimklApi(index: Int) : AccountManager(index), SyncAPI {
if (foundItem != null) { if (foundItem != null) {
return SimklSyncStatus( return SimklSyncStatus(
status = foundItem.status?.let { SyncWatchType.fromInternalId(SimklListStatusType.fromString(it)?.value) } status = foundItem.status?.let {
SyncWatchType.fromInternalId(
SimklListStatusType.fromString(
it
)?.value
)
}
?: return null, ?: return null,
score = foundItem.user_rating, score = foundItem.user_rating,
watchedEpisodes = foundItem.watched_episodes_count, watchedEpisodes = foundItem.watched_episodes_count,
@ -839,7 +850,7 @@ class SimklApi(index: Int) : AccountManager(index), SyncAPI {
) )
} else { } else {
return SimklSyncStatus( return SimklSyncStatus(
status = SyncWatchType.fromInternalId(SimklListStatusType.None.value) , status = SyncWatchType.fromInternalId(SimklListStatusType.None.value),
score = 0, score = 0,
watchedEpisodes = 0, watchedEpisodes = 0,
maxEpisodes = if (searchResult.type == "movie") 0 else searchResult.total_episodes, maxEpisodes = if (searchResult.type == "movie") 0 else searchResult.total_episodes,
@ -859,11 +870,13 @@ class SimklApi(index: Int) : AccountManager(index), SyncAPI {
val builder = SimklScoreBuilder.Builder() val builder = SimklScoreBuilder.Builder()
.apiUrl(this.mainUrl) .apiUrl(this.mainUrl)
.score(status.score, simklStatus?.oldScore) .score(status.score, simklStatus?.oldScore)
.status(status.status.internalId, (status as? SimklSyncStatus)?.oldStatus?.let { oldStatus -> .status(
SimklListStatusType.values().firstOrNull { status.status.internalId,
it.originalName == oldStatus (status as? SimklSyncStatus)?.oldStatus?.let { oldStatus ->
}?.value SimklListStatusType.entries.firstOrNull {
}) it.originalName == oldStatus
}?.value
})
.interceptor(interceptor) .interceptor(interceptor)
.ids(MediaObject.Ids.fromMap(parsedId)) .ids(MediaObject.Ids.fromMap(parsedId))
@ -996,7 +1009,7 @@ class SimklApi(index: Int) : AccountManager(index), SyncAPI {
val list = getSyncListSmart() ?: return null val list = getSyncListSmart() ?: return null
val baseMap = val baseMap =
SimklListStatusType.values() SimklListStatusType.entries
.filter { it.value >= 0 && it.value != SimklListStatusType.ReWatching.value } .filter { it.value >= 0 && it.value != SimklListStatusType.ReWatching.value }
.associate { .associate {
it.stringRes to emptyList<SyncAPI.LibraryItem>() it.stringRes to emptyList<SyncAPI.LibraryItem>()