AquaStream/app/src/main/java/com/lagradost/cloudstream3/syncproviders/SyncRepo.kt

48 lines
1.7 KiB
Kotlin
Raw Normal View History

2022-04-01 20:05:34 +00:00
package com.lagradost.cloudstream3.syncproviders
import com.lagradost.cloudstream3.ErrorLoadingException
import com.lagradost.cloudstream3.mvvm.Resource
2022-04-02 22:06:35 +00:00
import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
2022-04-01 20:05:34 +00:00
import com.lagradost.cloudstream3.mvvm.safeApiCall
class SyncRepo(private val repo: SyncAPI) {
2022-04-02 22:06:35 +00:00
val idPrefix = repo.idPrefix
val name = repo.name
2022-04-03 01:13:02 +00:00
val icon = repo.icon
2022-04-18 00:26:13 +00:00
val mainUrl = repo.mainUrl
val requiresLogin = repo.requiresLogin
2023-01-28 22:38:02 +00:00
val syncIdName = repo.syncIdName
var requireLibraryRefresh: Boolean
get() = repo.requireLibraryRefresh
set(value) {
repo.requireLibraryRefresh = value
}
2022-04-01 20:05:34 +00:00
2023-08-12 20:25:30 +00:00
suspend fun score(id: String, status: SyncAPI.AbstractSyncStatus): Resource<Boolean> {
2022-04-01 20:05:34 +00:00
return safeApiCall { repo.score(id, status) }
}
2023-08-12 20:25:30 +00:00
suspend fun getStatus(id: String): Resource<SyncAPI.AbstractSyncStatus> {
2022-04-01 20:05:34 +00:00
return safeApiCall { repo.getStatus(id) ?: throw ErrorLoadingException("No data") }
}
2023-01-28 22:38:02 +00:00
suspend fun getResult(id: String): Resource<SyncAPI.SyncResult> {
2022-04-01 20:05:34 +00:00
return safeApiCall { repo.getResult(id) ?: throw ErrorLoadingException("No data") }
}
2023-01-28 22:38:02 +00:00
suspend fun search(query: String): Resource<List<SyncAPI.SyncSearchResult>> {
2022-04-01 20:05:34 +00:00
return safeApiCall { repo.search(query) ?: throw ErrorLoadingException() }
}
2022-04-02 22:06:35 +00:00
2023-01-28 22:38:02 +00:00
suspend fun getPersonalLibrary(): Resource<SyncAPI.LibraryMetadata> {
return safeApiCall { repo.getPersonalLibrary() ?: throw ErrorLoadingException() }
}
fun hasAccount(): Boolean {
2022-04-02 22:06:35 +00:00
return normalSafeApiCall { repo.loginInfo() != null } ?: false
}
2022-04-18 00:26:13 +00:00
2023-01-28 22:38:02 +00:00
fun getIdFromUrl(url: String): String? = normalSafeApiCall {
repo.getIdFromUrl(url)
}
2022-04-01 20:05:34 +00:00
}