2021-06-15 16:07:20 +00:00
|
|
|
package com.lagradost.cloudstream3.utils
|
|
|
|
|
2022-02-05 22:21:45 +00:00
|
|
|
import com.fasterxml.jackson.annotation.JsonProperty
|
2021-12-16 23:45:20 +00:00
|
|
|
import com.lagradost.cloudstream3.AcraApplication.Companion.getKey
|
|
|
|
import com.lagradost.cloudstream3.AcraApplication.Companion.getKeys
|
|
|
|
import com.lagradost.cloudstream3.AcraApplication.Companion.removeKey
|
|
|
|
import com.lagradost.cloudstream3.AcraApplication.Companion.setKey
|
|
|
|
import com.lagradost.cloudstream3.DubStatus
|
2021-07-30 14:09:57 +00:00
|
|
|
import com.lagradost.cloudstream3.SearchResponse
|
|
|
|
import com.lagradost.cloudstream3.TvType
|
2021-06-15 23:25:58 +00:00
|
|
|
import com.lagradost.cloudstream3.ui.WatchType
|
2021-06-15 16:07:20 +00:00
|
|
|
|
|
|
|
const val VIDEO_POS_DUR = "video_pos_dur"
|
2021-06-15 23:25:58 +00:00
|
|
|
const val RESULT_WATCH_STATE = "result_watch_state"
|
2021-07-30 14:09:57 +00:00
|
|
|
const val RESULT_WATCH_STATE_DATA = "result_watch_state_data"
|
2021-08-25 15:28:25 +00:00
|
|
|
const val RESULT_RESUME_WATCHING = "result_resume_watching"
|
2021-06-26 22:15:19 +00:00
|
|
|
const val RESULT_SEASON = "result_season"
|
2021-12-16 23:45:20 +00:00
|
|
|
const val RESULT_DUB = "result_dub"
|
2021-06-15 16:07:20 +00:00
|
|
|
|
|
|
|
object DataStoreHelper {
|
2022-02-05 22:21:45 +00:00
|
|
|
data class PosDur(
|
|
|
|
@JsonProperty("position") val position: Long,
|
|
|
|
@JsonProperty("duration") val duration: Long
|
|
|
|
)
|
2021-07-30 14:09:57 +00:00
|
|
|
|
2021-07-18 23:57:04 +00:00
|
|
|
fun PosDur.fixVisual(): PosDur {
|
|
|
|
if (duration <= 0) return PosDur(0, duration)
|
|
|
|
val percentage = position * 100 / duration
|
|
|
|
if (percentage <= 1) return PosDur(0, duration)
|
|
|
|
if (percentage <= 5) return PosDur(5 * duration / 100, duration)
|
|
|
|
if (percentage >= 95) return PosDur(duration, duration)
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
2021-07-30 14:09:57 +00:00
|
|
|
data class BookmarkedData(
|
2022-02-05 22:21:45 +00:00
|
|
|
@JsonProperty("id") override val id: Int?,
|
|
|
|
@JsonProperty("bookmarkedTime") val bookmarkedTime: Long,
|
|
|
|
@JsonProperty("latestUpdatedTime") val latestUpdatedTime: Long,
|
|
|
|
@JsonProperty("name") override val name: String,
|
|
|
|
@JsonProperty("url") override val url: String,
|
|
|
|
@JsonProperty("apiName") override val apiName: String,
|
|
|
|
@JsonProperty("type") override val type: TvType,
|
|
|
|
@JsonProperty("posterUrl") override val posterUrl: String?,
|
|
|
|
@JsonProperty("year") val year: Int?,
|
2021-08-25 15:28:25 +00:00
|
|
|
) : SearchResponse
|
|
|
|
|
|
|
|
data class ResumeWatchingResult(
|
2022-02-05 22:21:45 +00:00
|
|
|
@JsonProperty("name") override val name: String,
|
|
|
|
@JsonProperty("url") override val url: String,
|
|
|
|
@JsonProperty("apiName") override val apiName: String,
|
|
|
|
@JsonProperty("type") override val type: TvType,
|
|
|
|
@JsonProperty("posterUrl") override val posterUrl: String?,
|
|
|
|
|
|
|
|
@JsonProperty("watchPos") val watchPos: PosDur?,
|
|
|
|
|
|
|
|
@JsonProperty("id") override val id: Int?,
|
|
|
|
@JsonProperty("parentId") val parentId: Int?,
|
|
|
|
@JsonProperty("episode") val episode: Int?,
|
|
|
|
@JsonProperty("season") val season: Int?,
|
|
|
|
@JsonProperty("isFromDownload") val isFromDownload: Boolean,
|
2021-07-30 14:09:57 +00:00
|
|
|
) : SearchResponse
|
|
|
|
|
2021-06-15 16:07:20 +00:00
|
|
|
var currentAccount: String = "0" //TODO ACCOUNT IMPLEMENTATION
|
|
|
|
|
2021-12-16 23:45:20 +00:00
|
|
|
fun getAllWatchStateIds(): List<Int>? {
|
2021-07-30 21:03:46 +00:00
|
|
|
val folder = "$currentAccount/$RESULT_WATCH_STATE"
|
2021-12-16 23:45:20 +00:00
|
|
|
return getKeys(folder)?.mapNotNull {
|
2021-07-30 23:41:54 +00:00
|
|
|
it.removePrefix("$folder/").toIntOrNull()
|
|
|
|
}
|
2021-07-30 21:03:46 +00:00
|
|
|
}
|
|
|
|
|
2021-12-16 23:45:20 +00:00
|
|
|
fun getAllResumeStateIds(): List<Int>? {
|
2021-08-25 15:28:25 +00:00
|
|
|
val folder = "$currentAccount/$RESULT_RESUME_WATCHING"
|
2021-12-16 23:45:20 +00:00
|
|
|
return getKeys(folder)?.mapNotNull {
|
2021-08-25 15:28:25 +00:00
|
|
|
it.removePrefix("$folder/").toIntOrNull()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-16 23:45:20 +00:00
|
|
|
fun setLastWatched(
|
2021-08-25 15:28:25 +00:00
|
|
|
parentId: Int?,
|
|
|
|
episodeId: Int?,
|
|
|
|
episode: Int?,
|
|
|
|
season: Int?,
|
|
|
|
isFromDownload: Boolean = false
|
|
|
|
) {
|
|
|
|
if (parentId == null || episodeId == null) return
|
|
|
|
setKey(
|
|
|
|
"$currentAccount/$RESULT_RESUME_WATCHING",
|
|
|
|
parentId.toString(),
|
|
|
|
VideoDownloadHelper.ResumeWatching(
|
|
|
|
parentId,
|
|
|
|
episodeId,
|
|
|
|
episode,
|
|
|
|
season,
|
|
|
|
System.currentTimeMillis(),
|
|
|
|
isFromDownload
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-12-16 23:45:20 +00:00
|
|
|
fun removeLastWatched(parentId: Int?) {
|
2021-08-25 15:28:25 +00:00
|
|
|
if (parentId == null) return
|
|
|
|
removeKey("$currentAccount/$RESULT_RESUME_WATCHING", parentId.toString())
|
|
|
|
}
|
|
|
|
|
2021-12-16 23:45:20 +00:00
|
|
|
fun getLastWatched(id: Int?): VideoDownloadHelper.ResumeWatching? {
|
2021-08-25 15:28:25 +00:00
|
|
|
if (id == null) return null
|
|
|
|
return getKey(
|
|
|
|
"$currentAccount/$RESULT_RESUME_WATCHING",
|
|
|
|
id.toString(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-12-16 23:45:20 +00:00
|
|
|
fun setBookmarkedData(id: Int?, data: BookmarkedData) {
|
2021-07-30 14:09:57 +00:00
|
|
|
if (id == null) return
|
2021-07-30 23:41:54 +00:00
|
|
|
setKey("$currentAccount/$RESULT_WATCH_STATE_DATA", id.toString(), data)
|
2021-07-30 14:09:57 +00:00
|
|
|
}
|
|
|
|
|
2021-12-16 23:45:20 +00:00
|
|
|
fun getBookmarkedData(id: Int?): BookmarkedData? {
|
2021-07-30 14:09:57 +00:00
|
|
|
if (id == null) return null
|
2021-07-30 23:41:54 +00:00
|
|
|
return getKey("$currentAccount/$RESULT_WATCH_STATE_DATA", id.toString())
|
2021-07-30 14:09:57 +00:00
|
|
|
}
|
|
|
|
|
2021-12-16 23:45:20 +00:00
|
|
|
fun setViewPos(id: Int?, pos: Long, dur: Long) {
|
2021-06-15 23:25:58 +00:00
|
|
|
if (id == null) return
|
2021-12-24 15:35:44 +00:00
|
|
|
if (dur < 30_000) return // too short
|
2021-06-15 16:07:20 +00:00
|
|
|
setKey("$currentAccount/$VIDEO_POS_DUR", id.toString(), PosDur(pos, dur))
|
|
|
|
}
|
|
|
|
|
2022-01-07 19:27:25 +00:00
|
|
|
fun getViewPos(id: Int?): PosDur? {
|
2022-02-05 22:21:45 +00:00
|
|
|
if (id == null) return null
|
2021-06-15 23:25:58 +00:00
|
|
|
return getKey("$currentAccount/$VIDEO_POS_DUR", id.toString(), null)
|
|
|
|
}
|
|
|
|
|
2021-12-16 23:45:20 +00:00
|
|
|
fun getDub(id: Int): DubStatus {
|
|
|
|
return DubStatus.values()[getKey("$currentAccount/$RESULT_DUB", id.toString()) ?: 0]
|
|
|
|
}
|
|
|
|
|
|
|
|
fun setDub(id: Int, status: DubStatus) {
|
|
|
|
setKey("$currentAccount/$RESULT_DUB", id.toString(), status.ordinal)
|
|
|
|
}
|
|
|
|
|
|
|
|
fun setResultWatchState(id: Int?, status: Int) {
|
2021-06-15 23:25:58 +00:00
|
|
|
if (id == null) return
|
2021-07-30 23:41:54 +00:00
|
|
|
val folder = "$currentAccount/$RESULT_WATCH_STATE"
|
|
|
|
if (status == WatchType.NONE.internalId) {
|
|
|
|
removeKey(folder, id.toString())
|
|
|
|
removeKey("$currentAccount/$RESULT_WATCH_STATE_DATA", id.toString())
|
|
|
|
} else {
|
|
|
|
setKey(folder, id.toString(), status)
|
|
|
|
}
|
2021-06-15 23:25:58 +00:00
|
|
|
}
|
|
|
|
|
2021-12-16 23:45:20 +00:00
|
|
|
fun getResultWatchState(id: Int): WatchType {
|
2022-02-05 22:21:45 +00:00
|
|
|
return WatchType.fromInternalId(
|
|
|
|
getKey<Int>(
|
|
|
|
"$currentAccount/$RESULT_WATCH_STATE",
|
|
|
|
id.toString(),
|
|
|
|
null
|
|
|
|
)
|
|
|
|
)
|
2021-06-15 16:07:20 +00:00
|
|
|
}
|
2021-06-26 22:15:19 +00:00
|
|
|
|
2021-12-16 23:45:20 +00:00
|
|
|
fun getResultSeason(id: Int): Int {
|
|
|
|
return getKey("$currentAccount/$RESULT_SEASON", id.toString()) ?: -1
|
2021-06-26 22:15:19 +00:00
|
|
|
}
|
2021-07-30 14:09:57 +00:00
|
|
|
|
2021-12-16 23:45:20 +00:00
|
|
|
fun setResultSeason(id: Int, value: Int?) {
|
2021-12-13 18:41:33 +00:00
|
|
|
setKey("$currentAccount/$RESULT_SEASON", id.toString(), value)
|
|
|
|
}
|
|
|
|
|
2021-12-16 23:45:20 +00:00
|
|
|
fun addSync(id: Int, idPrefix: String, url: String) {
|
2021-12-13 18:41:33 +00:00
|
|
|
setKey("${idPrefix}_sync", id.toString(), url)
|
|
|
|
}
|
|
|
|
|
2021-12-16 23:45:20 +00:00
|
|
|
fun getSync(id: Int, idPrefixes: List<String>): List<String?> {
|
2021-12-13 18:41:33 +00:00
|
|
|
return idPrefixes.map { idPrefix ->
|
|
|
|
getKey("${idPrefix}_sync", id.toString())
|
|
|
|
}
|
2021-06-26 22:15:19 +00:00
|
|
|
}
|
2021-06-15 16:07:20 +00:00
|
|
|
}
|