Skip to content

Commit

Permalink
Added Simkl (#548)
Browse files Browse the repository at this point in the history
  • Loading branch information
self-similarity committed Aug 12, 2023
1 parent dd4f4a2 commit d2d2e41
Show file tree
Hide file tree
Showing 16 changed files with 986 additions and 61 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build_to_archive.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ jobs:
SIGNING_KEY_ALIAS: "key0"
SIGNING_KEY_PASSWORD: ${{ steps.fetch_keystore.outputs.key_pwd }}
SIGNING_STORE_PASSWORD: ${{ steps.fetch_keystore.outputs.key_pwd }}
SIMKL_CLIENT_ID: ${{ secrets.SIMKL_CLIENT_ID }}
SIMKL_CLIENT_SECRET: ${{ secrets.SIMKL_CLIENT_SECRET }}
- uses: actions/checkout@v3
with:
repository: "recloudstream/cloudstream-archive"
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ jobs:
SIGNING_KEY_ALIAS: "key0"
SIGNING_KEY_PASSWORD: ${{ steps.fetch_keystore.outputs.key_pwd }}
SIGNING_STORE_PASSWORD: ${{ steps.fetch_keystore.outputs.key_pwd }}
SIMKL_CLIENT_ID: ${{ secrets.SIMKL_CLIENT_ID }}
SIMKL_CLIENT_SECRET: ${{ secrets.SIMKL_CLIENT_SECRET }}
- name: Create pre-release
uses: "marvinpinto/action-automatic-releases@latest"
with:
Expand Down
25 changes: 18 additions & 7 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties
import org.jetbrains.dokka.gradle.DokkaTask
import java.io.ByteArrayOutputStream
import java.net.URL
Expand Down Expand Up @@ -54,17 +55,27 @@ android {
versionName = "4.1.3"

resValue("string", "app_version", "${defaultConfig.versionName}${versionNameSuffix ?: ""}")

resValue("string", "commit_hash", "git rev-parse --short HEAD".execute() ?: "")

resValue("bool", "is_prerelease", "false")

// Reads local.properties
val localProperties = gradleLocalProperties(rootDir)

buildConfigField(
"String",
"BUILDDATE",
"new java.text.SimpleDateFormat(\"yyyy-MM-dd HH:mm\").format(new java.util.Date(" + System.currentTimeMillis() + "L));"
)

buildConfigField(
"String",
"SIMKL_CLIENT_ID",
"\"" + (System.getenv("SIMKL_CLIENT_ID") ?: localProperties["simkl.id"]) + "\""
)
buildConfigField(
"String",
"SIMKL_CLIENT_SECRET",
"\"" + (System.getenv("SIMKL_CLIENT_SECRET") ?: localProperties["simkl.secret"]) + "\""
)
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

kapt {
Expand Down Expand Up @@ -108,9 +119,9 @@ android {
}
}
//toolchain {
// languageVersion.set(JavaLanguageVersion.of(17))
// }
// jvmToolchain(17)
// languageVersion.set(JavaLanguageVersion.of(17))
// }
// jvmToolchain(17)

compileOptions {
isCoreLibraryDesugaringEnabled = true
Expand Down Expand Up @@ -211,7 +222,7 @@ dependencies {
// Networking
// implementation("com.squareup.okhttp3:okhttp:4.9.2")
// implementation("com.squareup.okhttp3:okhttp-dnsoverhttps:4.9.1")
implementation("com.github.Blatzar:NiceHttp:0.4.2")
implementation("com.github.Blatzar:NiceHttp:0.4.3")
// To fix SSL fuckery on android 9
implementation("org.conscrypt:conscrypt-android:2.2.1")
// Util to skip the URI file fuckery 🙏
Expand Down
29 changes: 28 additions & 1 deletion app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.json.JsonMapper
import com.fasterxml.jackson.module.kotlin.KotlinModule
import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.aniListApi
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.malApi
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.simklApi
import com.lagradost.cloudstream3.syncproviders.SyncIdName
import com.lagradost.cloudstream3.syncproviders.providers.SimklApi
import com.lagradost.cloudstream3.ui.player.SubtitleData
import com.lagradost.cloudstream3.utils.*
import com.lagradost.cloudstream3.utils.AppUtils.toJson
Expand Down Expand Up @@ -821,7 +824,8 @@ public enum class AutoDownloadMode(val value: Int) {
;

companion object {
infix fun getEnum(value: Int): AutoDownloadMode? = AutoDownloadMode.values().firstOrNull { it.value == value }
infix fun getEnum(value: Int): AutoDownloadMode? =
AutoDownloadMode.values().firstOrNull { it.value == value }
}
}

Expand Down Expand Up @@ -1143,6 +1147,7 @@ interface LoadResponse {
companion object {
private val malIdPrefix = malApi.idPrefix
private val aniListIdPrefix = aniListApi.idPrefix
private val simklIdPrefix = simklApi.idPrefix
var isTrailersEnabled = true

fun LoadResponse.isMovie(): Boolean {
Expand All @@ -1164,6 +1169,20 @@ interface LoadResponse {
this.actors = actors?.map { (actor, role) -> ActorData(actor, role = role) }
}

/**
* Internal helper function to add simkl ids from other databases.
*/
private fun LoadResponse.addSimklId(
database: SimklApi.Companion.SyncServices,
id: String?
) {
normalSafeApiCall {
this.syncData[simklIdPrefix] =
SimklApi.addIdToString(this.syncData[simklIdPrefix], database, id.toString())
?: return@normalSafeApiCall
}
}

@JvmName("addActorsOnly")
fun LoadResponse.addActors(actors: List<Actor>?) {
this.actors = actors?.map { actor -> ActorData(actor) }
Expand All @@ -1179,10 +1198,16 @@ interface LoadResponse {

fun LoadResponse.addMalId(id: Int?) {
this.syncData[malIdPrefix] = (id ?: return).toString()
this.addSimklId(SimklApi.Companion.SyncServices.Mal, id.toString())
}

fun LoadResponse.addAniListId(id: Int?) {
this.syncData[aniListIdPrefix] = (id ?: return).toString()
this.addSimklId(SimklApi.Companion.SyncServices.AniList, id.toString())
}

fun LoadResponse.addSimklId(id: Int?) {
this.addSimklId(SimklApi.Companion.SyncServices.Simkl, id.toString())
}

fun LoadResponse.addImdbUrl(url: String?) {
Expand Down Expand Up @@ -1264,6 +1289,7 @@ interface LoadResponse {

fun LoadResponse.addImdbId(id: String?) {
// TODO add imdb sync
this.addSimklId(SimklApi.Companion.SyncServices.Imdb, id)
}

fun LoadResponse.addTrackId(id: String?) {
Expand All @@ -1276,6 +1302,7 @@ interface LoadResponse {

fun LoadResponse.addTMDbId(id: String?) {
// TODO add TMDb sync
this.addSimklId(SimklApi.Companion.SyncServices.Tmdb, id)
}

fun LoadResponse.addRating(text: String?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,27 @@ abstract class AccountManager(private val defIndex: Int) : AuthAPI {
val malApi = MALApi(0)
val aniListApi = AniListApi(0)
val openSubtitlesApi = OpenSubtitlesApi(0)
val simklApi = SimklApi(0)
val indexSubtitlesApi = IndexSubtitleApi()
val addic7ed = Addic7ed()
val localListApi = LocalList()

// used to login via app intent
val OAuth2Apis
get() = listOf<OAuth2API>(
malApi, aniListApi
malApi, aniListApi, simklApi
)

// this needs init with context and can be accessed in settings
val accountManagers
get() = listOf(
malApi, aniListApi, openSubtitlesApi, //nginxApi
malApi, aniListApi, openSubtitlesApi, simklApi //nginxApi
)

// used for active syncing
val SyncApis
get() = listOf(
SyncRepo(malApi), SyncRepo(aniListApi), SyncRepo(localListApi)
SyncRepo(malApi), SyncRepo(aniListApi), SyncRepo(localListApi), SyncRepo(simklApi)
)

val inAppAuths
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ enum class SyncIdName {
MyAnimeList,
Trakt,
Imdb,
LocalList
Simkl,
LocalList,
}

interface SyncAPI : OAuth2API {
Expand All @@ -35,9 +36,9 @@ interface SyncAPI : OAuth2API {
4 -> PlanToWatch
5 -> ReWatching
*/
suspend fun score(id: String, status: SyncStatus): Boolean
suspend fun score(id: String, status: AbstractSyncStatus): Boolean

suspend fun getStatus(id: String): SyncStatus?
suspend fun getStatus(id: String): AbstractSyncStatus?

suspend fun getResult(id: String): SyncResult?

Expand All @@ -59,14 +60,24 @@ interface SyncAPI : OAuth2API {
override var id: Int? = null,
) : SearchResponse

abstract class AbstractSyncStatus {
abstract var status: Int

/** 1-10 */
abstract var score: Int?
abstract var watchedEpisodes: Int?
abstract var isFavorite: Boolean?
abstract var maxEpisodes: Int?
}

data class SyncStatus(
val status: Int,
override var status: Int,
/** 1-10 */
val score: Int?,
val watchedEpisodes: Int?,
var isFavorite: Boolean? = null,
var maxEpisodes: Int? = null,
)
override var score: Int?,
override var watchedEpisodes: Int?,
override var isFavorite: Boolean? = null,
override var maxEpisodes: Int? = null,
) : AbstractSyncStatus()

data class SyncResult(
/**Used to verify*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ class SyncRepo(private val repo: SyncAPI) {
repo.requireLibraryRefresh = value
}

suspend fun score(id: String, status: SyncAPI.SyncStatus): Resource<Boolean> {
suspend fun score(id: String, status: SyncAPI.AbstractSyncStatus): Resource<Boolean> {
return safeApiCall { repo.score(id, status) }
}

suspend fun getStatus(id: String): Resource<SyncAPI.SyncStatus> {
suspend fun getStatus(id: String): Resource<SyncAPI.AbstractSyncStatus> {
return safeApiCall { repo.getStatus(id) ?: throw ErrorLoadingException("No data") }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class AniListApi(index: Int) : AccountManager(index), SyncAPI {
)
}

override suspend fun getStatus(id: String): SyncAPI.SyncStatus? {
override suspend fun getStatus(id: String): SyncAPI.AbstractSyncStatus? {
val internalId = id.toIntOrNull() ?: return null
val data = getDataAboutId(internalId) ?: return null

Expand All @@ -171,7 +171,7 @@ class AniListApi(index: Int) : AccountManager(index), SyncAPI {
)
}

override suspend fun score(id: String, status: SyncAPI.SyncStatus): Boolean {
override suspend fun score(id: String, status: SyncAPI.AbstractSyncStatus): Boolean {
return postDataAboutId(
id.toIntOrNull() ?: return false,
fromIntToAnimeStatus(status.status),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ class LocalList : SyncAPI {

override val mainUrl = ""
override val syncIdName = SyncIdName.LocalList
override suspend fun score(id: String, status: SyncAPI.SyncStatus): Boolean {
override suspend fun score(id: String, status: SyncAPI.AbstractSyncStatus): Boolean {
return true
}

override suspend fun getStatus(id: String): SyncAPI.SyncStatus? {
override suspend fun getStatus(id: String): SyncAPI.AbstractSyncStatus? {
return null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class MALApi(index: Int) : AccountManager(index), SyncAPI {
return Regex("""/anime/((.*)/|(.*))""").find(url)!!.groupValues.first()
}

override suspend fun score(id: String, status: SyncAPI.SyncStatus): Boolean {
override suspend fun score(id: String, status: SyncAPI.AbstractSyncStatus): Boolean {
return setScoreRequest(
id.toIntOrNull() ?: return false,
fromIntToAnimeStatus(status.status),
Expand Down
Loading

0 comments on commit d2d2e41

Please sign in to comment.