mirror of
https://github.com/recloudstream/cloudstream.git
synced 2026-07-13 00:13:17 +00:00
Compare commits
37 commits
fix-repo-d
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b3c938ba7 |
||
|
|
15632b864a |
||
|
|
505722c1b5 |
||
|
|
70469f55db |
||
|
|
11792dd65c |
||
|
|
4a79ca1c9f |
||
|
|
3496e5f8d2 |
||
|
|
5cd1cb3433 |
||
|
|
f03b18ff95 |
||
|
|
0af9b7f569 |
||
|
|
1463cf40cd |
||
|
|
3e17b3a5a0 |
||
|
|
8c3dbdc5b6 |
||
|
|
5b0c5afeba |
||
|
|
e75b5e64a7 |
||
|
|
c36652d265 |
||
|
|
b681d443e4 |
||
|
|
189162fac9 |
||
|
|
3796406e63 |
||
|
|
8bdc599996 |
||
|
|
0e3191e28b |
||
|
|
11202d269d |
||
|
|
07b4d2d576 |
||
|
|
66afc3b1ee |
||
|
|
e428d422eb |
||
|
|
59eaed0c82 |
||
|
|
694c9c4413 |
||
|
|
480d48bea4 |
||
|
|
a123c5935c |
||
|
|
5cb939df69 |
||
|
|
60cfeba735 |
||
|
|
678726e9ee |
||
|
|
894a18a831 |
||
|
|
5bae7d35d8 |
||
|
|
94ce0d4385 |
||
|
|
55b5017068 |
||
|
|
e8c005dfeb |
73 changed files with 13833 additions and 1340 deletions
5
.github/workflows/pull_request.yml
vendored
5
.github/workflows/pull_request.yml
vendored
|
|
@ -26,6 +26,11 @@ jobs:
|
||||||
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
|
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
|
||||||
cache-read-only: false
|
cache-read-only: false
|
||||||
|
|
||||||
|
- name: Ensure binary compatibility
|
||||||
|
# This is to ensure that your code is backwards compatible.
|
||||||
|
# If this fails you need to add a @Prerelease annotation to new code.
|
||||||
|
run: ./gradlew library:checkKotlinAbi
|
||||||
|
|
||||||
- name: Run Gradle
|
- name: Run Gradle
|
||||||
run: ./gradlew assemblePrereleaseDebug lint check
|
run: ./gradlew assemblePrereleaseDebug lint check
|
||||||
|
|
||||||
|
|
|
||||||
21
COMPOSE.md
Normal file
21
COMPOSE.md
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
# Migration guide to Compose
|
||||||
|
|
||||||
|
### 1. MVI instead of MVVM
|
||||||
|
|
||||||
|
The current design of CloudStream loosely uses the MVVM architecture.
|
||||||
|
|
||||||
|
This means that the UI invokes the viewmodel with function calls, and it responds with LiveData fields that are observed. While this has worked, it generates a lot of boilerplate and has created some friction.
|
||||||
|
|
||||||
|
To make it easier to work with Compose, the new architecture will be based on MVI. In short this means that the viewmodel exposes a singular immutable class that is observed, and receives all UI events with a singular event that is a sealed class. All the UI should be able to be recreated based on this singular state class, and all interactions should be able to be replayed using only the event callback.
|
||||||
|
|
||||||
|
For a more detailed overview, see: https://www.youtube.com/watch?v=b2z1jvD4VMQ
|
||||||
|
|
||||||
|
This is part of the effort to make CloudStream cross platform, as it allows us to decouple UI and logic.
|
||||||
|
|
||||||
|
### 2. KMP-compatible libraries
|
||||||
|
|
||||||
|
We plan to leverage Kotlin's KMP project to compile our code to different architectures. However, this requires us to only use KMP-compatible libraries, no Java. Therefore any pull requests must ensure that they use KMP-compatible libraries only.
|
||||||
|
|
||||||
|
### 3. UI Changes
|
||||||
|
|
||||||
|
While migrating to the new compose UI, you also have the opportunity to change the UI. However, this should only be to freshen up the UI, not completely redesign it. It is also important to stress that this process should not lose any features of the old UI, and be very conservative with adding new features.
|
||||||
|
|
@ -1,157 +0,0 @@
|
||||||
package com.lagradost.cloudstream3.utils.serializers
|
|
||||||
|
|
||||||
import android.net.Uri
|
|
||||||
import com.lagradost.cloudstream3.utils.AppUtils.parseJson
|
|
||||||
import com.lagradost.cloudstream3.utils.AppUtils.toJson
|
|
||||||
import kotlinx.serialization.ExperimentalSerializationApi
|
|
||||||
import kotlinx.serialization.KeepGeneratedSerializer
|
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
import org.junit.Assert.assertEquals
|
|
||||||
import org.junit.Assert.assertFalse
|
|
||||||
import org.junit.Assert.assertNull
|
|
||||||
import org.junit.Assert.assertTrue
|
|
||||||
import org.junit.Test
|
|
||||||
|
|
||||||
@OptIn(ExperimentalSerializationApi::class)
|
|
||||||
@KeepGeneratedSerializer
|
|
||||||
@Serializable(with = NonEmptyData.Serializer::class)
|
|
||||||
data class NonEmptyData(
|
|
||||||
val title: String = "",
|
|
||||||
val tags: List<String> = emptyList(),
|
|
||||||
val meta: Map<String, String> = emptyMap(),
|
|
||||||
val name: String = "hello",
|
|
||||||
) {
|
|
||||||
object Serializer : NonEmptySerializer<NonEmptyData>(NonEmptyData.generatedSerializer())
|
|
||||||
}
|
|
||||||
|
|
||||||
@OptIn(ExperimentalSerializationApi::class)
|
|
||||||
@KeepGeneratedSerializer
|
|
||||||
@Serializable(with = WriteOnlyData.Serializer::class)
|
|
||||||
data class WriteOnlyData(
|
|
||||||
val fieldA: String = "",
|
|
||||||
val fieldB: String = "",
|
|
||||||
) {
|
|
||||||
object Serializer : WriteOnlySerializer<WriteOnlyData>(
|
|
||||||
WriteOnlyData.generatedSerializer(),
|
|
||||||
setOf("fieldB"),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@OptIn(ExperimentalSerializationApi::class)
|
|
||||||
@KeepGeneratedSerializer
|
|
||||||
@Serializable(with = MultiWriteOnly.Serializer::class)
|
|
||||||
data class MultiWriteOnly(
|
|
||||||
val fieldA: String = "",
|
|
||||||
val fieldB: String = "",
|
|
||||||
val fieldC: String = "",
|
|
||||||
) {
|
|
||||||
object Serializer : WriteOnlySerializer<MultiWriteOnly>(
|
|
||||||
MultiWriteOnly.generatedSerializer(),
|
|
||||||
setOf("fieldB", "fieldC"),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
data class UriData(
|
|
||||||
@Serializable(with = UriSerializer::class)
|
|
||||||
val uri: Uri = Uri.EMPTY,
|
|
||||||
)
|
|
||||||
|
|
||||||
class SerializerTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun nonEmptySerializerOmitsEmptyStrings() {
|
|
||||||
val data = NonEmptyData(title = "", name = "hello")
|
|
||||||
val result = data.toJson()
|
|
||||||
assertFalse(result.contains("title"))
|
|
||||||
assertTrue(result.contains("name"))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun nonEmptySerializerOmitsEmptyLists() {
|
|
||||||
val data = NonEmptyData(tags = emptyList(), name = "hello")
|
|
||||||
val result = data.toJson()
|
|
||||||
assertFalse(result.contains("tags"))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun nonEmptySerializerOmitsEmptyMaps() {
|
|
||||||
val data = NonEmptyData(meta = emptyMap(), name = "hello")
|
|
||||||
val result = data.toJson()
|
|
||||||
assertFalse(result.contains("meta"))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun nonEmptySerializerKeepsNonEmptyFields() {
|
|
||||||
val data = NonEmptyData(title = "hello", tags = listOf("a"), meta = mapOf("k" to "v"))
|
|
||||||
val result = data.toJson()
|
|
||||||
assertTrue(result.contains("title"))
|
|
||||||
assertTrue(result.contains("tags"))
|
|
||||||
assertTrue(result.contains("meta"))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun nonEmptySerializerDoesNotAffectDeserialization() {
|
|
||||||
val input = """{"title":"hello","tags":["a"],"meta":{"k":"v"},"name":"world"}"""
|
|
||||||
val result = parseJson<NonEmptyData>(input)
|
|
||||||
assertEquals("hello", result.title)
|
|
||||||
assertEquals(listOf("a"), result.tags)
|
|
||||||
assertEquals(mapOf("k" to "v"), result.meta)
|
|
||||||
assertEquals("world", result.name)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun writeOnlySerializerOmitsFieldOnSerialize() {
|
|
||||||
val data = WriteOnlyData(fieldA = "hello", fieldB = "secret")
|
|
||||||
val result = data.toJson()
|
|
||||||
assertTrue(result.contains("fieldA"))
|
|
||||||
assertFalse(result.contains("fieldB"))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun writeOnlySerializerDeserializesNormally() {
|
|
||||||
val input = """{"fieldA":"hello","fieldB":"secret"}"""
|
|
||||||
val result = parseJson<WriteOnlyData>(input)
|
|
||||||
assertEquals("hello", result.fieldA)
|
|
||||||
assertEquals("secret", result.fieldB)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun writeOnlySerializerDeserializesMissingAsDefault() {
|
|
||||||
val input = """{"fieldA":"hello"}"""
|
|
||||||
val result = parseJson<WriteOnlyData>(input)
|
|
||||||
assertEquals("hello", result.fieldA)
|
|
||||||
assertEquals("", result.fieldB)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun writeOnlySerializerHandlesMultipleKeys() {
|
|
||||||
val data = MultiWriteOnly(fieldA = "hello", fieldB = "secret1", fieldC = "secret2")
|
|
||||||
val result = data.toJson()
|
|
||||||
assertTrue(result.contains("fieldA"))
|
|
||||||
assertFalse(result.contains("fieldB"))
|
|
||||||
assertFalse(result.contains("fieldC"))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun uriSerializerSerializesUriToString() {
|
|
||||||
val data = UriData(uri = Uri.parse("https://example.com/path?query=1"))
|
|
||||||
val result = data.toJson()
|
|
||||||
assertTrue(result.contains("https://example.com/path?query=1"))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun uriSerializerDeserializesStringToUri() {
|
|
||||||
val input = """{"uri":"https://example.com/path?query=1"}"""
|
|
||||||
val result = parseJson<UriData>(input)
|
|
||||||
assertEquals(Uri.parse("https://example.com/path?query=1"), result.uri)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun uriSerializerRoundtripsCorrectly() {
|
|
||||||
val data = UriData(uri = Uri.parse("https://example.com/path?query=1"))
|
|
||||||
val encoded = data.toJson()
|
|
||||||
val decoded = parseJson<UriData>(encoded)
|
|
||||||
assertEquals(data.uri, decoded.uri)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
package com.lagradost.cloudstream3.utils.serializers
|
||||||
|
|
||||||
|
import android.net.Uri
|
||||||
|
import com.lagradost.cloudstream3.utils.AppUtils.parseJson
|
||||||
|
import com.lagradost.cloudstream3.utils.AppUtils.toJson
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class UriData(
|
||||||
|
@Serializable(with = UriSerializer::class)
|
||||||
|
@SerialName("uri") val uri: Uri = Uri.EMPTY,
|
||||||
|
)
|
||||||
|
|
||||||
|
class UriSerializerTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun uriSerializerSerializesUriToString() {
|
||||||
|
val data = UriData(uri = Uri.parse("https://example.com/path?query=1"))
|
||||||
|
val result = data.toJson()
|
||||||
|
assertTrue(result.contains("https://example.com/path?query=1"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun uriSerializerDeserializesStringToUri() {
|
||||||
|
val input = """{"uri":"https://example.com/path?query=1"}"""
|
||||||
|
val result = parseJson<UriData>(input)
|
||||||
|
assertEquals(Uri.parse("https://example.com/path?query=1"), result.uri)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun uriSerializerRoundtripsCorrectly() {
|
||||||
|
val data = UriData(uri = Uri.parse("https://example.com/path?query=1"))
|
||||||
|
val encoded = data.toJson()
|
||||||
|
val decoded = parseJson<UriData>(encoded)
|
||||||
|
assertEquals(data.uri, decoded.uri)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -171,6 +171,7 @@ import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.navigate
|
import com.lagradost.cloudstream3.utils.UIHelper.navigate
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.requestRW
|
import com.lagradost.cloudstream3.utils.UIHelper.requestRW
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.setNavigationBarColorCompat
|
import com.lagradost.cloudstream3.utils.UIHelper.setNavigationBarColorCompat
|
||||||
|
import com.lagradost.cloudstream3.utils.UIHelper.showProgress
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.toPx
|
import com.lagradost.cloudstream3.utils.UIHelper.toPx
|
||||||
import com.lagradost.cloudstream3.utils.USER_PROVIDER_API
|
import com.lagradost.cloudstream3.utils.USER_PROVIDER_API
|
||||||
import com.lagradost.cloudstream3.utils.USER_SELECTED_HOMEPAGE_API
|
import com.lagradost.cloudstream3.utils.USER_SELECTED_HOMEPAGE_API
|
||||||
|
|
@ -1214,7 +1215,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener, BiometricCa
|
||||||
// backup when we update the app, I don't trust myself to not boot lock users, might want to make this a setting?
|
// backup when we update the app, I don't trust myself to not boot lock users, might want to make this a setting?
|
||||||
safe {
|
safe {
|
||||||
val appVer = BuildConfig.VERSION_NAME
|
val appVer = BuildConfig.VERSION_NAME
|
||||||
val lastAppAutoBackup: String = getKey("VERSION_NAME") ?: ""
|
val lastAppAutoBackup: String = getKey<String>("VERSION_NAME") ?: ""
|
||||||
if (appVer != lastAppAutoBackup) {
|
if (appVer != lastAppAutoBackup) {
|
||||||
setKey("VERSION_NAME", BuildConfig.VERSION_NAME)
|
setKey("VERSION_NAME", BuildConfig.VERSION_NAME)
|
||||||
if (lastAppAutoBackup.isEmpty()) return@safe
|
if (lastAppAutoBackup.isEmpty()) return@safe
|
||||||
|
|
@ -1428,8 +1429,9 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener, BiometricCa
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
resultviewPreviewBookmark.isEnabled = false
|
resultviewPreviewBookmark.isEnabled = false
|
||||||
resultviewPreviewBookmark.setIconResource(R.drawable.ic_baseline_bookmark_border_24)
|
resultviewPreviewBookmark.showProgress()
|
||||||
resultviewPreviewBookmark.setText(R.string.loading)
|
//resultviewPreviewBookmark.setIconResource(R.drawable.ic_baseline_bookmark_border_24)
|
||||||
|
//resultviewPreviewBookmark.setText(R.string.loading)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2016,7 +2018,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener, BiometricCa
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (getKey(HAS_DONE_SETUP_KEY, false) != true) {
|
if (getKey<Boolean>(HAS_DONE_SETUP_KEY, false) != true) {
|
||||||
navController.navigate(R.id.navigation_setup_language)
|
navController.navigate(R.id.navigation_setup_language)
|
||||||
// If no plugins bring up extensions screen
|
// If no plugins bring up extensions screen
|
||||||
} else if (PluginManager.getPluginsOnline().isEmpty()
|
} else if (PluginManager.getPluginsOnline().isEmpty()
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ open class VlcPackage: OpenInAppAction(
|
||||||
intent.putExtra("secure_uri", true)
|
intent.putExtra("secure_uri", true)
|
||||||
intent.putExtra("title", video.name)
|
intent.putExtra("title", video.name)
|
||||||
|
|
||||||
val subsLang = getKey(SUBTITLE_AUTO_SELECT_KEY) ?: "en"
|
val subsLang = getKey<String>(SUBTITLE_AUTO_SELECT_KEY) ?: "en"
|
||||||
result.subs.firstOrNull {
|
result.subs.firstOrNull {
|
||||||
subsLang == it.languageCode
|
subsLang == it.languageCode
|
||||||
}?.let {
|
}?.let {
|
||||||
|
|
@ -74,4 +74,4 @@ open class VlcPackage: OpenInAppAction(
|
||||||
Log.d("VLC", "Position: $position, Duration: $duration")
|
Log.d("VLC", "Position: $position, Duration: $duration")
|
||||||
updateDurationAndPosition(position, duration)
|
updateDurationAndPosition(position, duration)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ fun Requests.initClient(context: Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Only use ignoreSSL if you know what you are doing*/
|
/** Only use ignoreSSL if you know what you are doing*/
|
||||||
@Prerelease
|
|
||||||
fun Requests.initClient(context: Context, ignoreSSL: Boolean = false) {
|
fun Requests.initClient(context: Context, ignoreSSL: Boolean = false) {
|
||||||
this.baseClient = buildDefaultClient(context, ignoreSSL)
|
this.baseClient = buildDefaultClient(context, ignoreSSL)
|
||||||
}
|
}
|
||||||
|
|
@ -34,7 +33,6 @@ fun buildDefaultClient(context: Context): OkHttpClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Only use ignoreSSL if you know what you are doing*/
|
/** Only use ignoreSSL if you know what you are doing*/
|
||||||
@Prerelease
|
|
||||||
fun buildDefaultClient(context: Context, ignoreSSL: Boolean = false): OkHttpClient {
|
fun buildDefaultClient(context: Context, ignoreSSL: Boolean = false): OkHttpClient {
|
||||||
safe { Security.insertProviderAt(Conscrypt.newProvider(), 1) }
|
safe { Security.insertProviderAt(Conscrypt.newProvider(), 1) }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -176,11 +176,11 @@ object PluginManager {
|
||||||
|
|
||||||
|
|
||||||
fun getPluginsOnline(): Array<PluginData> {
|
fun getPluginsOnline(): Array<PluginData> {
|
||||||
return getKey(PLUGINS_KEY) ?: emptyArray()
|
return getKey<Array<PluginData>>(PLUGINS_KEY) ?: emptyArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getPluginsLocal(): Array<PluginData> {
|
fun getPluginsLocal(): Array<PluginData> {
|
||||||
return getKey(PLUGINS_KEY_LOCAL) ?: emptyArray()
|
return getKey<Array<PluginData>>(PLUGINS_KEY_LOCAL) ?: emptyArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
private val CLOUD_STREAM_FOLDER =
|
private val CLOUD_STREAM_FOLDER =
|
||||||
|
|
@ -512,6 +512,9 @@ object PluginManager {
|
||||||
val res = dir.mkdirs()
|
val res = dir.mkdirs()
|
||||||
if (!res) {
|
if (!res) {
|
||||||
Log.w(TAG, "Failed to create local directories")
|
Log.w(TAG, "Failed to create local directories")
|
||||||
|
// We have tried to load local plugins, but exit early.
|
||||||
|
// This needs to be true to prevent the downloader waiting for plugins.
|
||||||
|
loadedLocalPlugins = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,7 @@ data class PluginWrapper(
|
||||||
object RepositoryManager {
|
object RepositoryManager {
|
||||||
const val ONLINE_PLUGINS_FOLDER = "Extensions"
|
const val ONLINE_PLUGINS_FOLDER = "Extensions"
|
||||||
val PREBUILT_REPOSITORIES: Array<RepositoryData> by lazy {
|
val PREBUILT_REPOSITORIES: Array<RepositoryData> by lazy {
|
||||||
getKey("PREBUILT_REPOSITORIES") ?: emptyArray()
|
getKey<Array<RepositoryData>>("PREBUILT_REPOSITORIES") ?: emptyArray()
|
||||||
}
|
}
|
||||||
private val GH_REGEX =
|
private val GH_REGEX =
|
||||||
Regex("^https://raw.githubusercontent.com/([A-Za-z0-9-]+)/([A-Za-z0-9_.-]+)/(.*)$")
|
Regex("^https://raw.githubusercontent.com/([A-Za-z0-9-]+)/([A-Za-z0-9_.-]+)/(.*)$")
|
||||||
|
|
@ -141,12 +141,18 @@ object RepositoryManager {
|
||||||
}
|
}
|
||||||
} else if (fixedUrl.matches("^[a-zA-Z0-9!_-]+$".toRegex())) {
|
} else if (fixedUrl.matches("^[a-zA-Z0-9!_-]+$".toRegex())) {
|
||||||
safeAsync {
|
safeAsync {
|
||||||
app.get("https://cutt.ly/${fixedUrl}", allowRedirects = false).let { it2 ->
|
if (fixedUrl.startsWith("!")) {
|
||||||
it2.headers["Location"]?.let { url ->
|
val response = app.get("https://py.md/${fixedUrl.removePrefix("!")}", allowRedirects = false)
|
||||||
if (url.startsWith("https://cutt.ly/404")) return@safeAsync null
|
val url = response.headers["Location"] ?: return@safeAsync null
|
||||||
if (url.removeSuffix("/") == "https://cutt.ly") return@safeAsync null
|
if (url.startsWith("https://py.md/404")) return@safeAsync null
|
||||||
return@safeAsync url
|
if (url.removeSuffix("/") == "https://py.md") return@safeAsync null
|
||||||
}
|
return@safeAsync url
|
||||||
|
} else {
|
||||||
|
val response = app.get("https://cutt.ly/${fixedUrl}", allowRedirects = false)
|
||||||
|
val url = response.headers["Location"] ?: return@safeAsync null
|
||||||
|
if (url.startsWith("https://cutt.ly/404")) return@safeAsync null
|
||||||
|
if (url.removeSuffix("/") == "https://cutt.ly") return@safeAsync null
|
||||||
|
return@safeAsync url
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else null
|
} else null
|
||||||
|
|
@ -234,7 +240,7 @@ object RepositoryManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getRepositories(): Array<RepositoryData> {
|
fun getRepositories(): Array<RepositoryData> {
|
||||||
return getKey(REPOSITORIES_KEY) ?: emptyArray()
|
return getKey<Array<RepositoryData>>(REPOSITORIES_KEY) ?: emptyArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't want to read before we write in another thread
|
// Don't want to read before we write in another thread
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,8 @@ abstract class AccountManager {
|
||||||
SubtitleRepo(openSubtitlesApi),
|
SubtitleRepo(openSubtitlesApi),
|
||||||
SubtitleRepo(addic7ed),
|
SubtitleRepo(addic7ed),
|
||||||
SubtitleRepo(subDlApi),
|
SubtitleRepo(subDlApi),
|
||||||
PlainAuthRepo(animeSkipApi)
|
PlainAuthRepo(animeSkipApi),
|
||||||
|
SubtitleRepo(subSourceApi)
|
||||||
)
|
)
|
||||||
|
|
||||||
fun updateAccountIds() {
|
fun updateAccountIds() {
|
||||||
|
|
@ -120,7 +121,8 @@ abstract class AccountManager {
|
||||||
val subtitleProviders = arrayOf(
|
val subtitleProviders = arrayOf(
|
||||||
SubtitleRepo(openSubtitlesApi),
|
SubtitleRepo(openSubtitlesApi),
|
||||||
SubtitleRepo(addic7ed),
|
SubtitleRepo(addic7ed),
|
||||||
SubtitleRepo(subDlApi)
|
SubtitleRepo(subDlApi),
|
||||||
|
SubtitleRepo(subSourceApi)
|
||||||
)
|
)
|
||||||
val syncApis = arrayOf(
|
val syncApis = arrayOf(
|
||||||
SyncRepo(malApi),
|
SyncRepo(malApi),
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package com.lagradost.cloudstream3.syncproviders
|
||||||
|
|
||||||
import androidx.annotation.WorkerThread
|
import androidx.annotation.WorkerThread
|
||||||
import com.lagradost.cloudstream3.APIHolder.unixTime
|
import com.lagradost.cloudstream3.APIHolder.unixTime
|
||||||
import com.lagradost.cloudstream3.ErrorLoadingException
|
|
||||||
import com.lagradost.cloudstream3.subtitles.AbstractSubtitleEntities.SubtitleEntity
|
import com.lagradost.cloudstream3.subtitles.AbstractSubtitleEntities.SubtitleEntity
|
||||||
import com.lagradost.cloudstream3.subtitles.AbstractSubtitleEntities.SubtitleSearch
|
import com.lagradost.cloudstream3.subtitles.AbstractSubtitleEntities.SubtitleSearch
|
||||||
import com.lagradost.cloudstream3.subtitles.SubtitleResource
|
import com.lagradost.cloudstream3.subtitles.SubtitleResource
|
||||||
|
|
@ -14,7 +13,8 @@ class SubtitleRepo(override val api: SubtitleAPI) : AuthRepo(api) {
|
||||||
data class SavedSearchResponse(
|
data class SavedSearchResponse(
|
||||||
val unixTime: Long,
|
val unixTime: Long,
|
||||||
val response: List<SubtitleEntity>,
|
val response: List<SubtitleEntity>,
|
||||||
val query: SubtitleSearch
|
val query: SubtitleSearch,
|
||||||
|
val idPrefix: String,
|
||||||
)
|
)
|
||||||
|
|
||||||
data class SavedResourceResponse(
|
data class SavedResourceResponse(
|
||||||
|
|
@ -66,7 +66,7 @@ class SubtitleRepo(override val api: SubtitleAPI) : AuthRepo(api) {
|
||||||
var found: List<SubtitleEntity>? = null
|
var found: List<SubtitleEntity>? = null
|
||||||
for (item in searchCache) {
|
for (item in searchCache) {
|
||||||
// 120 min save
|
// 120 min save
|
||||||
if (item.query == query && (unixTime - item.unixTime) < 60 * 120) {
|
if (item.idPrefix == idPrefix && item.query == query && (unixTime - item.unixTime) < 60 * 120) {
|
||||||
found = item.response
|
found = item.response
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
@ -79,7 +79,7 @@ class SubtitleRepo(override val api: SubtitleAPI) : AuthRepo(api) {
|
||||||
|
|
||||||
// only cache valid return values
|
// only cache valid return values
|
||||||
if (returnValue.isNotEmpty()) {
|
if (returnValue.isNotEmpty()) {
|
||||||
val add = SavedSearchResponse(unixTime, returnValue, query)
|
val add = SavedSearchResponse(unixTime, returnValue, query, idPrefix)
|
||||||
searchCache.withLock {
|
searchCache.withLock {
|
||||||
if (searchCache.size > CACHE_SIZE) {
|
if (searchCache.size > CACHE_SIZE) {
|
||||||
searchCache[searchCacheIndex] = add // rolling cache
|
searchCache[searchCacheIndex] = add // rolling cache
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -7,11 +7,10 @@ import com.lagradost.cloudstream3.subtitles.AbstractSubtitleEntities
|
||||||
import com.lagradost.cloudstream3.subtitles.SubtitleResource
|
import com.lagradost.cloudstream3.subtitles.SubtitleResource
|
||||||
import com.lagradost.cloudstream3.syncproviders.AuthData
|
import com.lagradost.cloudstream3.syncproviders.AuthData
|
||||||
import com.lagradost.cloudstream3.syncproviders.SubtitleAPI
|
import com.lagradost.cloudstream3.syncproviders.SubtitleAPI
|
||||||
import com.lagradost.cloudstream3.utils.AppUtils.parseJson
|
|
||||||
import com.lagradost.cloudstream3.utils.AppUtils.toJson
|
|
||||||
import com.lagradost.cloudstream3.utils.SubtitleHelper
|
import com.lagradost.cloudstream3.utils.SubtitleHelper
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
class SubSourceApi : SubtitleAPI() {
|
class SubSourceApi : SubtitleAPI() {
|
||||||
override val name = "SubSource"
|
override val name = "SubSource"
|
||||||
|
|
@ -20,77 +19,70 @@ class SubSourceApi : SubtitleAPI() {
|
||||||
override val requiresLogin = false
|
override val requiresLogin = false
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val APIURL = "https://api.subsource.net/api"
|
const val APIURL = "https://api.subsource.net/v1"
|
||||||
const val DOWNLOADENDPOINT = "https://api.subsource.net/api/downloadSub"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun search(
|
override suspend fun search(
|
||||||
auth: AuthData?,
|
auth: AuthData?,
|
||||||
query: AbstractSubtitleEntities.SubtitleSearch
|
query: AbstractSubtitleEntities.SubtitleSearch
|
||||||
): List<AbstractSubtitleEntities.SubtitleEntity>? {
|
): List<AbstractSubtitleEntities.SubtitleEntity>? {
|
||||||
|
|
||||||
//Only supports Imdb Id search for now
|
//Only supports Imdb Id search for now
|
||||||
if (query.imdbId == null) return null
|
if (query.imdbId == null) return null
|
||||||
val queryLang = SubtitleHelper.fromTagToEnglishLanguageName(query.lang)
|
val queryLang = SubtitleHelper.fromTagToEnglishLanguageName(query.lang)
|
||||||
val type = if ((query.seasonNumber ?: 0) > 0) TvType.TvSeries else TvType.Movie
|
val type = if ((query.seasonNumber ?: 0) > 0) TvType.TvSeries else TvType.Movie
|
||||||
|
|
||||||
val searchRes = app.post(
|
val searchResponse = app.post(
|
||||||
url = "$APIURL/searchMovie",
|
url = "$APIURL/movie/search",
|
||||||
data = mapOf(
|
json = mapOf(
|
||||||
"query" to query.imdbId!!
|
"includeSeasons" to false,
|
||||||
)
|
"limit" to 15,
|
||||||
).parsedSafe<ApiSearch>() ?: return null
|
"query" to query.imdbId!!,
|
||||||
|
"signal" to "{}"
|
||||||
|
),
|
||||||
|
cacheTime = 120,
|
||||||
|
cacheUnit = TimeUnit.MINUTES,
|
||||||
|
).parsedSafe<SearchRoot>() ?: return null
|
||||||
|
|
||||||
val postData = if (type == TvType.TvSeries) {
|
val firstResult = searchResponse.results.firstOrNull() ?: return null
|
||||||
mapOf(
|
|
||||||
"langs" to "[]",
|
val apiResponse = app.get(
|
||||||
"movieName" to searchRes.found.first().linkName,
|
url = "$APIURL${firstResult.link.replace("series", "subtitles")}",
|
||||||
"season" to "season-${query.seasonNumber}"
|
cacheTime = 120,
|
||||||
)
|
cacheUnit = TimeUnit.MINUTES,
|
||||||
} else {
|
).parsedSafe<ItemRoot>() ?: return null
|
||||||
mapOf(
|
|
||||||
"langs" to "[]",
|
val filteredSubtitles = apiResponse.subtitles.filter { sub ->
|
||||||
"movieName" to searchRes.found.first().linkName,
|
sub.releaseType != "trailer" &&
|
||||||
)
|
sub.language.equals(queryLang, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
val getMovieRes = app.post(
|
// api doesn't has episode number or lang filtering
|
||||||
url = "$APIURL/getMovie",
|
val subtitles = if (type == TvType.Movie) {
|
||||||
data = postData
|
filteredSubtitles
|
||||||
).parsedSafe<ApiResponse>().let {
|
} else {
|
||||||
// api doesn't has episode number or lang filtering
|
val shouldContain = String.format(
|
||||||
if (type == TvType.Movie) {
|
null,
|
||||||
it?.subs?.filter { sub ->
|
"E%02d",
|
||||||
sub.lang == queryLang
|
query.epNumber
|
||||||
}
|
)
|
||||||
} else {
|
filteredSubtitles.filter { sub ->
|
||||||
it?.subs?.filter { sub ->
|
sub.releaseInfo.contains(
|
||||||
sub.releaseName!!.contains(
|
shouldContain
|
||||||
String.format(
|
)
|
||||||
null,
|
|
||||||
"E%02d",
|
|
||||||
query.epNumber
|
|
||||||
)
|
|
||||||
) && sub.lang == queryLang
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} ?: return null
|
}
|
||||||
|
|
||||||
return getMovieRes.map { subtitle ->
|
return subtitles.map { subtitle ->
|
||||||
AbstractSubtitleEntities.SubtitleEntity(
|
AbstractSubtitleEntities.SubtitleEntity(
|
||||||
idPrefix = this.idPrefix,
|
idPrefix = this.idPrefix,
|
||||||
name = subtitle.releaseName!!,
|
name = subtitle.releaseInfo,
|
||||||
lang = subtitle.lang!!,
|
lang = subtitle.language,
|
||||||
data = SubData(
|
data = subtitle.link,
|
||||||
movie = subtitle.linkName!!,
|
|
||||||
lang = subtitle.lang,
|
|
||||||
id = subtitle.subId.toString(),
|
|
||||||
).toJson(),
|
|
||||||
type = type,
|
type = type,
|
||||||
source = this.name,
|
source = this.name,
|
||||||
epNumber = query.epNumber,
|
epNumber = query.epNumber,
|
||||||
seasonNumber = query.seasonNumber,
|
seasonNumber = query.seasonNumber,
|
||||||
isHearingImpaired = subtitle.hi == 1,
|
isHearingImpaired = subtitle.hearingImpaired == 1,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -99,79 +91,114 @@ class SubSourceApi : SubtitleAPI() {
|
||||||
auth: AuthData?,
|
auth: AuthData?,
|
||||||
subtitle: AbstractSubtitleEntities.SubtitleEntity
|
subtitle: AbstractSubtitleEntities.SubtitleEntity
|
||||||
) {
|
) {
|
||||||
val parsedSub = parseJson<SubData>(subtitle.data)
|
val data = app.get("$APIURL/subtitle/${subtitle.data}")
|
||||||
|
.parsedSafe<DownloadRoot>()
|
||||||
val subRes = app.post(
|
?: return
|
||||||
url = "$APIURL/getSub",
|
|
||||||
data = mapOf(
|
|
||||||
"movie" to parsedSub.movie,
|
|
||||||
"lang" to subtitle.lang,
|
|
||||||
"id" to parsedSub.id
|
|
||||||
)
|
|
||||||
).parsedSafe<SubTitleLink>() ?: return
|
|
||||||
|
|
||||||
this.addZipUrl(
|
this.addZipUrl(
|
||||||
"$DOWNLOADENDPOINT/${subRes.sub.downloadToken}"
|
"$APIURL/subtitle/download/${data.subtitle.downloadToken}"
|
||||||
) { name, _ ->
|
) { name, _ ->
|
||||||
name
|
name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class ApiSearch(
|
data class SearchRoot(
|
||||||
@JsonProperty("success") @SerialName("success") val success: Boolean,
|
@JsonProperty("success") @SerialName("success") var success: Boolean? = null,
|
||||||
@JsonProperty("found") @SerialName("found") val found: List<Found>,
|
@JsonProperty("results") @SerialName("results") var results: ArrayList<Results> = arrayListOf(),
|
||||||
|
@JsonProperty("users") @SerialName("users") var users: ArrayList<Users> = arrayListOf()
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Found(
|
data class Users(
|
||||||
@JsonProperty("id") @SerialName("id") val id: Long,
|
|
||||||
@JsonProperty("title") @SerialName("title") val title: String,
|
@JsonProperty("id") @SerialName("id") var id: Int? = null,
|
||||||
@JsonProperty("seasons") @SerialName("seasons") val seasons: Long,
|
@JsonProperty("displayname") @SerialName("displayname") var displayname: String? = null,
|
||||||
@JsonProperty("type") @SerialName("type") val type: String,
|
@JsonProperty("avatar") @SerialName("avatar") var avatar: String? = null,
|
||||||
@JsonProperty("releaseYear") @SerialName("releaseYear") val releaseYear: Long,
|
@JsonProperty("badges") @SerialName("badges") var badges: ArrayList<String> = arrayListOf()
|
||||||
@JsonProperty("linkName") @SerialName("linkName") val linkName: String,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class ApiResponse(
|
data class Results(
|
||||||
@JsonProperty("success") @SerialName("success") val success: Boolean,
|
@JsonProperty("id") @SerialName("id") var id: Int? = null,
|
||||||
@JsonProperty("movie") @SerialName("movie") val movie: Movie,
|
@JsonProperty("title") @SerialName("title") var title: String? = null,
|
||||||
@JsonProperty("subs") @SerialName("subs") val subs: List<Sub>,
|
@JsonProperty("type") @SerialName("type") var type: String? = null,
|
||||||
|
@JsonProperty("link") @SerialName("link") var link: String,
|
||||||
|
@JsonProperty("releaseYear") @SerialName("releaseYear") var releaseYear: Int? = null,
|
||||||
|
@JsonProperty("poster") @SerialName("poster") var poster: String? = null,
|
||||||
|
@JsonProperty("subtitleCount") @SerialName("subtitleCount") var subtitleCount: String? = null,
|
||||||
|
@JsonProperty("rating") @SerialName("rating") var rating: Double? = null,
|
||||||
|
@JsonProperty("cast") @SerialName("cast") var cast: ArrayList<String> = arrayListOf(),
|
||||||
|
@JsonProperty("genres") @SerialName("genres") var genres: ArrayList<String> = arrayListOf(),
|
||||||
|
@JsonProperty("score") @SerialName("score") var score: Double? = null
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Movie(
|
|
||||||
@JsonProperty("id") @SerialName("id") val id: Long? = null,
|
data class ItemRoot(
|
||||||
@JsonProperty("type") @SerialName("type") val type: String? = null,
|
|
||||||
@JsonProperty("year") @SerialName("year") val year: Long? = null,
|
// @SerialName("media_type" ) var mediaType : String? = null,
|
||||||
@JsonProperty("fullName") @SerialName("fullName") val fullName: String? = null,
|
@JsonProperty("subtitles") @SerialName("subtitles") var subtitles: ArrayList<Subtitles>,
|
||||||
|
//@SerialName("movie" ) var movie : Movie? = Movie()
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Sub(
|
data class Subtitles(
|
||||||
@JsonProperty("hi") @SerialName("hi") val hi: Int? = null,
|
|
||||||
@JsonProperty("fullLink") @SerialName("fullLink") val fullLink: String? = null,
|
@JsonProperty("id") @SerialName("id") var id: Int? = null,
|
||||||
@JsonProperty("linkName") @SerialName("linkName") val linkName: String? = null,
|
@JsonProperty("language") @SerialName("language") var language: String,
|
||||||
@JsonProperty("lang") @SerialName("lang") val lang: String? = null,
|
@JsonProperty("release_type") @SerialName("release_type") var releaseType: String? = null,
|
||||||
@JsonProperty("releaseName") @SerialName("releaseName") val releaseName: String? = null,
|
@JsonProperty("release_info") @SerialName("release_info") var releaseInfo: String,
|
||||||
@JsonProperty("subId") @SerialName("subId") val subId: Long? = null,
|
@JsonProperty("upload_date") @SerialName("upload_date") var uploadDate: String? = null,
|
||||||
|
@JsonProperty("hearing_impaired") @SerialName("hearing_impaired") var hearingImpaired: Int? = null,
|
||||||
|
@JsonProperty("caption") @SerialName("caption") var caption: String? = null,
|
||||||
|
@JsonProperty("rating") @SerialName("rating") var rating: String? = null,
|
||||||
|
@JsonProperty("uploader_id") @SerialName("uploader_id") var uploaderId: Int? = null,
|
||||||
|
@JsonProperty("uploader_displayname") @SerialName("uploader_displayname") var uploaderDisplayname: String? = null,
|
||||||
|
@JsonProperty("uploader_badges") @SerialName("uploader_badges") var uploaderBadges: ArrayList<String> = arrayListOf(),
|
||||||
|
@JsonProperty("link") @SerialName("link") var link: String,
|
||||||
|
@JsonProperty("production_type") @SerialName("production_type") var productionType: String? = null,
|
||||||
|
@JsonProperty("last_subtitle") @SerialName("last_subtitle") var lastSubtitle: Boolean? = null
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class SubData(
|
data class DownloadRoot(
|
||||||
@JsonProperty("movie") @SerialName("movie") val movie: String,
|
@JsonProperty("subtitle") @SerialName("subtitle") var subtitle: Subtitle,
|
||||||
@JsonProperty("lang") @SerialName("lang") val lang: String,
|
//@SerializedName("movie" ) var movie : Movie? = Movie(),
|
||||||
@JsonProperty("id") @SerialName("id") val id: String,
|
//@SerializedName("donationLinks" ) var donationLinks : DonationLinks? = DonationLinks(),
|
||||||
|
//@SerializedName("isDownloaded" ) var isDownloaded : Boolean? = null,
|
||||||
|
//@SerializedName("user_rated" ) var userRated : String? = null
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class SubTitleLink(
|
data class Subtitle(
|
||||||
@JsonProperty("sub") @SerialName("sub") val sub: SubToken,
|
|
||||||
)
|
@JsonProperty("id") @SerialName("id") var id: Int? = null,
|
||||||
|
@JsonProperty("uploaded_at") @SerialName("uploaded_at") var uploadedAt: String? = null,
|
||||||
|
@JsonProperty("language") @SerialName("language") var language: String? = null,
|
||||||
|
@JsonProperty("rating") @SerialName("rating") var rating: String? = null,
|
||||||
|
//SerialName("rates" ) var rates : Rates? = Rates(),
|
||||||
|
@JsonProperty("uploaded_by") @SerialName("uploaded_by") var uploadedBy: Int? = null,
|
||||||
|
//@SerialName("contribs" ) var contribs : ArrayList<Contribs> = arrayListOf(),
|
||||||
|
@JsonProperty("release_info") @SerialName("release_info") var releaseInfo: ArrayList<String> = arrayListOf(),
|
||||||
|
@JsonProperty("commentary") @SerialName("commentary") var commentary: String? = null,
|
||||||
|
@JsonProperty("files") @SerialName("files") var files: String? = null,
|
||||||
|
@JsonProperty("size") @SerialName("size") var size: String? = null,
|
||||||
|
@JsonProperty("downloads") @SerialName("downloads") var downloads: Int? = null,
|
||||||
|
@JsonProperty("comments") @SerialName("comments") var comments: Int? = null,
|
||||||
|
@JsonProperty("production_type") @SerialName("production_type") var productionType: String? = null,
|
||||||
|
@JsonProperty("release_type") @SerialName("release_type") var releaseType: String? = null,
|
||||||
|
@JsonProperty("episode") @SerialName("episode") var episode: String? = null,
|
||||||
|
@JsonProperty("hearing_impaired") @SerialName("hearing_impaired") var hearingImpaired: Int? = null,
|
||||||
|
@JsonProperty("foreign_parts") @SerialName("foreign_parts") var foreignParts: String? = null,
|
||||||
|
@JsonProperty("framerate") @SerialName("framerate") var framerate: String? = null,
|
||||||
|
@JsonProperty("preview") @SerialName("preview") var preview: String? = null,
|
||||||
|
@JsonProperty("user_uploaded") @SerialName("user_uploaded") var userUploaded: Boolean? = null,
|
||||||
|
@JsonProperty("download_token") @SerialName("download_token") var downloadToken: String
|
||||||
|
|
||||||
@Serializable
|
|
||||||
data class SubToken(
|
|
||||||
@JsonProperty("downloadToken") @SerialName("downloadToken") val downloadToken: String,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,10 @@ import com.lagradost.cloudstream3.utils.DataStoreHelper
|
||||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.getDefaultAccount
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.getDefaultAccount
|
||||||
import com.lagradost.cloudstream3.utils.ImageLoader.loadImage
|
import com.lagradost.cloudstream3.utils.ImageLoader.loadImage
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
|
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
|
||||||
|
import com.lagradost.cloudstream3.utils.UIHelper.hideProgress
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.navigate
|
import com.lagradost.cloudstream3.utils.UIHelper.navigate
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.showInputMethod
|
import com.lagradost.cloudstream3.utils.UIHelper.showInputMethod
|
||||||
|
import com.lagradost.cloudstream3.utils.UIHelper.showProgress
|
||||||
|
|
||||||
object AccountHelper {
|
object AccountHelper {
|
||||||
fun showAccountEditDialog(
|
fun showAccountEditDialog(
|
||||||
|
|
@ -164,7 +166,7 @@ object AccountHelper {
|
||||||
|
|
||||||
canSetPin = true
|
canSetPin = true
|
||||||
|
|
||||||
binding.editProfilePhotoButton.setOnClickListener({
|
binding.editProfilePhotoButton.setOnClickListener {
|
||||||
val bottomSheetDialog = BottomSheetDialog(context)
|
val bottomSheetDialog = BottomSheetDialog(context)
|
||||||
val sheetBinding = BottomInputDialogBinding.inflate(LayoutInflater.from(context))
|
val sheetBinding = BottomInputDialogBinding.inflate(LayoutInflater.from(context))
|
||||||
bottomSheetDialog.setContentView(sheetBinding.root)
|
bottomSheetDialog.setContentView(sheetBinding.root)
|
||||||
|
|
@ -174,42 +176,46 @@ object AccountHelper {
|
||||||
text1.text = context.getString(R.string.edit_profile_image_title)
|
text1.text = context.getString(R.string.edit_profile_image_title)
|
||||||
nginxTextInput.hint = context.getString(R.string.edit_profile_image_hint)
|
nginxTextInput.hint = context.getString(R.string.edit_profile_image_hint)
|
||||||
|
|
||||||
applyBtt.setOnClickListener({
|
applyBtt.setOnClickListener {
|
||||||
val url = sheetBinding.nginxTextInput.text.toString()
|
val url = sheetBinding.nginxTextInput.text.toString()
|
||||||
if (url.isNotEmpty()) {
|
if (url.isEmpty()) {
|
||||||
val imageLoader = ImageLoader(context)
|
|
||||||
val request = ImageRequest.Builder(context)
|
|
||||||
.data(url)
|
|
||||||
.allowHardware(false)
|
|
||||||
.listener(
|
|
||||||
onSuccess = { _, _ ->
|
|
||||||
currentEditAccount = currentEditAccount.copy(customImage = url)
|
|
||||||
binding.accountImage.loadImage(url)
|
|
||||||
showToast(
|
|
||||||
R.string.edit_profile_image_success,
|
|
||||||
Toast.LENGTH_SHORT
|
|
||||||
)
|
|
||||||
bottomSheetDialog.dismiss()
|
|
||||||
},
|
|
||||||
onError = { _, _ ->
|
|
||||||
showToast(
|
|
||||||
R.string.edit_profile_image_error_invalid,
|
|
||||||
Toast.LENGTH_SHORT
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.build()
|
|
||||||
imageLoader.enqueue(request)
|
|
||||||
} else {
|
|
||||||
showToast(R.string.edit_profile_image_error_empty, Toast.LENGTH_SHORT)
|
showToast(R.string.edit_profile_image_error_empty, Toast.LENGTH_SHORT)
|
||||||
|
return@setOnClickListener
|
||||||
}
|
}
|
||||||
|
applyBtt.showProgress()
|
||||||
|
val imageLoader = ImageLoader(context)
|
||||||
|
val request = ImageRequest.Builder(context)
|
||||||
|
.data(url)
|
||||||
|
.allowHardware(false)
|
||||||
|
.listener(
|
||||||
|
onSuccess = { _, _ ->
|
||||||
|
currentEditAccount = currentEditAccount.copy(customImage = url)
|
||||||
|
binding.accountImage.loadImage(url)
|
||||||
|
showToast(
|
||||||
|
R.string.edit_profile_image_success,
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
)
|
||||||
|
bottomSheetDialog.dismissSafe()
|
||||||
|
},
|
||||||
|
onError = { _, _ ->
|
||||||
|
showToast(
|
||||||
|
R.string.edit_profile_image_error_invalid,
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
)
|
||||||
|
applyBtt.hideProgress()
|
||||||
|
},
|
||||||
|
onCancel = {
|
||||||
|
applyBtt.hideProgress()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.build()
|
||||||
|
imageLoader.enqueue(request)
|
||||||
|
}
|
||||||
|
sheetBinding.cancelBtt.setOnClickListener {
|
||||||
bottomSheetDialog.dismissSafe()
|
bottomSheetDialog.dismissSafe()
|
||||||
})
|
}
|
||||||
sheetBinding.cancelBtt.setOnClickListener({
|
|
||||||
bottomSheetDialog.dismissSafe()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showPinInputDialog(
|
fun showPinInputDialog(
|
||||||
|
|
|
||||||
|
|
@ -719,7 +719,7 @@ class CS3IPlayer : IPlayer {
|
||||||
**/
|
**/
|
||||||
var preferredAudioTrackLanguage: String? = null
|
var preferredAudioTrackLanguage: String? = null
|
||||||
get() {
|
get() {
|
||||||
return field ?: getKey(
|
return field ?: getKey<String>(
|
||||||
"$currentAccount/$PREFERRED_AUDIO_LANGUAGE_KEY",
|
"$currentAccount/$PREFERRED_AUDIO_LANGUAGE_KEY",
|
||||||
field
|
field
|
||||||
)?.also {
|
)?.also {
|
||||||
|
|
|
||||||
|
|
@ -1202,6 +1202,10 @@ open class FullScreenPlayer : AbstractPlayerFragment<FragmentPlayerBinding>(
|
||||||
}
|
}
|
||||||
|
|
||||||
skipChapterButton.setOnClickListener {
|
skipChapterButton.setOnClickListener {
|
||||||
|
// Switch focus for a better UX, as otherwise it is reset to a random button like "back button"
|
||||||
|
if(skipChapterButton.hasFocus()) {
|
||||||
|
playerPausePlay.requestFocus()
|
||||||
|
}
|
||||||
player.handleEvent(CSPlayerEvent.SkipCurrentChapter)
|
player.handleEvent(CSPlayerEvent.SkipCurrentChapter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -117,8 +117,10 @@ import com.lagradost.cloudstream3.utils.UIHelper.clipboardHelper
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute
|
import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
|
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.fixSystemBarsPadding
|
import com.lagradost.cloudstream3.utils.UIHelper.fixSystemBarsPadding
|
||||||
|
import com.lagradost.cloudstream3.utils.UIHelper.hideProgress
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.hideSystemUI
|
import com.lagradost.cloudstream3.utils.UIHelper.hideSystemUI
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.popCurrentPage
|
import com.lagradost.cloudstream3.utils.UIHelper.popCurrentPage
|
||||||
|
import com.lagradost.cloudstream3.utils.UIHelper.showProgress
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.toPx
|
import com.lagradost.cloudstream3.utils.UIHelper.toPx
|
||||||
import com.lagradost.cloudstream3.utils.downloader.DownloadUtils.getImageBitmapFromUrl
|
import com.lagradost.cloudstream3.utils.downloader.DownloadUtils.getImageBitmapFromUrl
|
||||||
import com.lagradost.cloudstream3.utils.setText
|
import com.lagradost.cloudstream3.utils.setText
|
||||||
|
|
@ -507,7 +509,8 @@ class GeneratorPlayer : FullScreenPlayer() {
|
||||||
|
|
||||||
showDownloadProgress(DownloadEvent(0, 0, 0, null))
|
showDownloadProgress(DownloadEvent(0, 0, 0, null))
|
||||||
|
|
||||||
uiReset()
|
// uiReset() // Removed due to UX
|
||||||
|
|
||||||
currentSelectedLink = link
|
currentSelectedLink = link
|
||||||
// setEpisodes(viewModel.getAllMeta() ?: emptyList())
|
// setEpisodes(viewModel.getAllMeta() ?: emptyList())
|
||||||
setPlayerDimen(null)
|
setPlayerDimen(null)
|
||||||
|
|
@ -790,47 +793,58 @@ class GeneratorPlayer : FullScreenPlayer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.applyBtt.setOnClickListener {
|
binding.applyBtt.setOnClickListener {
|
||||||
currentSubtitle?.let { currentSubtitle ->
|
val currentSubtitle = currentSubtitle
|
||||||
providers.firstOrNull { it.idPrefix == currentSubtitle.idPrefix }?.let { api ->
|
if (currentSubtitle == null) {
|
||||||
ioSafe {
|
dialog.dismissSafe()
|
||||||
when (val apiResource =
|
return@setOnClickListener
|
||||||
Resource.fromResult(api.resource(currentSubtitle))) {
|
}
|
||||||
is Resource.Success -> {
|
|
||||||
val subtitles = apiResource.value.getSubtitles().map { resource ->
|
|
||||||
SubtitleData(
|
|
||||||
originalName = resource.name ?: getName(
|
|
||||||
currentSubtitle,
|
|
||||||
true
|
|
||||||
),
|
|
||||||
nameSuffix = "",
|
|
||||||
url = resource.url,
|
|
||||||
origin = resource.origin,
|
|
||||||
mimeType = resource.url.toSubtitleMimeType(),
|
|
||||||
headers = currentSubtitle.headers,
|
|
||||||
languageCode = currentSubtitle.lang
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if (subtitles.isEmpty()) {
|
|
||||||
showToast(R.string.no_subtitles)
|
|
||||||
return@ioSafe
|
|
||||||
}
|
|
||||||
runOnMainThread {
|
|
||||||
addAndSelectSubtitles(*subtitles.toTypedArray())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
is Resource.Failure -> {
|
val api = providers.firstOrNull { it.idPrefix == currentSubtitle.idPrefix }
|
||||||
showToast(apiResource.errorString)
|
if (api == null) {
|
||||||
}
|
dialog.dismissSafe()
|
||||||
|
return@setOnClickListener
|
||||||
|
}
|
||||||
|
|
||||||
is Resource.Loading -> {
|
binding.applyBtt.showProgress()
|
||||||
// not possible
|
ioSafe {
|
||||||
}
|
val apiResource =
|
||||||
|
Resource.fromResult(api.resource(currentSubtitle))
|
||||||
|
binding.applyBtt.hideProgress()
|
||||||
|
when (apiResource) {
|
||||||
|
is Resource.Success -> {
|
||||||
|
val subtitles = apiResource.value.getSubtitles().map { resource ->
|
||||||
|
SubtitleData(
|
||||||
|
originalName = resource.name ?: getName(
|
||||||
|
currentSubtitle,
|
||||||
|
true
|
||||||
|
),
|
||||||
|
nameSuffix = "",
|
||||||
|
url = resource.url,
|
||||||
|
origin = resource.origin,
|
||||||
|
mimeType = resource.url.toSubtitleMimeType(),
|
||||||
|
headers = currentSubtitle.headers,
|
||||||
|
languageCode = currentSubtitle.lang
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
if (subtitles.isEmpty()) {
|
||||||
|
showToast(R.string.no_subtitles)
|
||||||
|
return@ioSafe
|
||||||
|
}
|
||||||
|
dialog.dismissSafe()
|
||||||
|
runOnMainThread {
|
||||||
|
addAndSelectSubtitles(*subtitles.toTypedArray())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
is Resource.Failure -> {
|
||||||
|
showToast(apiResource.errorString)
|
||||||
|
}
|
||||||
|
|
||||||
|
is Resource.Loading -> {
|
||||||
|
// not possible
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dialog.dismissSafe()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dialog.setOnDismissListener {
|
dialog.setOnDismissListener {
|
||||||
|
|
@ -1698,8 +1712,10 @@ class GeneratorPlayer : FullScreenPlayer() {
|
||||||
if (settingsManager.getBoolean(
|
if (settingsManager.getBoolean(
|
||||||
ctx.getString(R.string.episode_sync_enabled_key), true
|
ctx.getString(R.string.episode_sync_enabled_key), true
|
||||||
)
|
)
|
||||||
) maxEpisodeSet = meta.episode
|
) {
|
||||||
sync.modifyMaxEpisode(meta.totalEpisodeIndex ?: meta.episode)
|
maxEpisodeSet = meta.episode
|
||||||
|
sync.modifyMaxEpisode(meta.totalEpisodeIndex ?: meta.episode)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,14 @@ import androidx.annotation.OptIn
|
||||||
import androidx.media3.common.MimeTypes
|
import androidx.media3.common.MimeTypes
|
||||||
import androidx.media3.common.util.UnstableApi
|
import androidx.media3.common.util.UnstableApi
|
||||||
import androidx.media3.ui.SubtitleView
|
import androidx.media3.ui.SubtitleView
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||||
import com.lagradost.cloudstream3.SubtitleFile
|
import com.lagradost.cloudstream3.SubtitleFile
|
||||||
import com.lagradost.cloudstream3.ui.subtitles.SaveCaptionStyle
|
import com.lagradost.cloudstream3.ui.subtitles.SaveCaptionStyle
|
||||||
import com.lagradost.cloudstream3.ui.subtitles.SubtitlesFragment.Companion.setSubtitleViewStyle
|
import com.lagradost.cloudstream3.ui.subtitles.SubtitlesFragment.Companion.setSubtitleViewStyle
|
||||||
import com.lagradost.cloudstream3.utils.SubtitleHelper.fromLanguageToTagIETF
|
import com.lagradost.cloudstream3.utils.SubtitleHelper.fromLanguageToTagIETF
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.toPx
|
import com.lagradost.cloudstream3.utils.UIHelper.toPx
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
enum class SubtitleStatus {
|
enum class SubtitleStatus {
|
||||||
IS_ACTIVE,
|
IS_ACTIVE,
|
||||||
|
|
@ -32,17 +35,19 @@ enum class SubtitleOrigin {
|
||||||
* @param url Url for the subtitle, when EMBEDDED_IN_VIDEO this variable is used as the real backend id
|
* @param url Url for the subtitle, when EMBEDDED_IN_VIDEO this variable is used as the real backend id
|
||||||
* @param headers if empty it will use the base onlineDataSource headers else only the specified headers
|
* @param headers if empty it will use the base onlineDataSource headers else only the specified headers
|
||||||
* @param languageCode usually, tags such as "en", "es-mx", or "zh-hant-TW". But it could be something like "English 4"
|
* @param languageCode usually, tags such as "en", "es-mx", or "zh-hant-TW". But it could be something like "English 4"
|
||||||
* */
|
*/
|
||||||
|
@Serializable
|
||||||
data class SubtitleData(
|
data class SubtitleData(
|
||||||
val originalName: String,
|
@SerialName("originalName") val originalName: String,
|
||||||
val nameSuffix: String,
|
@SerialName("nameSuffix") val nameSuffix: String,
|
||||||
val url: String,
|
@SerialName("url") val url: String,
|
||||||
val origin: SubtitleOrigin,
|
@SerialName("origin") val origin: SubtitleOrigin,
|
||||||
val mimeType: String,
|
@SerialName("mimeType") val mimeType: String,
|
||||||
val headers: Map<String, String>,
|
@SerialName("headers") val headers: Map<String, String>,
|
||||||
val languageCode: String?,
|
@SerialName("languageCode") val languageCode: String?,
|
||||||
) {
|
) {
|
||||||
/** Internal ID for exoplayer, unique for each link*/
|
/** Internal ID for media3, unique for each link. */
|
||||||
|
@JsonIgnore
|
||||||
fun getId(): String {
|
fun getId(): String {
|
||||||
return if (origin == SubtitleOrigin.EMBEDDED_IN_VIDEO) url
|
return if (origin == SubtitleOrigin.EMBEDDED_IN_VIDEO) url
|
||||||
else "$url|$name"
|
else "$url|$name"
|
||||||
|
|
@ -54,22 +59,22 @@ data class SubtitleData(
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Tries hard to figure out a valid IETF tag based on language code and name. Will return null if not found. */
|
/** Tries hard to figure out a valid IETF tag based on language code and name. Will return null if not found. */
|
||||||
|
@JsonIgnore
|
||||||
fun getIETF_tag(): String? {
|
fun getIETF_tag(): String? {
|
||||||
return fromLanguageToTagIETF(this.languageCode) ?: fromLanguageToTagIETF(this.originalName, halfMatch = true)
|
return fromLanguageToTagIETF(this.languageCode) ?: fromLanguageToTagIETF(this.originalName, halfMatch = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
val name = "$originalName $nameSuffix"
|
@SerialName("name") val name = "$originalName $nameSuffix"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the URL, but tries to fix it if it is malformed.
|
* Gets the URL, but tries to fix it if it is malformed.
|
||||||
*/
|
*/
|
||||||
|
@JsonIgnore
|
||||||
fun getFixedUrl(): String {
|
fun getFixedUrl(): String {
|
||||||
// Some extensions fail to include the protocol, this helps with that.
|
// Some extensions fail to include the protocol, this helps with that.
|
||||||
val fixedSubUrl = if (this.url.startsWith("//")) {
|
val fixedSubUrl = if (this.url.startsWith("//")) {
|
||||||
"https:${this.url}"
|
"https:${this.url}"
|
||||||
} else {
|
} else this.url
|
||||||
this.url
|
|
||||||
}
|
|
||||||
return fixedSubUrl
|
return fixedSubUrl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -142,4 +147,4 @@ class PlayerSubtitleHelper {
|
||||||
setSubStyle(it)
|
setSubStyle(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@ import com.lagradost.cloudstream3.mvvm.logError
|
||||||
import com.lagradost.cloudstream3.utils.ExtractorLink
|
import com.lagradost.cloudstream3.utils.ExtractorLink
|
||||||
import com.lagradost.cloudstream3.utils.ExtractorLinkType
|
import com.lagradost.cloudstream3.utils.ExtractorLinkType
|
||||||
import com.lagradost.cloudstream3.utils.newExtractorLink
|
import com.lagradost.cloudstream3.utils.newExtractorLink
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
import torrServer.TorrServer
|
import torrServer.TorrServer
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.net.ConnectException
|
import java.net.ConnectException
|
||||||
|
|
@ -32,14 +34,14 @@ object Torrent {
|
||||||
|
|
||||||
/** Returns true if the server is up */
|
/** Returns true if the server is up */
|
||||||
private suspend fun echo(): Boolean {
|
private suspend fun echo(): Boolean {
|
||||||
if(TORRENT_SERVER_URL.isEmpty()) {
|
if (TORRENT_SERVER_URL.isEmpty()) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return try {
|
return try {
|
||||||
app.get(
|
app.get(
|
||||||
"$TORRENT_SERVER_URL/echo",
|
"$TORRENT_SERVER_URL/echo",
|
||||||
).text.isNotEmpty()
|
).text.isNotEmpty()
|
||||||
} catch (e: ConnectException) {
|
} catch (_: ConnectException) {
|
||||||
// `Failed to connect to /127.0.0.1:8090` if the server is down
|
// `Failed to connect to /127.0.0.1:8090` if the server is down
|
||||||
false
|
false
|
||||||
} catch (t: Throwable) {
|
} catch (t: Throwable) {
|
||||||
|
|
@ -52,7 +54,7 @@ object Torrent {
|
||||||
/** Gracefully shutdown the server.
|
/** Gracefully shutdown the server.
|
||||||
* should not be used because I am unable to start it again, and the stopTorrentServer() crashes the app */
|
* should not be used because I am unable to start it again, and the stopTorrentServer() crashes the app */
|
||||||
suspend fun shutdown(): Boolean {
|
suspend fun shutdown(): Boolean {
|
||||||
if(TORRENT_SERVER_URL.isEmpty()) {
|
if (TORRENT_SERVER_URL.isEmpty()) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return try {
|
return try {
|
||||||
|
|
@ -68,7 +70,7 @@ object Torrent {
|
||||||
/** Lists all torrents by the server */
|
/** Lists all torrents by the server */
|
||||||
@Throws
|
@Throws
|
||||||
private suspend fun list(): Array<TorrentStatus> {
|
private suspend fun list(): Array<TorrentStatus> {
|
||||||
if(TORRENT_SERVER_URL.isEmpty()) {
|
if (TORRENT_SERVER_URL.isEmpty()) {
|
||||||
throw ErrorLoadingException("Not initialized")
|
throw ErrorLoadingException("Not initialized")
|
||||||
}
|
}
|
||||||
return app.post(
|
return app.post(
|
||||||
|
|
@ -83,7 +85,7 @@ object Torrent {
|
||||||
|
|
||||||
/** Drops a single torrent, (I think) this means closing the stream. Returns returns if it is successful */
|
/** Drops a single torrent, (I think) this means closing the stream. Returns returns if it is successful */
|
||||||
private suspend fun drop(hash: String): Boolean {
|
private suspend fun drop(hash: String): Boolean {
|
||||||
if(TORRENT_SERVER_URL.isEmpty()) {
|
if (TORRENT_SERVER_URL.isEmpty()) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return try {
|
return try {
|
||||||
|
|
@ -104,7 +106,7 @@ object Torrent {
|
||||||
|
|
||||||
/** Removes a single torrent from the server registry */
|
/** Removes a single torrent from the server registry */
|
||||||
private suspend fun rem(hash: String): Boolean {
|
private suspend fun rem(hash: String): Boolean {
|
||||||
if(TORRENT_SERVER_URL.isEmpty()) {
|
if (TORRENT_SERVER_URL.isEmpty()) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return try {
|
return try {
|
||||||
|
|
@ -126,7 +128,7 @@ object Torrent {
|
||||||
|
|
||||||
/** Removes all torrents from the server, and returns if it is successful */
|
/** Removes all torrents from the server, and returns if it is successful */
|
||||||
suspend fun clearAll(): Boolean {
|
suspend fun clearAll(): Boolean {
|
||||||
if(TORRENT_SERVER_URL.isEmpty()) {
|
if (TORRENT_SERVER_URL.isEmpty()) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return try {
|
return try {
|
||||||
|
|
@ -164,10 +166,8 @@ object Torrent {
|
||||||
/** Gets all the metadata of a torrent, will throw if that hash does not exists
|
/** Gets all the metadata of a torrent, will throw if that hash does not exists
|
||||||
* https://github.com/Diegopyl1209/torrentserver-aniyomi/blob/c18f58e51b6738f053261bc863177078aa9c1c98/web/api/torrents.go#L126 */
|
* https://github.com/Diegopyl1209/torrentserver-aniyomi/blob/c18f58e51b6738f053261bc863177078aa9c1c98/web/api/torrents.go#L126 */
|
||||||
@Throws
|
@Throws
|
||||||
suspend fun get(
|
suspend fun get(hash: String): TorrentStatus {
|
||||||
hash: String,
|
if (TORRENT_SERVER_URL.isEmpty()) {
|
||||||
): TorrentStatus {
|
|
||||||
if(TORRENT_SERVER_URL.isEmpty()) {
|
|
||||||
throw ErrorLoadingException("Not initialized")
|
throw ErrorLoadingException("Not initialized")
|
||||||
}
|
}
|
||||||
return app.post(
|
return app.post(
|
||||||
|
|
@ -184,7 +184,7 @@ object Torrent {
|
||||||
/** Adds a torrent to the server, this is needed for us to get the hash for further modification, as well as start streaming it*/
|
/** Adds a torrent to the server, this is needed for us to get the hash for further modification, as well as start streaming it*/
|
||||||
@Throws
|
@Throws
|
||||||
private suspend fun add(url: String): TorrentStatus {
|
private suspend fun add(url: String): TorrentStatus {
|
||||||
if(TORRENT_SERVER_URL.isEmpty()) {
|
if (TORRENT_SERVER_URL.isEmpty()) {
|
||||||
throw ErrorLoadingException("Not initialized")
|
throw ErrorLoadingException("Not initialized")
|
||||||
}
|
}
|
||||||
return app.post(
|
return app.post(
|
||||||
|
|
@ -204,7 +204,7 @@ object Torrent {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
val port = TorrServer.startTorrentServer(dir, 0)
|
val port = TorrServer.startTorrentServer(dir, 0)
|
||||||
if(port < 0) {
|
if (port < 0) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
TORRENT_SERVER_URL = "http://127.0.0.1:$port"
|
TORRENT_SERVER_URL = "http://127.0.0.1:$port"
|
||||||
|
|
@ -278,94 +278,55 @@ object Torrent {
|
||||||
|
|
||||||
// https://github.com/Diegopyl1209/torrentserver-aniyomi/blob/c18f58e51b6738f053261bc863177078aa9c1c98/web/api/torrents.go#L18
|
// https://github.com/Diegopyl1209/torrentserver-aniyomi/blob/c18f58e51b6738f053261bc863177078aa9c1c98/web/api/torrents.go#L18
|
||||||
// https://github.com/Diegopyl1209/torrentserver-aniyomi/blob/main/web/api/route.go#L7
|
// https://github.com/Diegopyl1209/torrentserver-aniyomi/blob/main/web/api/route.go#L7
|
||||||
|
@Serializable
|
||||||
data class TorrentRequest(
|
data class TorrentRequest(
|
||||||
@JsonProperty("action")
|
@JsonProperty("action") @SerialName("action") val action: String,
|
||||||
val action: String,
|
@JsonProperty("hash") @SerialName("hash") val hash: String = "",
|
||||||
@JsonProperty("hash")
|
@JsonProperty("link") @SerialName("link") val link: String = "",
|
||||||
val hash: String = "",
|
@JsonProperty("title") @SerialName("title") val title: String = "",
|
||||||
@JsonProperty("link")
|
@JsonProperty("poster") @SerialName("poster") val poster: String = "",
|
||||||
val link: String = "",
|
@JsonProperty("data") @SerialName("data") val data: String = "",
|
||||||
@JsonProperty("title")
|
@JsonProperty("save_to_db") @SerialName("save_to_db") val saveToDB: Boolean = false,
|
||||||
val title: String = "",
|
|
||||||
@JsonProperty("poster")
|
|
||||||
val poster: String = "",
|
|
||||||
@JsonProperty("data")
|
|
||||||
val data: String = "",
|
|
||||||
@JsonProperty("save_to_db")
|
|
||||||
val saveToDB: Boolean = false,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// https://github.com/Diegopyl1209/torrentserver-aniyomi/blob/c18f58e51b6738f053261bc863177078aa9c1c98/torr/state/state.go#L33
|
// https://github.com/Diegopyl1209/torrentserver-aniyomi/blob/c18f58e51b6738f053261bc863177078aa9c1c98/torr/state/state.go#L33
|
||||||
// omitempty = nullable
|
// omitempty = nullable
|
||||||
|
@Serializable
|
||||||
data class TorrentStatus(
|
data class TorrentStatus(
|
||||||
@JsonProperty("title")
|
@JsonProperty("title") @SerialName("title") var title: String,
|
||||||
var title: String,
|
@JsonProperty("poster") @SerialName("poster") var poster: String,
|
||||||
@JsonProperty("poster")
|
@JsonProperty("data") @SerialName("data") var data: String?,
|
||||||
var poster: String,
|
@JsonProperty("timestamp") @SerialName("timestamp") var timestamp: Long,
|
||||||
@JsonProperty("data")
|
@JsonProperty("name") @SerialName("name") var name: String?,
|
||||||
var data: String?,
|
@JsonProperty("hash") @SerialName("hash") var hash: String?,
|
||||||
@JsonProperty("timestamp")
|
@JsonProperty("stat") @SerialName("stat") var stat: Int,
|
||||||
var timestamp: Long,
|
@JsonProperty("stat_string") @SerialName("stat_string") var statString: String,
|
||||||
@JsonProperty("name")
|
@JsonProperty("loaded_size") @SerialName("loaded_size") var loadedSize: Long?,
|
||||||
var name: String?,
|
@JsonProperty("torrent_size") @SerialName("torrent_size") var torrentSize: Long?,
|
||||||
@JsonProperty("hash")
|
@JsonProperty("preloaded_bytes") @SerialName("preloaded_bytes") var preloadedBytes: Long?,
|
||||||
var hash: String?,
|
@JsonProperty("preload_size") @SerialName("preload_size") var preloadSize: Long?,
|
||||||
@JsonProperty("stat")
|
@JsonProperty("download_speed") @SerialName("download_speed") var downloadSpeed: Double?,
|
||||||
var stat: Int,
|
@JsonProperty("upload_speed") @SerialName("upload_speed") var uploadSpeed: Double?,
|
||||||
@JsonProperty("stat_string")
|
@JsonProperty("total_peers") @SerialName("total_peers") var totalPeers: Int?,
|
||||||
var statString: String,
|
@JsonProperty("pending_peers") @SerialName("pending_peers") var pendingPeers: Int?,
|
||||||
@JsonProperty("loaded_size")
|
@JsonProperty("active_peers") @SerialName("active_peers") var activePeers: Int?,
|
||||||
var loadedSize: Long?,
|
@JsonProperty("connected_seeders") @SerialName("connected_seeders") var connectedSeeders: Int?,
|
||||||
@JsonProperty("torrent_size")
|
@JsonProperty("half_open_peers") @SerialName("half_open_peers") var halfOpenPeers: Int?,
|
||||||
var torrentSize: Long?,
|
@JsonProperty("bytes_written") @SerialName("bytes_written") var bytesWritten: Long?,
|
||||||
@JsonProperty("preloaded_bytes")
|
@JsonProperty("bytes_written_data") @SerialName("bytes_written_data") var bytesWrittenData: Long?,
|
||||||
var preloadedBytes: Long?,
|
@JsonProperty("bytes_read") @SerialName("bytes_read") var bytesRead: Long?,
|
||||||
@JsonProperty("preload_size")
|
@JsonProperty("bytes_read_data") @SerialName("bytes_read_data") var bytesReadData: Long?,
|
||||||
var preloadSize: Long?,
|
@JsonProperty("bytes_read_useful_data") @SerialName("bytes_read_useful_data") var bytesReadUsefulData: Long?,
|
||||||
@JsonProperty("download_speed")
|
@JsonProperty("chunks_written") @SerialName("chunks_written") var chunksWritten: Long?,
|
||||||
var downloadSpeed: Double?,
|
@JsonProperty("chunks_read") @SerialName("chunks_read") var chunksRead: Long?,
|
||||||
@JsonProperty("upload_speed")
|
@JsonProperty("chunks_read_useful") @SerialName("chunks_read_useful") var chunksReadUseful: Long?,
|
||||||
var uploadSpeed: Double?,
|
@JsonProperty("chunks_read_wasted") @SerialName("chunks_read_wasted") var chunksReadWasted: Long?,
|
||||||
@JsonProperty("total_peers")
|
@JsonProperty("pieces_dirtied_good") @SerialName("pieces_dirtied_good") var piecesDirtiedGood: Long?,
|
||||||
var totalPeers: Int?,
|
@JsonProperty("pieces_dirtied_bad") @SerialName("pieces_dirtied_bad") var piecesDirtiedBad: Long?,
|
||||||
@JsonProperty("pending_peers")
|
@JsonProperty("duration_seconds") @SerialName("duration_seconds") var durationSeconds: Double?,
|
||||||
var pendingPeers: Int?,
|
@JsonProperty("bit_rate") @SerialName("bit_rate") var bitRate: String?,
|
||||||
@JsonProperty("active_peers")
|
@JsonProperty("file_stats") @SerialName("file_stats") var fileStats: List<TorrentFileStat>?,
|
||||||
var activePeers: Int?,
|
@JsonProperty("trackers") @SerialName("trackers") var trackers: List<String>?,
|
||||||
@JsonProperty("connected_seeders")
|
|
||||||
var connectedSeeders: Int?,
|
|
||||||
@JsonProperty("half_open_peers")
|
|
||||||
var halfOpenPeers: Int?,
|
|
||||||
@JsonProperty("bytes_written")
|
|
||||||
var bytesWritten: Long?,
|
|
||||||
@JsonProperty("bytes_written_data")
|
|
||||||
var bytesWrittenData: Long?,
|
|
||||||
@JsonProperty("bytes_read")
|
|
||||||
var bytesRead: Long?,
|
|
||||||
@JsonProperty("bytes_read_data")
|
|
||||||
var bytesReadData: Long?,
|
|
||||||
@JsonProperty("bytes_read_useful_data")
|
|
||||||
var bytesReadUsefulData: Long?,
|
|
||||||
@JsonProperty("chunks_written")
|
|
||||||
var chunksWritten: Long?,
|
|
||||||
@JsonProperty("chunks_read")
|
|
||||||
var chunksRead: Long?,
|
|
||||||
@JsonProperty("chunks_read_useful")
|
|
||||||
var chunksReadUseful: Long?,
|
|
||||||
@JsonProperty("chunks_read_wasted")
|
|
||||||
var chunksReadWasted: Long?,
|
|
||||||
@JsonProperty("pieces_dirtied_good")
|
|
||||||
var piecesDirtiedGood: Long?,
|
|
||||||
@JsonProperty("pieces_dirtied_bad")
|
|
||||||
var piecesDirtiedBad: Long?,
|
|
||||||
@JsonProperty("duration_seconds")
|
|
||||||
var durationSeconds: Double?,
|
|
||||||
@JsonProperty("bit_rate")
|
|
||||||
var bitRate: String?,
|
|
||||||
@JsonProperty("file_stats")
|
|
||||||
var fileStats: List<TorrentFileStat>?,
|
|
||||||
@JsonProperty("trackers")
|
|
||||||
var trackers: List<String>?,
|
|
||||||
) {
|
) {
|
||||||
fun streamUrl(url: String): String {
|
fun streamUrl(url: String): String {
|
||||||
val fileName =
|
val fileName =
|
||||||
|
|
@ -381,12 +342,10 @@ object Torrent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class TorrentFileStat(
|
data class TorrentFileStat(
|
||||||
@JsonProperty("id")
|
@JsonProperty("id") @SerialName("id") val id: Int?,
|
||||||
val id: Int?,
|
@JsonProperty("path") @SerialName("path") val path: String?,
|
||||||
@JsonProperty("path")
|
@JsonProperty("length") @SerialName("length") val length: Long?,
|
||||||
val path: String?,
|
|
||||||
@JsonProperty("length")
|
|
||||||
val length: Long?,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ object QualityDataHelper {
|
||||||
|
|
||||||
fun getSourcePriority(profile: Int, name: String?): Int {
|
fun getSourcePriority(profile: Int, name: String?): Int {
|
||||||
if (name == null) return DEFAULT_SOURCE_PRIORITY
|
if (name == null) return DEFAULT_SOURCE_PRIORITY
|
||||||
return getKey(
|
return getKey<Int>(
|
||||||
"$currentAccount/$VIDEO_SOURCE_PRIORITY/$profile",
|
"$currentAccount/$VIDEO_SOURCE_PRIORITY/$profile",
|
||||||
name,
|
name,
|
||||||
DEFAULT_SOURCE_PRIORITY
|
DEFAULT_SOURCE_PRIORITY
|
||||||
|
|
@ -94,7 +94,7 @@ object QualityDataHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getQualityPriority(profile: Int, quality: Qualities): Int {
|
fun getQualityPriority(profile: Int, quality: Qualities): Int {
|
||||||
return getKey(
|
return getKey<Int>(
|
||||||
"$currentAccount/$VIDEO_QUALITY_PRIORITY/$profile",
|
"$currentAccount/$VIDEO_QUALITY_PRIORITY/$profile",
|
||||||
quality.value.toString(),
|
quality.value.toString(),
|
||||||
quality.defaultPriority
|
quality.defaultPriority
|
||||||
|
|
@ -223,4 +223,4 @@ object QualityDataHelper {
|
||||||
if (target == null) return Qualities.Unknown
|
if (target == null) return Qualities.Unknown
|
||||||
return Qualities.entries.minBy { abs(it.value - target) }
|
return Qualities.entries.minBy { abs(it.value - target) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,9 @@ import android.content.Intent
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import android.view.animation.Animation
|
||||||
|
import android.view.animation.OvershootInterpolator
|
||||||
|
import android.view.animation.ScaleAnimation
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import com.lagradost.cloudstream3.ActorData
|
import com.lagradost.cloudstream3.ActorData
|
||||||
import com.lagradost.cloudstream3.ActorRole
|
import com.lagradost.cloudstream3.ActorRole
|
||||||
|
|
@ -46,6 +49,24 @@ class ActorAdaptor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onUpdateContent(holder: ViewHolderState<Any>, item: ActorData, position: Int) {
|
||||||
|
when (val binding = holder.view) {
|
||||||
|
is CastItemBinding -> {
|
||||||
|
val anim: Animation = ScaleAnimation(
|
||||||
|
0.8f, 1f,
|
||||||
|
0.8f, 1f,
|
||||||
|
Animation.RELATIVE_TO_SELF, 0.5f,
|
||||||
|
Animation.RELATIVE_TO_SELF, 0.5f
|
||||||
|
)
|
||||||
|
anim.fillAfter = true
|
||||||
|
anim.duration = 200
|
||||||
|
anim.interpolator = OvershootInterpolator()
|
||||||
|
binding.voiceActorImageHolder2.startAnimation(anim)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.onUpdateContent(holder, item, position)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onBindContent(holder: ViewHolderState<Any>, item: ActorData, position: Int) {
|
override fun onBindContent(holder: ViewHolderState<Any>, item: ActorData, position: Int) {
|
||||||
when (val binding = holder.view) {
|
when (val binding = holder.view) {
|
||||||
is CastItemBinding -> {
|
is CastItemBinding -> {
|
||||||
|
|
@ -137,4 +158,4 @@ class ActorAdaptor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@ import com.lagradost.cloudstream3.utils.DataStoreHelper.getViewPos
|
||||||
import com.lagradost.cloudstream3.utils.Event
|
import com.lagradost.cloudstream3.utils.Event
|
||||||
import com.lagradost.cloudstream3.utils.ImageLoader.loadImage
|
import com.lagradost.cloudstream3.utils.ImageLoader.loadImage
|
||||||
import com.lagradost.cloudstream3.utils.UiImage
|
import com.lagradost.cloudstream3.utils.UiImage
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
const val START_ACTION_RESUME_LATEST = 1
|
const val START_ACTION_RESUME_LATEST = 1
|
||||||
const val START_ACTION_LOAD_EP = 2
|
const val START_ACTION_LOAD_EP = 2
|
||||||
|
|
@ -34,33 +36,32 @@ enum class VideoWatchState {
|
||||||
Watched
|
Watched
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class ResultEpisode(
|
data class ResultEpisode(
|
||||||
val headerName: String,
|
@SerialName("headerName") val headerName: String,
|
||||||
val name: String?,
|
@SerialName("name") val name: String?,
|
||||||
val poster: String?,
|
@SerialName("poster") val poster: String?,
|
||||||
val episode: Int,
|
@SerialName("episode") val episode: Int,
|
||||||
val seasonIndex: Int?, // this is the "season" index used season names
|
@SerialName("seasonIndex") val seasonIndex: Int?, // this is the "season" index used season names
|
||||||
val season: Int?, // this is the display
|
@SerialName("season") val season: Int?, // this is the display
|
||||||
val data: String,
|
@SerialName("data") val data: String,
|
||||||
val apiName: String,
|
@SerialName("apiName") val apiName: String,
|
||||||
val id: Int,
|
@SerialName("id") val id: Int,
|
||||||
val index: Int,
|
@SerialName("index") val index: Int,
|
||||||
val position: Long, // time in MS
|
@SerialName("position") val position: Long, // time in MS
|
||||||
val duration: Long, // duration in MS
|
@SerialName("duration") val duration: Long, // duration in MS
|
||||||
val score: Score?,
|
@SerialName("score") val score: Score?,
|
||||||
val description: String?,
|
@SerialName("description") val description: String?,
|
||||||
val isFiller: Boolean?,
|
@SerialName("isFiller") val isFiller: Boolean?,
|
||||||
val tvType: TvType,
|
@SerialName("tvType") val tvType: TvType,
|
||||||
val parentId: Int,
|
@SerialName("parentId") val parentId: Int,
|
||||||
/**
|
/** Conveys if the episode itself is marked as watched. */
|
||||||
* Conveys if the episode itself is marked as watched
|
@SerialName("videoWatchState") val videoWatchState: VideoWatchState,
|
||||||
**/
|
/** Sum of all previous season episode counts + episode. */
|
||||||
val videoWatchState: VideoWatchState,
|
@SerialName("totalEpisodeIndex") val totalEpisodeIndex: Int? = null,
|
||||||
/** Sum of all previous season episode counts + episode */
|
@SerialName("airDate") val airDate: Long? = null,
|
||||||
val totalEpisodeIndex: Int? = null,
|
@SerialName("runTime") val runTime: Int? = null,
|
||||||
val airDate: Long? = null,
|
@SerialName("seasonData") val seasonData: SeasonData? = null,
|
||||||
val runTime: Int? = null,
|
|
||||||
val seasonData: SeasonData? = null,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
fun ResultEpisode.getRealPosition(): Long {
|
fun ResultEpisode.getRealPosition(): Long {
|
||||||
|
|
|
||||||
|
|
@ -182,6 +182,7 @@ class SyncViewModel : ViewModel() {
|
||||||
fun publishUserData() = ioSafe {
|
fun publishUserData() = ioSafe {
|
||||||
Log.i(TAG, "publishUserData")
|
Log.i(TAG, "publishUserData")
|
||||||
val user = userData.value
|
val user = userData.value
|
||||||
|
_userDataResponse.postValue(Resource.Loading())
|
||||||
if (user is Resource.Success) {
|
if (user is Resource.Success) {
|
||||||
syncs.forEach { (prefix, id) ->
|
syncs.forEach { (prefix, id) ->
|
||||||
repos.firstOrNull { it.idPrefix == prefix }?.updateStatus(id, user.value)
|
repos.firstOrNull { it.idPrefix == prefix }?.updateStatus(id, user.value)
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,8 @@ import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialogTe
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute
|
import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
|
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard
|
import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard
|
||||||
|
import com.lagradost.cloudstream3.utils.UIHelper.hideProgress
|
||||||
|
import com.lagradost.cloudstream3.utils.UIHelper.showProgress
|
||||||
import com.lagradost.cloudstream3.utils.setText
|
import com.lagradost.cloudstream3.utils.setText
|
||||||
import com.lagradost.cloudstream3.utils.txt
|
import com.lagradost.cloudstream3.utils.txt
|
||||||
import qrcode.QRCode
|
import qrcode.QRCode
|
||||||
|
|
@ -348,6 +350,7 @@ class SettingsAccount : BasePreferenceFragmentCompat(), BiometricCallback {
|
||||||
email = if (req.email) binding.loginEmailInput.text?.toString() else null,
|
email = if (req.email) binding.loginEmailInput.text?.toString() else null,
|
||||||
server = if (req.server) binding.loginServerInput.text?.toString() else null,
|
server = if (req.server) binding.loginServerInput.text?.toString() else null,
|
||||||
)
|
)
|
||||||
|
binding.applyBtt.showProgress()
|
||||||
ioSafe {
|
ioSafe {
|
||||||
try {
|
try {
|
||||||
if (api.login(loginData)) {
|
if (api.login(loginData)) {
|
||||||
|
|
@ -377,6 +380,8 @@ class SettingsAccount : BasePreferenceFragmentCompat(), BiometricCallback {
|
||||||
api.name
|
api.name
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
} finally {
|
||||||
|
binding.applyBtt.hideProgress()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -249,7 +249,7 @@ class SettingsFragment : BaseFragment<MainSettingsBinding>(
|
||||||
|
|
||||||
val appVersion = BuildConfig.VERSION_NAME
|
val appVersion = BuildConfig.VERSION_NAME
|
||||||
val commitHash = activity?.currentCommitHash() ?: ""
|
val commitHash = activity?.currentCommitHash() ?: ""
|
||||||
val buildTimestamp = SimpleDateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG,
|
val buildTimestamp = SimpleDateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.MEDIUM,
|
||||||
Locale.getDefault()
|
Locale.getDefault()
|
||||||
).apply { timeZone = TimeZone.getTimeZone("UTC")
|
).apply { timeZone = TimeZone.getTimeZone("UTC")
|
||||||
}.format(Date(BuildConfig.BUILD_DATE)).replace("UTC", "")
|
}.format(Date(BuildConfig.BUILD_DATE)).replace("UTC", "")
|
||||||
|
|
@ -262,4 +262,4 @@ class SettingsFragment : BaseFragment<MainSettingsBinding>(
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -359,7 +359,7 @@ class SettingsGeneral : BasePreferenceFragmentCompat() {
|
||||||
} ?: emptyList()
|
} ?: emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
settingsManager.edit { putBoolean(getString(R.string.jsdelivr_proxy_key), getKey(getString(R.string.jsdelivr_proxy_key), false) ?: false) }
|
settingsManager.edit { putBoolean(getString(R.string.jsdelivr_proxy_key), getKey<Boolean>(getString(R.string.jsdelivr_proxy_key), false) ?: false) }
|
||||||
getPref(R.string.jsdelivr_proxy_key)?.setOnPreferenceChangeListener { _, newValue ->
|
getPref(R.string.jsdelivr_proxy_key)?.setOnPreferenceChangeListener { _, newValue ->
|
||||||
setKey(getString(R.string.jsdelivr_proxy_key), newValue)
|
setKey(getString(R.string.jsdelivr_proxy_key), newValue)
|
||||||
return@setOnPreferenceChangeListener true
|
return@setOnPreferenceChangeListener true
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,8 @@ import com.lagradost.cloudstream3.utils.AppContextUtils.setDefaultFocus
|
||||||
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
|
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
|
||||||
import com.lagradost.cloudstream3.utils.Coroutines.main
|
import com.lagradost.cloudstream3.utils.Coroutines.main
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
|
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
|
||||||
|
import com.lagradost.cloudstream3.utils.UIHelper.hideProgress
|
||||||
|
import com.lagradost.cloudstream3.utils.UIHelper.showProgress
|
||||||
import com.lagradost.cloudstream3.utils.setText
|
import com.lagradost.cloudstream3.utils.setText
|
||||||
|
|
||||||
class ExtensionsFragment : BaseFragment<FragmentExtensionsBinding>(
|
class ExtensionsFragment : BaseFragment<FragmentExtensionsBinding>(
|
||||||
|
|
@ -278,13 +280,18 @@ class ExtensionsFragment : BaseFragment<FragmentExtensionsBinding>(
|
||||||
binding.applyBtt.setOnClickListener secondListener@{
|
binding.applyBtt.setOnClickListener secondListener@{
|
||||||
val name = binding.repoNameInput.text?.toString()
|
val name = binding.repoNameInput.text?.toString()
|
||||||
val urlInput = binding.repoUrlInput.text?.toString()
|
val urlInput = binding.repoUrlInput.text?.toString()
|
||||||
|
if (urlInput.isNullOrEmpty()) {
|
||||||
|
showToast(R.string.error_invalid_url, Toast.LENGTH_SHORT)
|
||||||
|
return@secondListener
|
||||||
|
}
|
||||||
|
binding.applyBtt.showProgress()
|
||||||
ioSafe {
|
ioSafe {
|
||||||
val url = urlInput?.let { it1 -> RepositoryManager.parseRepoUrl(it1) }
|
try {
|
||||||
if (url.isNullOrBlank()) {
|
val url = RepositoryManager.parseRepoUrl(urlInput)
|
||||||
main {
|
if (url.isNullOrBlank()) {
|
||||||
showToast(R.string.error_invalid_data, Toast.LENGTH_SHORT)
|
showToast(R.string.error_invalid_data, Toast.LENGTH_SHORT)
|
||||||
|
return@ioSafe
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
val repository = RepositoryManager.parseRepository(url)
|
val repository = RepositoryManager.parseRepository(url)
|
||||||
|
|
||||||
// Exit if wrong repository
|
// Exit if wrong repository
|
||||||
|
|
@ -300,23 +307,28 @@ class ExtensionsFragment : BaseFragment<FragmentExtensionsBinding>(
|
||||||
extensionViewModel.loadStats()
|
extensionViewModel.loadStats()
|
||||||
extensionViewModel.loadRepositories()
|
extensionViewModel.loadRepositories()
|
||||||
|
|
||||||
|
dialog.dismissSafe(activity) // Only dismiss if the repo was added
|
||||||
|
|
||||||
val plugins = RepositoryManager.getRepoPlugins(newRepo)
|
val plugins = RepositoryManager.getRepoPlugins(newRepo)
|
||||||
if (plugins.isNullOrEmpty()) {
|
if (plugins.isNullOrEmpty()) {
|
||||||
showToast(R.string.no_plugins_found_error, Toast.LENGTH_LONG)
|
showToast(R.string.no_plugins_found_error, Toast.LENGTH_LONG)
|
||||||
} else {
|
return@ioSafe
|
||||||
this@ExtensionsFragment.activity?.addRepositoryDialog(
|
|
||||||
newRepo
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this@ExtensionsFragment.activity?.addRepositoryDialog(
|
||||||
|
newRepo
|
||||||
|
)
|
||||||
|
} finally {
|
||||||
|
binding.applyBtt.hideProgress()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dialog.dismissSafe(activity)
|
|
||||||
}
|
}
|
||||||
binding.cancelBtt.setOnClickListener {
|
binding.cancelBtt.setOnClickListener {
|
||||||
dialog.dismissSafe(activity)
|
dialog.dismissSafe(activity)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
val isTv = isLayout(TV)
|
val isTv = isLayout(TV)
|
||||||
binding.apply {
|
binding.apply {
|
||||||
addRepoButton.isGone = isTv
|
addRepoButton.isGone = isTv
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ class ChromecastSubtitlesFragment : BaseFragment<ChromecastSubtitleSettingsBindi
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getCurrentSavedStyle(): SaveChromeCaptionStyle {
|
fun getCurrentSavedStyle(): SaveChromeCaptionStyle {
|
||||||
return getKey(CHROME_SUBTITLE_KEY) ?: defaultState
|
return getKey<SaveChromeCaptionStyle>(CHROME_SUBTITLE_KEY) ?: defaultState
|
||||||
}
|
}
|
||||||
|
|
||||||
private val defaultState = SaveChromeCaptionStyle()
|
private val defaultState = SaveChromeCaptionStyle()
|
||||||
|
|
|
||||||
|
|
@ -261,7 +261,7 @@ class SubtitlesFragment : BaseDialogFragment<SubtitleSettingsBinding>(
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getCurrentSavedStyle(): SaveCaptionStyle {
|
fun getCurrentSavedStyle(): SaveCaptionStyle {
|
||||||
return cachedSubtitleStyle ?: (getKey(SUBTITLE_KEY) ?: SaveCaptionStyle(
|
return cachedSubtitleStyle ?: (getKey<SaveCaptionStyle>(SUBTITLE_KEY) ?: SaveCaptionStyle(
|
||||||
foregroundColor = getDefColor(0),
|
foregroundColor = getDefColor(0),
|
||||||
backgroundColor = getDefColor(2),
|
backgroundColor = getDefColor(2),
|
||||||
windowColor = getDefColor(3),
|
windowColor = getDefColor(3),
|
||||||
|
|
@ -293,11 +293,11 @@ class SubtitlesFragment : BaseDialogFragment<SubtitleSettingsBinding>(
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getDownloadSubsLanguageTagIETF(): List<String> {
|
fun getDownloadSubsLanguageTagIETF(): List<String> {
|
||||||
return getKey(SUBTITLE_DOWNLOAD_KEY) ?: listOf("en")
|
return getKey<List<String>>(SUBTITLE_DOWNLOAD_KEY) ?: listOf("en")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getAutoSelectLanguageTagIETF(): String {
|
fun getAutoSelectLanguageTagIETF(): String {
|
||||||
return getKey(SUBTITLE_AUTO_SELECT_KEY) ?: "en"
|
return getKey<String>(SUBTITLE_AUTO_SELECT_KEY) ?: "en"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -365,8 +365,14 @@ object AppContextUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Sort subtitles by names */
|
||||||
fun sortSubs(subs: Set<SubtitleData>): List<SubtitleData> {
|
fun sortSubs(subs: Set<SubtitleData>): List<SubtitleData> {
|
||||||
return subs.sortedBy { it.name }
|
// Be aware, sorting by "$originalName $nameSuffix" causes "a (b) 1" < "a 1",
|
||||||
|
// where "originalName then nameSuffix" preserves "a 1" < "a (b) 1", because we do not compare '(' and '1'.
|
||||||
|
return subs
|
||||||
|
.sortedWith(
|
||||||
|
compareBy { subtitle: SubtitleData -> subtitle.originalName }
|
||||||
|
.thenBy { subtitle: SubtitleData -> subtitle.nameSuffix })
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.getApiSettings(): HashSet<String> {
|
fun Context.getApiSettings(): HashSet<String> {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.lagradost.cloudstream3.utils
|
package com.lagradost.cloudstream3.utils
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty
|
import com.fasterxml.jackson.annotation.JsonProperty
|
||||||
import com.lagradost.cloudstream3.APIHolder.unixTimeMS
|
import com.lagradost.cloudstream3.APIHolder.unixTimeMS
|
||||||
import com.lagradost.cloudstream3.CloudStreamApp.Companion.context
|
import com.lagradost.cloudstream3.CloudStreamApp.Companion.context
|
||||||
|
|
@ -31,6 +32,12 @@ import com.lagradost.cloudstream3.ui.result.ResultEpisode
|
||||||
import com.lagradost.cloudstream3.ui.result.VideoWatchState
|
import com.lagradost.cloudstream3.ui.result.VideoWatchState
|
||||||
import com.lagradost.cloudstream3.utils.AppContextUtils.filterProviderByPreferredMedia
|
import com.lagradost.cloudstream3.utils.AppContextUtils.filterProviderByPreferredMedia
|
||||||
import com.lagradost.cloudstream3.utils.downloader.DownloadObjects
|
import com.lagradost.cloudstream3.utils.downloader.DownloadObjects
|
||||||
|
import com.lagradost.cloudstream3.utils.serializers.WriteOnlySerializer
|
||||||
|
import kotlinx.serialization.ExperimentalSerializationApi
|
||||||
|
import kotlinx.serialization.KeepGeneratedSerializer
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
import kotlinx.serialization.Transient
|
||||||
import java.util.Calendar
|
import java.util.Calendar
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
import java.util.GregorianCalendar
|
import java.util.GregorianCalendar
|
||||||
|
|
@ -43,17 +50,18 @@ const val RESULT_WATCH_STATE = "result_watch_state"
|
||||||
const val RESULT_WATCH_STATE_DATA = "result_watch_state_data"
|
const val RESULT_WATCH_STATE_DATA = "result_watch_state_data"
|
||||||
const val RESULT_SUBSCRIBED_STATE_DATA = "result_subscribed_state_data"
|
const val RESULT_SUBSCRIBED_STATE_DATA = "result_subscribed_state_data"
|
||||||
const val RESULT_FAVORITES_STATE_DATA = "result_favorites_state_data"
|
const val RESULT_FAVORITES_STATE_DATA = "result_favorites_state_data"
|
||||||
const val RESULT_RESUME_WATCHING = "result_resume_watching_2" // changed due to id changes
|
const val RESULT_RESUME_WATCHING = "result_resume_watching_2" // Changed due to id changes
|
||||||
const val RESULT_RESUME_WATCHING_OLD = "result_resume_watching"
|
const val RESULT_RESUME_WATCHING_OLD = "result_resume_watching"
|
||||||
const val RESULT_RESUME_WATCHING_HAS_MIGRATED = "result_resume_watching_migrated"
|
const val RESULT_RESUME_WATCHING_HAS_MIGRATED = "result_resume_watching_migrated"
|
||||||
const val RESULT_EPISODE = "result_episode"
|
const val RESULT_EPISODE = "result_episode"
|
||||||
const val RESULT_SEASON = "result_season"
|
const val RESULT_SEASON = "result_season"
|
||||||
const val RESULT_DUB = "result_dub"
|
const val RESULT_DUB = "result_dub"
|
||||||
const val KEY_RESULT_SORT = "result_sort"
|
const val KEY_RESULT_SORT = "result_sort"
|
||||||
const val USER_PINNED_PROVIDERS = "user_pinned_providers" //key for pinned user set
|
const val USER_PINNED_PROVIDERS = "user_pinned_providers" // Key for pinned user set
|
||||||
|
|
||||||
class UserPreferenceDelegate<T : Any>(
|
class UserPreferenceDelegate<T : Any>(
|
||||||
private val key: String, private val default: T //, private val klass: KClass<T>
|
private val key: String,
|
||||||
|
private val default: T,
|
||||||
) {
|
) {
|
||||||
private val klass: KClass<out T> = default::class
|
private val klass: KClass<out T> = default::class
|
||||||
private val realKey get() = "${DataStoreHelper.currentAccount}/$key"
|
private val realKey get() = "${DataStoreHelper.currentAccount}/$key"
|
||||||
|
|
@ -63,7 +71,7 @@ class UserPreferenceDelegate<T : Any>(
|
||||||
operator fun setValue(
|
operator fun setValue(
|
||||||
self: Any?,
|
self: Any?,
|
||||||
property: KProperty<*>,
|
property: KProperty<*>,
|
||||||
t: T?
|
t: T?,
|
||||||
) {
|
) {
|
||||||
if (t == null) {
|
if (t == null) {
|
||||||
removeKey(realKey)
|
removeKey(realKey)
|
||||||
|
|
@ -82,7 +90,7 @@ object DataStoreHelper {
|
||||||
R.drawable.profile_bg_pink,
|
R.drawable.profile_bg_pink,
|
||||||
R.drawable.profile_bg_purple,
|
R.drawable.profile_bg_purple,
|
||||||
R.drawable.profile_bg_red,
|
R.drawable.profile_bg_red,
|
||||||
R.drawable.profile_bg_teal
|
R.drawable.profile_bg_teal,
|
||||||
)
|
)
|
||||||
|
|
||||||
private var searchPreferenceProvidersStrings: List<String> by UserPreferenceDelegate(
|
private var searchPreferenceProvidersStrings: List<String> by UserPreferenceDelegate(
|
||||||
|
|
@ -112,16 +120,17 @@ object DataStoreHelper {
|
||||||
private var searchPreferenceTagsStrings: List<String> by UserPreferenceDelegate(
|
private var searchPreferenceTagsStrings: List<String> by UserPreferenceDelegate(
|
||||||
"search_pref_tags",
|
"search_pref_tags",
|
||||||
listOf(TvType.Movie, TvType.TvSeries).map { it.name })
|
listOf(TvType.Movie, TvType.TvSeries).map { it.name })
|
||||||
|
|
||||||
var searchPreferenceTags: List<TvType>
|
var searchPreferenceTags: List<TvType>
|
||||||
get() = deserializeTv(searchPreferenceTagsStrings)
|
get() = deserializeTv(searchPreferenceTagsStrings)
|
||||||
set(value) {
|
set(value) {
|
||||||
searchPreferenceTagsStrings = serializeTv(value)
|
searchPreferenceTagsStrings = serializeTv(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private var homePreferenceStrings: List<String> by UserPreferenceDelegate(
|
private var homePreferenceStrings: List<String> by UserPreferenceDelegate(
|
||||||
"home_pref_homepage",
|
"home_pref_homepage",
|
||||||
listOf(TvType.Movie, TvType.TvSeries).map { it.name })
|
listOf(TvType.Movie, TvType.TvSeries).map { it.name })
|
||||||
|
|
||||||
var homePreference: List<TvType>
|
var homePreference: List<TvType>
|
||||||
get() = deserializeTv(homePreferenceStrings)
|
get() = deserializeTv(homePreferenceStrings)
|
||||||
set(value) {
|
set(value) {
|
||||||
|
|
@ -132,38 +141,38 @@ object DataStoreHelper {
|
||||||
"home_bookmarked_last_list",
|
"home_bookmarked_last_list",
|
||||||
IntArray(0)
|
IntArray(0)
|
||||||
)
|
)
|
||||||
|
|
||||||
var playBackSpeed: Float by UserPreferenceDelegate("playback_speed", 1.0f)
|
var playBackSpeed: Float by UserPreferenceDelegate("playback_speed", 1.0f)
|
||||||
var resizeMode: Int by UserPreferenceDelegate("resize_mode", 0)
|
var resizeMode: Int by UserPreferenceDelegate("resize_mode", 0)
|
||||||
var librarySortingMode: Int by UserPreferenceDelegate(
|
var librarySortingMode: Int by UserPreferenceDelegate(
|
||||||
"library_sorting_mode",
|
"library_sorting_mode",
|
||||||
ListSorting.AlphabeticalA.ordinal
|
ListSorting.AlphabeticalA.ordinal
|
||||||
)
|
)
|
||||||
|
|
||||||
private var _resultsSortingMode: Int by UserPreferenceDelegate(
|
private var _resultsSortingMode: Int by UserPreferenceDelegate(
|
||||||
"results_sorting_mode",
|
"results_sorting_mode",
|
||||||
EpisodeSortType.NUMBER_ASC.ordinal
|
EpisodeSortType.NUMBER_ASC.ordinal
|
||||||
)
|
)
|
||||||
|
|
||||||
var resultsSortingMode: EpisodeSortType
|
var resultsSortingMode: EpisodeSortType
|
||||||
get() = EpisodeSortType.entries.getOrNull(_resultsSortingMode) ?: EpisodeSortType.NUMBER_ASC
|
get() = EpisodeSortType.entries.getOrNull(_resultsSortingMode) ?: EpisodeSortType.NUMBER_ASC
|
||||||
set(value) {
|
set(value) {
|
||||||
_resultsSortingMode = value.ordinal
|
_resultsSortingMode = value.ordinal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class Account(
|
data class Account(
|
||||||
@JsonProperty("keyIndex")
|
@JsonProperty("keyIndex") @SerialName("keyIndex") val keyIndex: Int,
|
||||||
val keyIndex: Int,
|
@JsonProperty("name") @SerialName("name") val name: String,
|
||||||
@JsonProperty("name")
|
@JsonProperty("customImage") @SerialName("customImage") val customImage: String? = null,
|
||||||
val name: String,
|
@JsonProperty("defaultImageIndex") @SerialName("defaultImageIndex") val defaultImageIndex: Int,
|
||||||
@JsonProperty("customImage")
|
@JsonProperty("lockPin") @SerialName("lockPin") val lockPin: String? = null,
|
||||||
val customImage: String? = null,
|
|
||||||
@JsonProperty("defaultImageIndex")
|
|
||||||
val defaultImageIndex: Int,
|
|
||||||
@JsonProperty("lockPin")
|
|
||||||
val lockPin: String? = null,
|
|
||||||
) {
|
) {
|
||||||
val image
|
@get:JsonIgnore
|
||||||
get() = customImage?.let { UiImage.Image(it) } ?: profileImages.getOrNull(
|
val image get() = customImage?.let { UiImage.Image(it) } ?:
|
||||||
defaultImageIndex
|
profileImages.getOrNull(defaultImageIndex)?.let {
|
||||||
)?.let { UiImage.Drawable(it) } ?: UiImage.Drawable(profileImages.first())
|
UiImage.Drawable(it)
|
||||||
|
} ?: UiImage.Drawable(profileImages.first())
|
||||||
}
|
}
|
||||||
|
|
||||||
const val TAG = "data_store_helper"
|
const val TAG = "data_store_helper"
|
||||||
|
|
@ -176,7 +185,7 @@ object DataStoreHelper {
|
||||||
* Setting this does not automatically reload the homepage.
|
* Setting this does not automatically reload the homepage.
|
||||||
*/
|
*/
|
||||||
var currentHomePage: String?
|
var currentHomePage: String?
|
||||||
get() = getKey("$currentAccount/$USER_SELECTED_HOMEPAGE_API")
|
get() = getKey<String>("$currentAccount/$USER_SELECTED_HOMEPAGE_API")
|
||||||
set(value) {
|
set(value) {
|
||||||
val key = "$currentAccount/$USER_SELECTED_HOMEPAGE_API"
|
val key = "$currentAccount/$USER_SELECTED_HOMEPAGE_API"
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
|
|
@ -188,7 +197,6 @@ object DataStoreHelper {
|
||||||
|
|
||||||
fun setAccount(account: Account) {
|
fun setAccount(account: Account) {
|
||||||
val homepage = currentHomePage
|
val homepage = currentHomePage
|
||||||
|
|
||||||
selectedKeyIndex = account.keyIndex
|
selectedKeyIndex = account.keyIndex
|
||||||
AccountManager.updateAccountIds()
|
AccountManager.updateAccountIds()
|
||||||
showToast(context?.getString(R.string.logged_account, account.name) ?: account.name)
|
showToast(context?.getString(R.string.logged_account, account.name) ?: account.name)
|
||||||
|
|
@ -206,7 +214,7 @@ object DataStoreHelper {
|
||||||
currentAccounts.getOrNull(currentAccounts.indexOfFirst { it.keyIndex == 0 }) ?: Account(
|
currentAccounts.getOrNull(currentAccounts.indexOfFirst { it.keyIndex == 0 }) ?: Account(
|
||||||
keyIndex = 0,
|
keyIndex = 0,
|
||||||
name = context.getString(R.string.default_account),
|
name = context.getString(R.string.default_account),
|
||||||
defaultImageIndex = 0
|
defaultImageIndex = 0,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -232,18 +240,21 @@ object DataStoreHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class PosDur(
|
data class PosDur(
|
||||||
@JsonProperty("position") val position: Long,
|
@JsonProperty("position") @SerialName("position") val position: Long,
|
||||||
@JsonProperty("duration") val duration: Long
|
@JsonProperty("duration") @SerialName("duration") val duration: Long,
|
||||||
)
|
)
|
||||||
|
|
||||||
fun PosDur.fixVisual(): PosDur {
|
fun PosDur.fixVisual(): PosDur {
|
||||||
if (duration <= 0) return PosDur(0, duration)
|
if (duration <= 0) return PosDur(0, duration)
|
||||||
val percentage = position * 100 / duration
|
val percentage = position * 100 / duration
|
||||||
if (percentage <= 1) return PosDur(0, duration)
|
return when {
|
||||||
if (percentage <= 5) return PosDur(5 * duration / 100, duration)
|
percentage <= 1 -> PosDur(0, duration)
|
||||||
if (percentage >= 95) return PosDur(duration, duration)
|
percentage <= 5 -> PosDur(5 * duration / 100, duration)
|
||||||
return this
|
percentage >= 95 -> PosDur(duration, duration)
|
||||||
|
else -> this
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Int.toYear(): Date =
|
fun Int.toYear(): Date =
|
||||||
|
|
@ -251,28 +262,38 @@ object DataStoreHelper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to display notifications on new episodes and posters in library.
|
* Used to display notifications on new episodes and posters in library.
|
||||||
**/
|
*/
|
||||||
|
@Serializable
|
||||||
abstract class LibrarySearchResponse(
|
abstract class LibrarySearchResponse(
|
||||||
@JsonProperty("id") override var id: Int?,
|
/**
|
||||||
@JsonProperty("latestUpdatedTime") open val latestUpdatedTime: Long,
|
* These fields are marked @Transient because this class is only ever serialized through
|
||||||
@JsonProperty("name") override val name: String,
|
* through its subclasses, which redeclare each property with their own @SerialName
|
||||||
@JsonProperty("url") override val url: String,
|
* annotations. Without @Transient here, kotlinx.serialization would try to
|
||||||
@JsonProperty("apiName") override val apiName: String,
|
* generate a serializer for the abstract base class itself (or double-serialize
|
||||||
@JsonProperty("type") override var type: TvType?,
|
* these fields), which fails/conflicts since these are meant to be overridden,
|
||||||
@JsonProperty("posterUrl") override var posterUrl: String?,
|
* not serialized directly from the parent.
|
||||||
@JsonProperty("year") open val year: Int?,
|
*/
|
||||||
@JsonProperty("syncData") open val syncData: Map<String, String>?,
|
@Transient override var id: Int? = null,
|
||||||
@JsonProperty("quality") override var quality: SearchQuality?,
|
@Transient open val latestUpdatedTime: Long = 0L,
|
||||||
@JsonProperty("posterHeaders") override var posterHeaders: Map<String, String>?,
|
@Transient override val name: String = "",
|
||||||
@JsonProperty("plot") open val plot: String? = null,
|
@Transient override val url: String = "",
|
||||||
@JsonProperty("score") override var score: Score? = null,
|
@Transient override val apiName: String = "",
|
||||||
@JsonProperty("tags") open val tags: List<String>? = null,
|
@Transient override var type: TvType? = null,
|
||||||
|
@Transient override var posterUrl: String? = null,
|
||||||
|
@Transient open val year: Int? = null,
|
||||||
|
@Transient open val syncData: Map<String, String>? = null,
|
||||||
|
@Transient override var quality: SearchQuality? = null,
|
||||||
|
@Transient override var posterHeaders: Map<String, String>? = null,
|
||||||
|
@Transient open val plot: String? = null,
|
||||||
|
@Transient override var score: Score? = null,
|
||||||
|
@Transient open val tags: List<String>? = null,
|
||||||
) : SearchResponse {
|
) : SearchResponse {
|
||||||
@JsonProperty("rating", access = JsonProperty.Access.WRITE_ONLY)
|
@JsonProperty("rating", access = JsonProperty.Access.WRITE_ONLY)
|
||||||
|
@SerialName("rating")
|
||||||
@Deprecated(
|
@Deprecated(
|
||||||
"`rating` is the old scoring system, use score instead",
|
"`rating` is the old scoring system, use score instead",
|
||||||
replaceWith = ReplaceWith("score"),
|
replaceWith = ReplaceWith("score"),
|
||||||
level = DeprecationLevel.ERROR
|
level = DeprecationLevel.ERROR,
|
||||||
)
|
)
|
||||||
var rating: Int? = null
|
var rating: Int? = null
|
||||||
set(value) {
|
set(value) {
|
||||||
|
|
@ -283,23 +304,26 @@ object DataStoreHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalSerializationApi::class) // KeepGeneratedSerializer is an experimental annotation for now
|
||||||
|
@KeepGeneratedSerializer
|
||||||
|
@Serializable(with = SubscribedData.Serializer::class)
|
||||||
data class SubscribedData(
|
data class SubscribedData(
|
||||||
@JsonProperty("subscribedTime") val subscribedTime: Long,
|
@JsonProperty("subscribedTime") @SerialName("subscribedTime") val subscribedTime: Long,
|
||||||
@JsonProperty("lastSeenEpisodeCount") val lastSeenEpisodeCount: Map<DubStatus, Int?>,
|
@JsonProperty("lastSeenEpisodeCount") @SerialName("lastSeenEpisodeCount") val lastSeenEpisodeCount: Map<DubStatus, Int?>,
|
||||||
override var id: Int?,
|
@JsonProperty("id") @SerialName("id") override var id: Int?,
|
||||||
override val latestUpdatedTime: Long,
|
@JsonProperty("latestUpdatedTime") @SerialName("latestUpdatedTime") override val latestUpdatedTime: Long,
|
||||||
override val name: String,
|
@JsonProperty("name") @SerialName("name") override val name: String,
|
||||||
override val url: String,
|
@JsonProperty("url") @SerialName("url") override val url: String,
|
||||||
override val apiName: String,
|
@JsonProperty("apiName") @SerialName("apiName") override val apiName: String,
|
||||||
override var type: TvType?,
|
@JsonProperty("type") @SerialName("type") override var type: TvType?,
|
||||||
override var posterUrl: String?,
|
@JsonProperty("posterUrl") @SerialName("posterUrl") override var posterUrl: String?,
|
||||||
override val year: Int?,
|
@JsonProperty("year") @SerialName("year") override val year: Int?,
|
||||||
override val syncData: Map<String, String>? = null,
|
@JsonProperty("syncData") @SerialName("syncData") override val syncData: Map<String, String>? = null,
|
||||||
override var quality: SearchQuality? = null,
|
@JsonProperty("quality") @SerialName("quality") override var quality: SearchQuality? = null,
|
||||||
override var posterHeaders: Map<String, String>? = null,
|
@JsonProperty("posterHeaders") @SerialName("posterHeaders") override var posterHeaders: Map<String, String>? = null,
|
||||||
override val plot: String? = null,
|
@JsonProperty("plot") @SerialName("plot") override val plot: String? = null,
|
||||||
override var score: Score? = null,
|
@JsonProperty("score") @SerialName("score") override var score: Score? = null,
|
||||||
override val tags: List<String>? = null,
|
@JsonProperty("tags") @SerialName("tags") override val tags: List<String>? = null,
|
||||||
) : LibrarySearchResponse(
|
) : LibrarySearchResponse(
|
||||||
id,
|
id,
|
||||||
latestUpdatedTime,
|
latestUpdatedTime,
|
||||||
|
|
@ -314,8 +338,13 @@ object DataStoreHelper {
|
||||||
posterHeaders,
|
posterHeaders,
|
||||||
plot,
|
plot,
|
||||||
score,
|
score,
|
||||||
tags
|
tags,
|
||||||
) {
|
) {
|
||||||
|
object Serializer : WriteOnlySerializer<SubscribedData>(
|
||||||
|
SubscribedData.generatedSerializer(),
|
||||||
|
setOf("rating"),
|
||||||
|
)
|
||||||
|
|
||||||
fun toLibraryItem(): SyncAPI.LibraryItem? {
|
fun toLibraryItem(): SyncAPI.LibraryItem? {
|
||||||
return SyncAPI.LibraryItem(
|
return SyncAPI.LibraryItem(
|
||||||
name,
|
name,
|
||||||
|
|
@ -334,27 +363,30 @@ object DataStoreHelper {
|
||||||
this.id,
|
this.id,
|
||||||
plot = this.plot,
|
plot = this.plot,
|
||||||
score = this.score,
|
score = this.score,
|
||||||
tags = this.tags
|
tags = this.tags,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalSerializationApi::class) // KeepGeneratedSerializer is an experimental annotation for now
|
||||||
|
@KeepGeneratedSerializer
|
||||||
|
@Serializable(with = BookmarkedData.Serializer::class)
|
||||||
data class BookmarkedData(
|
data class BookmarkedData(
|
||||||
@JsonProperty("bookmarkedTime") val bookmarkedTime: Long,
|
@JsonProperty("bookmarkedTime") @SerialName("bookmarkedTime") val bookmarkedTime: Long,
|
||||||
override var id: Int?,
|
@JsonProperty("id") @SerialName("id") override var id: Int?,
|
||||||
override val latestUpdatedTime: Long,
|
@JsonProperty("latestUpdatedTime") @SerialName("latestUpdatedTime") override val latestUpdatedTime: Long,
|
||||||
override val name: String,
|
@JsonProperty("name") @SerialName("name") override val name: String,
|
||||||
override val url: String,
|
@JsonProperty("url") @SerialName("url") override val url: String,
|
||||||
override val apiName: String,
|
@JsonProperty("apiName") @SerialName("apiName") override val apiName: String,
|
||||||
override var type: TvType?,
|
@JsonProperty("type") @SerialName("type") override var type: TvType?,
|
||||||
override var posterUrl: String?,
|
@JsonProperty("posterUrl") @SerialName("posterUrl") override var posterUrl: String?,
|
||||||
override val year: Int?,
|
@JsonProperty("year") @SerialName("year") override val year: Int?,
|
||||||
override val syncData: Map<String, String>? = null,
|
@JsonProperty("syncData") @SerialName("syncData") override val syncData: Map<String, String>? = null,
|
||||||
override var quality: SearchQuality? = null,
|
@JsonProperty("quality") @SerialName("quality") override var quality: SearchQuality? = null,
|
||||||
override var posterHeaders: Map<String, String>? = null,
|
@JsonProperty("posterHeaders") @SerialName("posterHeaders") override var posterHeaders: Map<String, String>? = null,
|
||||||
override val plot: String? = null,
|
@JsonProperty("plot") @SerialName("plot") override val plot: String? = null,
|
||||||
override var score: Score? = null,
|
@JsonProperty("score") @SerialName("score") override var score: Score? = null,
|
||||||
override val tags: List<String>? = null,
|
@JsonProperty("tags") @SerialName("tags") override val tags: List<String>? = null,
|
||||||
) : LibrarySearchResponse(
|
) : LibrarySearchResponse(
|
||||||
id,
|
id,
|
||||||
latestUpdatedTime,
|
latestUpdatedTime,
|
||||||
|
|
@ -367,8 +399,13 @@ object DataStoreHelper {
|
||||||
syncData,
|
syncData,
|
||||||
quality,
|
quality,
|
||||||
posterHeaders,
|
posterHeaders,
|
||||||
plot
|
plot,
|
||||||
) {
|
) {
|
||||||
|
object Serializer : WriteOnlySerializer<BookmarkedData>(
|
||||||
|
BookmarkedData.generatedSerializer(),
|
||||||
|
setOf("rating"),
|
||||||
|
)
|
||||||
|
|
||||||
fun toLibraryItem(id: String): SyncAPI.LibraryItem {
|
fun toLibraryItem(id: String): SyncAPI.LibraryItem {
|
||||||
return SyncAPI.LibraryItem(
|
return SyncAPI.LibraryItem(
|
||||||
name,
|
name,
|
||||||
|
|
@ -387,27 +424,30 @@ object DataStoreHelper {
|
||||||
this.id,
|
this.id,
|
||||||
plot = this.plot,
|
plot = this.plot,
|
||||||
score = this.score,
|
score = this.score,
|
||||||
tags = this.tags
|
tags = this.tags,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalSerializationApi::class) // KeepGeneratedSerializer is an experimental annotation for now
|
||||||
|
@KeepGeneratedSerializer
|
||||||
|
@Serializable(with = FavoritesData.Serializer::class)
|
||||||
data class FavoritesData(
|
data class FavoritesData(
|
||||||
@JsonProperty("favoritesTime") val favoritesTime: Long,
|
@JsonProperty("favoritesTime") @SerialName("favoritesTime") val favoritesTime: Long,
|
||||||
override var id: Int?,
|
@JsonProperty("id") @SerialName("id") override var id: Int?,
|
||||||
override val latestUpdatedTime: Long,
|
@JsonProperty("latestUpdatedTime") @SerialName("latestUpdatedTime") override val latestUpdatedTime: Long,
|
||||||
override val name: String,
|
@JsonProperty("name") @SerialName("name") override val name: String,
|
||||||
override val url: String,
|
@JsonProperty("url") @SerialName("url") override val url: String,
|
||||||
override val apiName: String,
|
@JsonProperty("apiName") @SerialName("apiName") override val apiName: String,
|
||||||
override var type: TvType?,
|
@JsonProperty("type") @SerialName("type") override var type: TvType?,
|
||||||
override var posterUrl: String?,
|
@JsonProperty("posterUrl") @SerialName("posterUrl") override var posterUrl: String?,
|
||||||
override val year: Int?,
|
@JsonProperty("year") @SerialName("year") override val year: Int?,
|
||||||
override val syncData: Map<String, String>? = null,
|
@JsonProperty("syncData") @SerialName("syncData") override val syncData: Map<String, String>? = null,
|
||||||
override var quality: SearchQuality? = null,
|
@JsonProperty("quality") @SerialName("quality") override var quality: SearchQuality? = null,
|
||||||
override var posterHeaders: Map<String, String>? = null,
|
@JsonProperty("posterHeaders") @SerialName("posterHeaders") override var posterHeaders: Map<String, String>? = null,
|
||||||
override val plot: String? = null,
|
@JsonProperty("plot") @SerialName("plot") override val plot: String? = null,
|
||||||
override var score: Score? = null,
|
@JsonProperty("score") @SerialName("score") override var score: Score? = null,
|
||||||
override val tags: List<String>? = null,
|
@JsonProperty("tags") @SerialName("tags") override val tags: List<String>? = null,
|
||||||
) : LibrarySearchResponse(
|
) : LibrarySearchResponse(
|
||||||
id,
|
id,
|
||||||
latestUpdatedTime,
|
latestUpdatedTime,
|
||||||
|
|
@ -420,8 +460,13 @@ object DataStoreHelper {
|
||||||
syncData,
|
syncData,
|
||||||
quality,
|
quality,
|
||||||
posterHeaders,
|
posterHeaders,
|
||||||
plot
|
plot,
|
||||||
) {
|
) {
|
||||||
|
object Serializer : WriteOnlySerializer<FavoritesData>(
|
||||||
|
FavoritesData.generatedSerializer(),
|
||||||
|
setOf("rating"),
|
||||||
|
)
|
||||||
|
|
||||||
fun toLibraryItem(): SyncAPI.LibraryItem? {
|
fun toLibraryItem(): SyncAPI.LibraryItem? {
|
||||||
return SyncAPI.LibraryItem(
|
return SyncAPI.LibraryItem(
|
||||||
name,
|
name,
|
||||||
|
|
@ -440,31 +485,32 @@ object DataStoreHelper {
|
||||||
this.id,
|
this.id,
|
||||||
plot = this.plot,
|
plot = this.plot,
|
||||||
score = this.score,
|
score = this.score,
|
||||||
tags = this.tags
|
tags = this.tags,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class ResumeWatchingResult(
|
data class ResumeWatchingResult(
|
||||||
@JsonProperty("name") override val name: String,
|
@JsonProperty("name") @SerialName("name") override val name: String,
|
||||||
@JsonProperty("url") override val url: String,
|
@JsonProperty("url") @SerialName("url") override val url: String,
|
||||||
@JsonProperty("apiName") override val apiName: String,
|
@JsonProperty("apiName") @SerialName("apiName") override val apiName: String,
|
||||||
@JsonProperty("type") override var type: TvType? = null,
|
@JsonProperty("type") @SerialName("type") override var type: TvType? = null,
|
||||||
@JsonProperty("posterUrl") override var posterUrl: String?,
|
@JsonProperty("posterUrl") @SerialName("posterUrl") override var posterUrl: String?,
|
||||||
@JsonProperty("watchPos") val watchPos: PosDur?,
|
@JsonProperty("watchPos") @SerialName("watchPos") val watchPos: PosDur?,
|
||||||
@JsonProperty("id") override var id: Int?,
|
@JsonProperty("id") @SerialName("id") override var id: Int?,
|
||||||
@JsonProperty("parentId") val parentId: Int?,
|
@JsonProperty("parentId") @SerialName("parentId") val parentId: Int?,
|
||||||
@JsonProperty("episode") val episode: Int?,
|
@JsonProperty("episode") @SerialName("episode") val episode: Int?,
|
||||||
@JsonProperty("season") val season: Int?,
|
@JsonProperty("season") @SerialName("season") val season: Int?,
|
||||||
@JsonProperty("isFromDownload") val isFromDownload: Boolean,
|
@JsonProperty("isFromDownload") @SerialName("isFromDownload") val isFromDownload: Boolean,
|
||||||
@JsonProperty("quality") override var quality: SearchQuality? = null,
|
@JsonProperty("quality") @SerialName("quality") override var quality: SearchQuality? = null,
|
||||||
@JsonProperty("posterHeaders") override var posterHeaders: Map<String, String>? = null,
|
@JsonProperty("posterHeaders") @SerialName("posterHeaders") override var posterHeaders: Map<String, String>? = null,
|
||||||
@JsonProperty("score") override var score: Score? = null,
|
@JsonProperty("score") @SerialName("score") override var score: Score? = null,
|
||||||
) : SearchResponse
|
) : SearchResponse
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A datastore wide account for future implementations of a multiple account system
|
* A datastore wide account for future implementations of a multiple account system
|
||||||
**/
|
*/
|
||||||
|
|
||||||
fun getAllWatchStateIds(): List<Int>? {
|
fun getAllWatchStateIds(): List<Int>? {
|
||||||
val folder = "$currentAccount/$RESULT_WATCH_STATE"
|
val folder = "$currentAccount/$RESULT_WATCH_STATE"
|
||||||
|
|
@ -500,7 +546,7 @@ object DataStoreHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun migrateResumeWatching() {
|
fun migrateResumeWatching() {
|
||||||
// if (getKey(RESULT_RESUME_WATCHING_HAS_MIGRATED, false) != true) {
|
// if (getKey<Boolean>(RESULT_RESUME_WATCHING_HAS_MIGRATED, false) != true) {
|
||||||
setKey(RESULT_RESUME_WATCHING_HAS_MIGRATED, true)
|
setKey(RESULT_RESUME_WATCHING_HAS_MIGRATED, true)
|
||||||
getAllResumeStateIdsOld()?.forEach { id ->
|
getAllResumeStateIdsOld()?.forEach { id ->
|
||||||
getLastWatchedOld(id)?.let {
|
getLastWatchedOld(id)?.let {
|
||||||
|
|
@ -510,12 +556,12 @@ object DataStoreHelper {
|
||||||
it.episode,
|
it.episode,
|
||||||
it.season,
|
it.season,
|
||||||
it.isFromDownload,
|
it.isFromDownload,
|
||||||
it.updateTime
|
it.updateTime,
|
||||||
)
|
)
|
||||||
removeLastWatchedOld(it.parentId)
|
removeLastWatchedOld(it.parentId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setLastWatched(
|
fun setLastWatched(
|
||||||
|
|
@ -536,7 +582,7 @@ object DataStoreHelper {
|
||||||
episode,
|
episode,
|
||||||
season,
|
season,
|
||||||
updateTime ?: System.currentTimeMillis(),
|
updateTime ?: System.currentTimeMillis(),
|
||||||
isFromDownload
|
isFromDownload,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -553,7 +599,7 @@ object DataStoreHelper {
|
||||||
|
|
||||||
fun getLastWatched(id: Int?): DownloadObjects.ResumeWatching? {
|
fun getLastWatched(id: Int?): DownloadObjects.ResumeWatching? {
|
||||||
if (id == null) return null
|
if (id == null) return null
|
||||||
return getKey(
|
return getKey<DownloadObjects.ResumeWatching>(
|
||||||
"$currentAccount/$RESULT_RESUME_WATCHING",
|
"$currentAccount/$RESULT_RESUME_WATCHING",
|
||||||
id.toString(),
|
id.toString(),
|
||||||
)
|
)
|
||||||
|
|
@ -561,7 +607,7 @@ object DataStoreHelper {
|
||||||
|
|
||||||
private fun getLastWatchedOld(id: Int?): DownloadObjects.ResumeWatching? {
|
private fun getLastWatchedOld(id: Int?): DownloadObjects.ResumeWatching? {
|
||||||
if (id == null) return null
|
if (id == null) return null
|
||||||
return getKey(
|
return getKey<DownloadObjects.ResumeWatching>(
|
||||||
"$currentAccount/$RESULT_RESUME_WATCHING_OLD",
|
"$currentAccount/$RESULT_RESUME_WATCHING_OLD",
|
||||||
id.toString(),
|
id.toString(),
|
||||||
)
|
)
|
||||||
|
|
@ -575,18 +621,18 @@ object DataStoreHelper {
|
||||||
|
|
||||||
fun getBookmarkedData(id: Int?): BookmarkedData? {
|
fun getBookmarkedData(id: Int?): BookmarkedData? {
|
||||||
if (id == null) return null
|
if (id == null) return null
|
||||||
return getKey("$currentAccount/$RESULT_WATCH_STATE_DATA", id.toString())
|
return getKey<BookmarkedData>("$currentAccount/$RESULT_WATCH_STATE_DATA", id.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getAllBookmarkedData(): List<BookmarkedData> {
|
fun getAllBookmarkedData(): List<BookmarkedData> {
|
||||||
return getKeys("$currentAccount/$RESULT_WATCH_STATE_DATA")?.mapNotNull {
|
return getKeys("$currentAccount/$RESULT_WATCH_STATE_DATA")?.mapNotNull {
|
||||||
getKey(it)
|
getKey<BookmarkedData>(it)
|
||||||
} ?: emptyList()
|
} ?: emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getAllSubscriptions(): List<SubscribedData> {
|
fun getAllSubscriptions(): List<SubscribedData> {
|
||||||
return getKeys("$currentAccount/$RESULT_SUBSCRIBED_STATE_DATA")?.mapNotNull {
|
return getKeys("$currentAccount/$RESULT_SUBSCRIBED_STATE_DATA")?.mapNotNull {
|
||||||
getKey(it)
|
getKey<SubscribedData>(it)
|
||||||
} ?: emptyList()
|
} ?: emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -598,12 +644,12 @@ object DataStoreHelper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set new seen episodes and update time
|
* Set new seen episodes and update time
|
||||||
**/
|
*/
|
||||||
fun updateSubscribedData(id: Int?, data: SubscribedData?, episodeResponse: EpisodeResponse?) {
|
fun updateSubscribedData(id: Int?, data: SubscribedData?, episodeResponse: EpisodeResponse?) {
|
||||||
if (id == null || data == null || episodeResponse == null) return
|
if (id == null || data == null || episodeResponse == null) return
|
||||||
val newData = data.copy(
|
val newData = data.copy(
|
||||||
latestUpdatedTime = unixTimeMS,
|
latestUpdatedTime = unixTimeMS,
|
||||||
lastSeenEpisodeCount = episodeResponse.getLatestEpisodes()
|
lastSeenEpisodeCount = episodeResponse.getLatestEpisodes(),
|
||||||
)
|
)
|
||||||
setKey("$currentAccount/$RESULT_SUBSCRIBED_STATE_DATA", id.toString(), newData)
|
setKey("$currentAccount/$RESULT_SUBSCRIBED_STATE_DATA", id.toString(), newData)
|
||||||
}
|
}
|
||||||
|
|
@ -616,12 +662,12 @@ object DataStoreHelper {
|
||||||
|
|
||||||
fun getSubscribedData(id: Int?): SubscribedData? {
|
fun getSubscribedData(id: Int?): SubscribedData? {
|
||||||
if (id == null) return null
|
if (id == null) return null
|
||||||
return getKey("$currentAccount/$RESULT_SUBSCRIBED_STATE_DATA", id.toString())
|
return getKey<SubscribedData>("$currentAccount/$RESULT_SUBSCRIBED_STATE_DATA", id.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getAllFavorites(): List<FavoritesData> {
|
fun getAllFavorites(): List<FavoritesData> {
|
||||||
return getKeys("$currentAccount/$RESULT_FAVORITES_STATE_DATA")?.mapNotNull {
|
return getKeys("$currentAccount/$RESULT_FAVORITES_STATE_DATA")?.mapNotNull {
|
||||||
getKey(it)
|
getKey<FavoritesData>(it)
|
||||||
} ?: emptyList()
|
} ?: emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -639,7 +685,7 @@ object DataStoreHelper {
|
||||||
|
|
||||||
fun getFavoritesData(id: Int?): FavoritesData? {
|
fun getFavoritesData(id: Int?): FavoritesData? {
|
||||||
if (id == null) return null
|
if (id == null) return null
|
||||||
return getKey("$currentAccount/$RESULT_FAVORITES_STATE_DATA", id.toString())
|
return getKey<FavoritesData>("$currentAccount/$RESULT_FAVORITES_STATE_DATA", id.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setViewPos(id: Int?, pos: Long, dur: Long) {
|
fun setViewPos(id: Int?, pos: Long, dur: Long) {
|
||||||
|
|
@ -648,10 +694,10 @@ object DataStoreHelper {
|
||||||
setKey("$currentAccount/$VIDEO_POS_DUR", id.toString(), PosDur(pos, dur))
|
setKey("$currentAccount/$VIDEO_POS_DUR", id.toString(), PosDur(pos, dur))
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Sets the position, duration, and resume data of an episode/movie,
|
/**
|
||||||
*
|
* Sets the position, duration, and resume data of an episode/movie,
|
||||||
* if nextEpisode is not specified it will not be able to set the next episode as resumable if progress > NEXT_WATCH_EPISODE_PERCENTAGE
|
* If nextEpisode is not specified it will not be able to set the next episode as resumable if progress > NEXT_WATCH_EPISODE_PERCENTAGE
|
||||||
* */
|
*/
|
||||||
fun setViewPosAndResume(id: Int?, position: Long, duration: Long, currentEpisode: Any?, nextEpisode: Any?) {
|
fun setViewPosAndResume(id: Int?, position: Long, duration: Long, currentEpisode: Any?, nextEpisode: Any?) {
|
||||||
setViewPos(id, position, duration)
|
setViewPos(id, position, duration)
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
|
|
@ -687,7 +733,7 @@ object DataStoreHelper {
|
||||||
resumeMeta.id,
|
resumeMeta.id,
|
||||||
resumeMeta.episode,
|
resumeMeta.episode,
|
||||||
resumeMeta.season,
|
resumeMeta.season,
|
||||||
isFromDownload = false
|
isFromDownload = false,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -697,7 +743,7 @@ object DataStoreHelper {
|
||||||
resumeMeta.id,
|
resumeMeta.id,
|
||||||
resumeMeta.episode,
|
resumeMeta.episode,
|
||||||
resumeMeta.season,
|
resumeMeta.season,
|
||||||
isFromDownload = true
|
isFromDownload = true,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -706,17 +752,16 @@ object DataStoreHelper {
|
||||||
|
|
||||||
fun getViewPos(id: Int?): PosDur? {
|
fun getViewPos(id: Int?): PosDur? {
|
||||||
if (id == null) return null
|
if (id == null) return null
|
||||||
return getKey("$currentAccount/$VIDEO_POS_DUR", id.toString(), null)
|
return getKey<PosDur>("$currentAccount/$VIDEO_POS_DUR", id.toString(), null)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getVideoWatchState(id: Int?): VideoWatchState? {
|
fun getVideoWatchState(id: Int?): VideoWatchState? {
|
||||||
if (id == null) return null
|
if (id == null) return null
|
||||||
return getKey("$currentAccount/$VIDEO_WATCH_STATE", id.toString(), null)
|
return getKey<VideoWatchState>("$currentAccount/$VIDEO_WATCH_STATE", id.toString(), null)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setVideoWatchState(id: Int?, watchState: VideoWatchState) {
|
fun setVideoWatchState(id: Int?, watchState: VideoWatchState) {
|
||||||
if (id == null) return
|
if (id == null) return
|
||||||
|
|
||||||
// None == No key
|
// None == No key
|
||||||
if (watchState == VideoWatchState.None) {
|
if (watchState == VideoWatchState.None) {
|
||||||
removeKey("$currentAccount/$VIDEO_WATCH_STATE", id.toString())
|
removeKey("$currentAccount/$VIDEO_WATCH_STATE", id.toString())
|
||||||
|
|
@ -727,7 +772,7 @@ object DataStoreHelper {
|
||||||
|
|
||||||
fun getDub(id: Int): DubStatus? {
|
fun getDub(id: Int): DubStatus? {
|
||||||
return DubStatus.entries
|
return DubStatus.entries
|
||||||
.getOrNull(getKey("$currentAccount/$RESULT_DUB", id.toString(), -1) ?: -1)
|
.getOrNull(getKey<Int>("$currentAccount/$RESULT_DUB", id.toString(), -1) ?: -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setDub(id: Int, status: DubStatus) {
|
fun setDub(id: Int, status: DubStatus) {
|
||||||
|
|
@ -748,13 +793,13 @@ object DataStoreHelper {
|
||||||
getKey<Int>(
|
getKey<Int>(
|
||||||
"$currentAccount/$RESULT_WATCH_STATE",
|
"$currentAccount/$RESULT_WATCH_STATE",
|
||||||
id.toString(),
|
id.toString(),
|
||||||
null
|
null,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getResultSeason(id: Int): Int? {
|
fun getResultSeason(id: Int): Int? {
|
||||||
return getKey("$currentAccount/$RESULT_SEASON", id.toString(), null)
|
return getKey<Int>("$currentAccount/$RESULT_SEASON", id.toString(), null)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setResultSeason(id: Int, value: Int?) {
|
fun setResultSeason(id: Int, value: Int?) {
|
||||||
|
|
@ -762,7 +807,7 @@ object DataStoreHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getResultEpisode(id: Int): Int? {
|
fun getResultEpisode(id: Int): Int? {
|
||||||
return getKey("$currentAccount/$RESULT_EPISODE", id.toString(), null)
|
return getKey<Int>("$currentAccount/$RESULT_EPISODE", id.toString(), null)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setResultEpisode(id: Int, value: Int?) {
|
fun setResultEpisode(id: Int, value: Int?) {
|
||||||
|
|
@ -775,12 +820,11 @@ object DataStoreHelper {
|
||||||
|
|
||||||
fun getSync(id: Int, idPrefixes: List<String>): List<String?> {
|
fun getSync(id: Int, idPrefixes: List<String>): List<String?> {
|
||||||
return idPrefixes.map { idPrefix ->
|
return idPrefixes.map { idPrefix ->
|
||||||
getKey("${idPrefix}_sync", id.toString())
|
getKey<String>("${idPrefix}_sync", id.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var pinnedProviders: Array<String>
|
var pinnedProviders: Array<String>
|
||||||
get() = getKey(USER_PINNED_PROVIDERS) ?: emptyArray<String>()
|
get() = getKey<Array<String>>(USER_PINNED_PROVIDERS) ?: emptyArray<String>()
|
||||||
set(value) = setKey(USER_PINNED_PROVIDERS, value)
|
set(value) = setKey(USER_PINNED_PROVIDERS, value)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ object SyncUtil {
|
||||||
// Gogoanime, Twistmoe and 9anime
|
// Gogoanime, Twistmoe and 9anime
|
||||||
val url = "https://raw.githubusercontent.com/MALSync/MAL-Sync-Backup/master/data/pages/$site/$slug.json"
|
val url = "https://raw.githubusercontent.com/MALSync/MAL-Sync-Backup/master/data/pages/$site/$slug.json"
|
||||||
val response = app.get(url, cacheTime = 1, cacheUnit = TimeUnit.DAYS).text
|
val response = app.get(url, cacheTime = 1, cacheUnit = TimeUnit.DAYS).text
|
||||||
val mapped = tryParseJson<MalSyncPage?>(response)
|
val mapped = tryParseJson<MalSyncPage>(response)
|
||||||
|
|
||||||
val overrideMal = mapped?.malId ?: mapped?.mal?.id ?: mapped?.anilist?.malId
|
val overrideMal = mapped?.malId ?: mapped?.mal?.id ?: mapped?.anilist?.malId
|
||||||
val overrideAnilist = mapped?.aniId ?: mapped?.anilist?.id
|
val overrideAnilist = mapped?.aniId ?: mapped?.anilist?.id
|
||||||
|
|
|
||||||
|
|
@ -23,15 +23,15 @@ const val PROGRAM_ID_LIST_KEY = "persistent_program_ids"
|
||||||
|
|
||||||
object TvChannelUtils {
|
object TvChannelUtils {
|
||||||
fun Context.saveProgramId(programId: Long) {
|
fun Context.saveProgramId(programId: Long) {
|
||||||
val existing: List<Long> = getKey(PROGRAM_ID_LIST_KEY) ?: emptyList()
|
val existing: List<Long> = getKey<List<Long>>(PROGRAM_ID_LIST_KEY) ?: emptyList()
|
||||||
val updated = (existing + programId).distinct()
|
val updated = (existing + programId).distinct()
|
||||||
setKey(PROGRAM_ID_LIST_KEY, updated)
|
setKey(PROGRAM_ID_LIST_KEY, updated)
|
||||||
}
|
}
|
||||||
fun Context.getStoredProgramIds(): List<Long> {
|
fun Context.getStoredProgramIds(): List<Long> {
|
||||||
return getKey(PROGRAM_ID_LIST_KEY) ?: emptyList()
|
return getKey<List<Long>>(PROGRAM_ID_LIST_KEY) ?: emptyList()
|
||||||
}
|
}
|
||||||
fun Context.removeProgramId(programId: Long) {
|
fun Context.removeProgramId(programId: Long) {
|
||||||
val existing: List<Long> = getKey(PROGRAM_ID_LIST_KEY) ?: emptyList()
|
val existing: List<Long> = getKey<List<Long>>(PROGRAM_ID_LIST_KEY) ?: emptyList()
|
||||||
val updated = existing.filter { it != programId }
|
val updated = existing.filter { it != programId }
|
||||||
setKey(PROGRAM_ID_LIST_KEY, updated)
|
setKey(PROGRAM_ID_LIST_KEY, updated)
|
||||||
}
|
}
|
||||||
|
|
@ -161,4 +161,4 @@ object TvChannelUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,9 +65,12 @@ import androidx.navigation.fragment.NavHostFragment
|
||||||
import androidx.palette.graphics.Palette
|
import androidx.palette.graphics.Palette
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import com.google.android.material.appbar.AppBarLayout
|
import com.google.android.material.appbar.AppBarLayout
|
||||||
|
import com.google.android.material.button.MaterialButton
|
||||||
import com.google.android.material.chip.Chip
|
import com.google.android.material.chip.Chip
|
||||||
import com.google.android.material.chip.ChipDrawable
|
import com.google.android.material.chip.ChipDrawable
|
||||||
import com.google.android.material.chip.ChipGroup
|
import com.google.android.material.chip.ChipGroup
|
||||||
|
import com.google.android.material.progressindicator.CircularProgressIndicatorSpec
|
||||||
|
import com.google.android.material.progressindicator.IndeterminateDrawable
|
||||||
import com.lagradost.cloudstream3.CloudStreamApp.Companion.context
|
import com.lagradost.cloudstream3.CloudStreamApp.Companion.context
|
||||||
import com.lagradost.cloudstream3.CommonActivity.activity
|
import com.lagradost.cloudstream3.CommonActivity.activity
|
||||||
import com.lagradost.cloudstream3.CommonActivity.showToast
|
import com.lagradost.cloudstream3.CommonActivity.showToast
|
||||||
|
|
@ -583,6 +586,43 @@ object UIHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Source: https://stackoverflow.com/questions/70954321/circular-progress-indicator-inside-buttons-android-material-design
|
||||||
|
*
|
||||||
|
* Shows indeterminate progress bar on this button in place of where icon would be.
|
||||||
|
* By default the tint of progress bar is the same as iconTint.
|
||||||
|
*
|
||||||
|
* @param tintColor (@ColorInt Int) Sets custom progress bar tint color.
|
||||||
|
*/
|
||||||
|
fun MaterialButton.showProgress(@ColorInt tintColor: Int = this.iconTint.defaultColor) =
|
||||||
|
// Use runOnMainThreadNative to allow process on io threads, to make the code a bit cleaner
|
||||||
|
runOnMainThreadNative {
|
||||||
|
// No need to set it again, as then it will reset the animation
|
||||||
|
if(this.icon is IndeterminateDrawable<*>) {
|
||||||
|
return@runOnMainThreadNative
|
||||||
|
}
|
||||||
|
val spec = CircularProgressIndicatorSpec(
|
||||||
|
context, null, 0,
|
||||||
|
com.google.android.material.R.style.Widget_Material3_CircularProgressIndicator_ExtraSmall
|
||||||
|
)
|
||||||
|
|
||||||
|
spec.indicatorColors = intArrayOf(tintColor)
|
||||||
|
|
||||||
|
val progressIndicatorDrawable =
|
||||||
|
IndeterminateDrawable.createCircularDrawable(context, spec)
|
||||||
|
|
||||||
|
this.icon = progressIndicatorDrawable
|
||||||
|
if (this.getTag(R.id.text1) == null)
|
||||||
|
this.setTag(R.id.text1, this.text)
|
||||||
|
this.text = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
fun MaterialButton.hideProgress() =
|
||||||
|
runOnMainThreadNative {
|
||||||
|
this.text = this.getTag(R.id.text1) as? String
|
||||||
|
this.icon = null
|
||||||
|
}
|
||||||
|
|
||||||
/**id, stringRes */
|
/**id, stringRes */
|
||||||
@SuppressLint("RestrictedApi")
|
@SuppressLint("RestrictedApi")
|
||||||
fun View.popupMenuNoIcons(
|
fun View.popupMenuNoIcons(
|
||||||
|
|
|
||||||
|
|
@ -1640,11 +1640,11 @@ object VideoDownloadManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getDownloadResumePackage(context: Context, id: Int): DownloadResumePackage? {
|
fun getDownloadResumePackage(context: Context, id: Int): DownloadResumePackage? {
|
||||||
return context.getKey(KEY_RESUME_PACKAGES, id.toString())
|
return context.getKey<DownloadResumePackage>(KEY_RESUME_PACKAGES, id.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getDownloadQueuePackage(context: Context, id: Int): DownloadQueueWrapper? {
|
fun getDownloadQueuePackage(context: Context, id: Int): DownloadQueueWrapper? {
|
||||||
return context.getKey(KEY_RESUME_IN_QUEUE, id.toString())
|
return context.getKey<DownloadQueueWrapper>(KEY_RESUME_IN_QUEUE, id.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getDownloadEpisodeMetadata(
|
fun getDownloadEpisodeMetadata(
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,32 @@
|
||||||
package com.lagradost.cloudstream3.utils.downloader
|
package com.lagradost.cloudstream3.utils.downloader
|
||||||
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty
|
import com.fasterxml.jackson.annotation.JsonProperty
|
||||||
import com.lagradost.cloudstream3.Score
|
import com.lagradost.cloudstream3.Score
|
||||||
|
import com.lagradost.cloudstream3.SkipSerializationTest
|
||||||
import com.lagradost.cloudstream3.TvType
|
import com.lagradost.cloudstream3.TvType
|
||||||
import com.lagradost.cloudstream3.services.DownloadQueueService
|
import com.lagradost.cloudstream3.services.DownloadQueueService
|
||||||
import com.lagradost.cloudstream3.ui.player.SubtitleData
|
import com.lagradost.cloudstream3.ui.player.SubtitleData
|
||||||
import com.lagradost.cloudstream3.ui.result.ResultEpisode
|
import com.lagradost.cloudstream3.ui.result.ResultEpisode
|
||||||
import com.lagradost.cloudstream3.utils.ExtractorLink
|
import com.lagradost.cloudstream3.utils.ExtractorLink
|
||||||
|
import com.lagradost.cloudstream3.utils.serializers.UriSerializer
|
||||||
|
import com.lagradost.cloudstream3.utils.serializers.WriteOnlySerializer
|
||||||
import com.lagradost.safefile.SafeFile
|
import com.lagradost.safefile.SafeFile
|
||||||
|
import kotlinx.serialization.ExperimentalSerializationApi
|
||||||
|
import kotlinx.serialization.KeepGeneratedSerializer
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.io.OutputStream
|
import java.io.OutputStream
|
||||||
import java.util.Objects
|
import java.util.Objects
|
||||||
|
|
||||||
object DownloadObjects {
|
object DownloadObjects {
|
||||||
/** An item can either be something to resume or something new to start */
|
/** An item can either be something to resume or something new to start */
|
||||||
|
@Serializable
|
||||||
data class DownloadQueueWrapper(
|
data class DownloadQueueWrapper(
|
||||||
@JsonProperty("resumePackage") val resumePackage: DownloadResumePackage?,
|
@JsonProperty("resumePackage") @SerialName("resumePackage") val resumePackage: DownloadResumePackage?,
|
||||||
@JsonProperty("downloadItem") val downloadItem: DownloadQueueItem?,
|
@JsonProperty("downloadItem") @SerialName("downloadItem") val downloadItem: DownloadQueueItem?,
|
||||||
) {
|
) {
|
||||||
init {
|
init {
|
||||||
assert(resumePackage != null || downloadItem != null) {
|
assert(resumePackage != null || downloadItem != null) {
|
||||||
|
|
@ -26,56 +35,66 @@ object DownloadObjects {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Loop through the current download instances to see if it is currently downloading. Also includes link loading. */
|
/** Loop through the current download instances to see if it is currently downloading. Also includes link loading. */
|
||||||
|
@JsonIgnore
|
||||||
fun isCurrentlyDownloading(): Boolean {
|
fun isCurrentlyDownloading(): Boolean {
|
||||||
return DownloadQueueService.downloadInstances.value.any { it.downloadQueueWrapper.id == this.id }
|
return DownloadQueueService.downloadInstances.value.any { it.downloadQueueWrapper.id == this.id }
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonProperty("id")
|
@JsonProperty("id") @SerialName("id")
|
||||||
val id = resumePackage?.item?.ep?.id ?: downloadItem!!.episode.id
|
val id = resumePackage?.item?.ep?.id ?: downloadItem!!.episode.id
|
||||||
|
|
||||||
@JsonProperty("parentId")
|
@JsonProperty("parentId") @SerialName("parentId")
|
||||||
val parentId = resumePackage?.item?.ep?.parentId ?: downloadItem!!.episode.parentId
|
val parentId = resumePackage?.item?.ep?.parentId ?: downloadItem!!.episode.parentId
|
||||||
}
|
}
|
||||||
|
|
||||||
/** General data about the episode and show to start a download from. */
|
/** General data about the episode and show to start a download from. */
|
||||||
|
@Serializable
|
||||||
data class DownloadQueueItem(
|
data class DownloadQueueItem(
|
||||||
@JsonProperty("episode") val episode: ResultEpisode,
|
@JsonProperty("episode") @SerialName("episode") val episode: ResultEpisode,
|
||||||
@JsonProperty("isMovie") val isMovie: Boolean,
|
@JsonProperty("isMovie") @SerialName("isMovie") val isMovie: Boolean,
|
||||||
@JsonProperty("resultName") val resultName: String,
|
@JsonProperty("resultName") @SerialName("resultName") val resultName: String,
|
||||||
@JsonProperty("resultType") val resultType: TvType,
|
@JsonProperty("resultType") @SerialName("resultType") val resultType: TvType,
|
||||||
@JsonProperty("resultPoster") val resultPoster: String?,
|
@JsonProperty("resultPoster") @SerialName("resultPoster") val resultPoster: String?,
|
||||||
@JsonProperty("apiName") val apiName: String,
|
@JsonProperty("apiName") @SerialName("apiName") val apiName: String,
|
||||||
@JsonProperty("resultId") val resultId: Int,
|
@JsonProperty("resultId") @SerialName("resultId") val resultId: Int,
|
||||||
@JsonProperty("resultUrl") val resultUrl: String,
|
@JsonProperty("resultUrl") @SerialName("resultUrl") val resultUrl: String,
|
||||||
@JsonProperty("links") val links: List<ExtractorLink>? = null,
|
@JsonProperty("links") @SerialName("links") val links: List<ExtractorLink>? = null,
|
||||||
@JsonProperty("subs") val subs: List<SubtitleData>? = null,
|
@JsonProperty("subs") @SerialName("subs") val subs: List<SubtitleData>? = null,
|
||||||
) {
|
) {
|
||||||
fun toWrapper(): DownloadQueueWrapper {
|
fun toWrapper(): DownloadQueueWrapper {
|
||||||
return DownloadQueueWrapper(null, this)
|
return DownloadQueueWrapper(null, this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface DownloadCached {
|
||||||
|
val id: Int
|
||||||
|
}
|
||||||
|
|
||||||
abstract class DownloadCached(
|
@OptIn(ExperimentalSerializationApi::class) // KeepGeneratedSerializer is an experimental annotation for now
|
||||||
@JsonProperty("id") open val id: Int,
|
@KeepGeneratedSerializer
|
||||||
)
|
@Serializable(with = DownloadEpisodeCached.Serializer::class)
|
||||||
|
|
||||||
data class DownloadEpisodeCached(
|
data class DownloadEpisodeCached(
|
||||||
@JsonProperty("name") val name: String?,
|
@JsonProperty("name") @SerialName("name") val name: String?,
|
||||||
@JsonProperty("poster") val poster: String?,
|
@JsonProperty("poster") @SerialName("poster") val poster: String?,
|
||||||
@JsonProperty("episode") val episode: Int,
|
@JsonProperty("episode") @SerialName("episode") val episode: Int,
|
||||||
@JsonProperty("season") val season: Int?,
|
@JsonProperty("season") @SerialName("season") val season: Int?,
|
||||||
@JsonProperty("parentId") val parentId: Int,
|
@JsonProperty("parentId") @SerialName("parentId") val parentId: Int,
|
||||||
@JsonProperty("score") var score: Score? = null,
|
@JsonProperty("score") @SerialName("score") var score: Score? = null,
|
||||||
@JsonProperty("description") val description: String?,
|
@JsonProperty("description") @SerialName("description") val description: String?,
|
||||||
@JsonProperty("cacheTime") val cacheTime: Long,
|
@JsonProperty("cacheTime") @SerialName("cacheTime") val cacheTime: Long,
|
||||||
override val id: Int,
|
@JsonProperty("id") @SerialName("id") override val id: Int,
|
||||||
) : DownloadCached(id) {
|
) : DownloadCached {
|
||||||
|
object Serializer : WriteOnlySerializer<DownloadEpisodeCached>(
|
||||||
|
DownloadEpisodeCached.generatedSerializer(),
|
||||||
|
setOf("rating"),
|
||||||
|
)
|
||||||
|
|
||||||
@JsonProperty("rating", access = JsonProperty.Access.WRITE_ONLY)
|
@JsonProperty("rating", access = JsonProperty.Access.WRITE_ONLY)
|
||||||
|
@SerialName("rating")
|
||||||
@Deprecated(
|
@Deprecated(
|
||||||
"`rating` is the old scoring system, use score instead",
|
"`rating` is the old scoring system, use score instead",
|
||||||
replaceWith = ReplaceWith("score"),
|
replaceWith = ReplaceWith("score"),
|
||||||
level = DeprecationLevel.ERROR
|
level = DeprecationLevel.ERROR,
|
||||||
)
|
)
|
||||||
var rating: Int? = null
|
var rating: Int? = null
|
||||||
set(value) {
|
set(value) {
|
||||||
|
|
@ -87,74 +106,81 @@ object DownloadObjects {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** What to display to the user for a downloaded show/movie. Includes info such as name, poster and url */
|
/** What to display to the user for a downloaded show/movie. Includes info such as name, poster and url */
|
||||||
|
@Serializable
|
||||||
data class DownloadHeaderCached(
|
data class DownloadHeaderCached(
|
||||||
@JsonProperty("apiName") val apiName: String,
|
@JsonProperty("apiName") @SerialName("apiName") val apiName: String,
|
||||||
@JsonProperty("url") val url: String,
|
@JsonProperty("url") @SerialName("url") val url: String,
|
||||||
@JsonProperty("type") val type: TvType,
|
@JsonProperty("type") @SerialName("type") val type: TvType,
|
||||||
@JsonProperty("name") val name: String,
|
@JsonProperty("name") @SerialName("name") val name: String,
|
||||||
@JsonProperty("poster") val poster: String?,
|
@JsonProperty("poster") @SerialName("poster") val poster: String?,
|
||||||
@JsonProperty("cacheTime") val cacheTime: Long,
|
@JsonProperty("cacheTime") @SerialName("cacheTime") val cacheTime: Long,
|
||||||
override val id: Int,
|
@JsonProperty("id") @SerialName("id") override val id: Int,
|
||||||
) : DownloadCached(id)
|
) : DownloadCached
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class DownloadResumePackage(
|
data class DownloadResumePackage(
|
||||||
@JsonProperty("item") val item: DownloadItem,
|
@JsonProperty("item") @SerialName("item") val item: DownloadItem,
|
||||||
/** Tills which link should get resumed */
|
/** Tills which link should get resumed */
|
||||||
@JsonProperty("linkIndex") val linkIndex: Int?,
|
@JsonProperty("linkIndex") @SerialName("linkIndex") val linkIndex: Int?,
|
||||||
) {
|
) {
|
||||||
fun toWrapper(): DownloadQueueWrapper {
|
fun toWrapper(): DownloadQueueWrapper {
|
||||||
return DownloadQueueWrapper(this, null)
|
return DownloadQueueWrapper(this, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class DownloadItem(
|
data class DownloadItem(
|
||||||
@JsonProperty("source") val source: String?,
|
@JsonProperty("source") @SerialName("source") val source: String?,
|
||||||
@JsonProperty("folder") val folder: String?,
|
@JsonProperty("folder") @SerialName("folder") val folder: String?,
|
||||||
@JsonProperty("ep") val ep: DownloadEpisodeMetadata,
|
@JsonProperty("ep") @SerialName("ep") val ep: DownloadEpisodeMetadata,
|
||||||
@JsonProperty("links") val links: List<ExtractorLink>,
|
@JsonProperty("links") @SerialName("links") val links: List<ExtractorLink>,
|
||||||
)
|
)
|
||||||
|
|
||||||
/** Metadata for a specific episode and how to display it. */
|
/** Metadata for a specific episode and how to display it. */
|
||||||
|
@Serializable
|
||||||
data class DownloadEpisodeMetadata(
|
data class DownloadEpisodeMetadata(
|
||||||
@JsonProperty("id") val id: Int,
|
@JsonProperty("id") @SerialName("id") val id: Int,
|
||||||
@JsonProperty("parentId") val parentId: Int,
|
@JsonProperty("parentId") @SerialName("parentId") val parentId: Int,
|
||||||
@JsonProperty("mainName") val mainName: String,
|
@JsonProperty("mainName") @SerialName("mainName") val mainName: String,
|
||||||
@JsonProperty("sourceApiName") val sourceApiName: String?,
|
@JsonProperty("sourceApiName") @SerialName("sourceApiName") val sourceApiName: String?,
|
||||||
@JsonProperty("poster") val poster: String?,
|
@JsonProperty("poster") @SerialName("poster") val poster: String?,
|
||||||
@JsonProperty("name") val name: String?,
|
@JsonProperty("name") @SerialName("name") val name: String?,
|
||||||
@JsonProperty("season") val season: Int?,
|
@JsonProperty("season") @SerialName("season") val season: Int?,
|
||||||
@JsonProperty("episode") val episode: Int?,
|
@JsonProperty("episode") @SerialName("episode") val episode: Int?,
|
||||||
@JsonProperty("type") val type: TvType?,
|
@JsonProperty("type") @SerialName("type") val type: TvType?,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class DownloadedFileInfo(
|
data class DownloadedFileInfo(
|
||||||
@JsonProperty("totalBytes") val totalBytes: Long,
|
@JsonProperty("totalBytes") @SerialName("totalBytes") val totalBytes: Long,
|
||||||
@JsonProperty("relativePath") val relativePath: String,
|
@JsonProperty("relativePath") @SerialName("relativePath") val relativePath: String,
|
||||||
@JsonProperty("displayName") val displayName: String,
|
@JsonProperty("displayName") @SerialName("displayName") val displayName: String,
|
||||||
@JsonProperty("extraInfo") val extraInfo: String? = null,
|
@JsonProperty("extraInfo") @SerialName("extraInfo") val extraInfo: String? = null,
|
||||||
@JsonProperty("basePath") val basePath: String? = null, // null is for legacy downloads. See getBasePath()
|
@JsonProperty("basePath") @SerialName("basePath") val basePath: String? = null, // null is for legacy downloads. See getBasePath()
|
||||||
// Hash of the link associated with this DownloadFile, used so not override old data in the DownloadedFileInfo
|
// Hash of the link associated with this DownloadFile, used so not override old data in the DownloadedFileInfo
|
||||||
@JsonProperty("linkHash") val linkHash : Int? = null
|
@JsonProperty("linkHash") @SerialName("linkHash") val linkHash: Int? = null,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
@SkipSerializationTest // Uri has issues with Jackson
|
||||||
data class DownloadedFileInfoResult(
|
data class DownloadedFileInfoResult(
|
||||||
@JsonProperty("fileLength") val fileLength: Long,
|
@JsonProperty("fileLength") @SerialName("fileLength") val fileLength: Long,
|
||||||
@JsonProperty("totalBytes") val totalBytes: Long,
|
@JsonProperty("totalBytes") @SerialName("totalBytes") val totalBytes: Long,
|
||||||
@JsonProperty("path") val path: Uri,
|
@JsonProperty("path") @SerialName("path")
|
||||||
|
@Serializable(with = UriSerializer::class)
|
||||||
|
val path: Uri,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class ResumeWatching(
|
data class ResumeWatching(
|
||||||
@JsonProperty("parentId") val parentId: Int,
|
@JsonProperty("parentId") @SerialName("parentId") val parentId: Int,
|
||||||
@JsonProperty("episodeId") val episodeId: Int?,
|
@JsonProperty("episodeId") @SerialName("episodeId") val episodeId: Int?,
|
||||||
@JsonProperty("episode") val episode: Int?,
|
@JsonProperty("episode") @SerialName("episode") val episode: Int?,
|
||||||
@JsonProperty("season") val season: Int?,
|
@JsonProperty("season") @SerialName("season") val season: Int?,
|
||||||
@JsonProperty("updateTime") val updateTime: Long,
|
@JsonProperty("updateTime") @SerialName("updateTime") val updateTime: Long,
|
||||||
@JsonProperty("isFromDownload") val isFromDownload: Boolean,
|
@JsonProperty("isFromDownload") @SerialName("isFromDownload") val isFromDownload: Boolean,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
data class DownloadStatus(
|
data class DownloadStatus(
|
||||||
/** if you should retry with the same args and hope for a better result */
|
/** if you should retry with the same args and hope for a better result */
|
||||||
val retrySame: Boolean,
|
val retrySame: Boolean,
|
||||||
|
|
@ -164,20 +190,19 @@ object DownloadObjects {
|
||||||
val success: Boolean,
|
val success: Boolean,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
data class CreateNotificationMetadata(
|
data class CreateNotificationMetadata(
|
||||||
val type: VideoDownloadManager.DownloadType,
|
val type: VideoDownloadManager.DownloadType,
|
||||||
val bytesDownloaded: Long,
|
val bytesDownloaded: Long,
|
||||||
val bytesTotal: Long,
|
val bytesTotal: Long,
|
||||||
val hlsProgress: Long? = null,
|
val hlsProgress: Long? = null,
|
||||||
val hlsTotal: Long? = null,
|
val hlsTotal: Long? = null,
|
||||||
val bytesPerSecond: Long
|
val bytesPerSecond: Long,
|
||||||
)
|
)
|
||||||
|
|
||||||
data class StreamData(
|
data class StreamData(
|
||||||
private val fileLength: Long,
|
private val fileLength: Long,
|
||||||
val file: SafeFile,
|
val file: SafeFile,
|
||||||
//val fileStream: OutputStream,
|
// val fileStream: OutputStream,
|
||||||
) {
|
) {
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
fun open(): OutputStream {
|
fun open(): OutputStream {
|
||||||
|
|
@ -198,9 +223,11 @@ object DownloadObjects {
|
||||||
val exists: Boolean get() = file.exists() == true
|
val exists: Boolean get() = file.exists() == true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
/** bytes have the size end-start where the byte range is [start,end)
|
* Bytes have the size end-start where the byte range is [start,end)
|
||||||
* note that ByteArray is a pointer and therefore cant be stored without cloning it */
|
* note that ByteArray is a pointer and therefore can't be stored
|
||||||
|
* without cloning it.
|
||||||
|
*/
|
||||||
data class LazyStreamDownloadResponse(
|
data class LazyStreamDownloadResponse(
|
||||||
val bytes: ByteArray,
|
val bytes: ByteArray,
|
||||||
val startByte: Long,
|
val startByte: Long,
|
||||||
|
|
@ -221,4 +248,4 @@ object DownloadObjects {
|
||||||
return Objects.hash(startByte, endByte)
|
return Objects.hash(startByte, endByte)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@
|
||||||
</androidx.cardview.widget.CardView>
|
</androidx.cardview.widget.CardView>
|
||||||
|
|
||||||
<androidx.cardview.widget.CardView
|
<androidx.cardview.widget.CardView
|
||||||
|
android:id="@+id/voice_actor_image_holder2"
|
||||||
android:layout_width="70dp"
|
android:layout_width="70dp"
|
||||||
android:layout_height="70dp"
|
android:layout_height="70dp"
|
||||||
android:foreground="@drawable/outline_drawable"
|
android:foreground="@drawable/outline_drawable"
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ juniversalchardet = "2.5.0"
|
||||||
kotlinGradlePlugin = "2.3.20"
|
kotlinGradlePlugin = "2.3.20"
|
||||||
kotlinxAtomicfu = "0.33.0"
|
kotlinxAtomicfu = "0.33.0"
|
||||||
kotlinxCollectionsImmutable = "0.4.0"
|
kotlinxCollectionsImmutable = "0.4.0"
|
||||||
kotlinxCoroutinesCore = "1.11.0"
|
kotlinxCoroutines = "1.11.0"
|
||||||
kotlinxDatetime = "0.8.0"
|
kotlinxDatetime = "0.8.0"
|
||||||
kotlinxSerializationJson = "1.11.0"
|
kotlinxSerializationJson = "1.11.0"
|
||||||
ksoup = "0.2.6"
|
ksoup = "0.2.6"
|
||||||
|
|
@ -63,7 +63,7 @@ compileSdk = "36"
|
||||||
targetSdk = "36"
|
targetSdk = "36"
|
||||||
|
|
||||||
versionCode = "68"
|
versionCode = "68"
|
||||||
versionName = "4.7.0"
|
versionName = "4.8.0"
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
activity-ktx = { module = "androidx.activity:activity-ktx", version.ref = "activityKtx" }
|
activity-ktx = { module = "androidx.activity:activity-ktx", version.ref = "activityKtx" }
|
||||||
|
|
@ -96,7 +96,8 @@ kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref =
|
||||||
kotlin-test = { group = "org.jetbrains.kotlin", name = "kotlin-test", version.ref = "kotlinGradlePlugin" }
|
kotlin-test = { group = "org.jetbrains.kotlin", name = "kotlin-test", version.ref = "kotlinGradlePlugin" }
|
||||||
kotlinx-atomicfu = { module = "org.jetbrains.kotlinx:atomicfu", version.ref = "kotlinxAtomicfu" }
|
kotlinx-atomicfu = { module = "org.jetbrains.kotlinx:atomicfu", version.ref = "kotlinxAtomicfu" }
|
||||||
kotlinx-collections-immutable = { module = "org.jetbrains.kotlinx:kotlinx-collections-immutable", version.ref = "kotlinxCollectionsImmutable" }
|
kotlinx-collections-immutable = { module = "org.jetbrains.kotlinx:kotlinx-collections-immutable", version.ref = "kotlinxCollectionsImmutable" }
|
||||||
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinxCoroutinesCore" }
|
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinxCoroutines" }
|
||||||
|
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinxCoroutines" }
|
||||||
kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinxDatetime" }
|
kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinxDatetime" }
|
||||||
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerializationJson" }
|
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerializationJson" }
|
||||||
ksoup = { module = "com.fleeksoft.ksoup:ksoup", version.ref = "ksoup" }
|
ksoup = { module = "com.fleeksoft.ksoup:ksoup", version.ref = "ksoup" }
|
||||||
|
|
|
||||||
15
library/README.md
Normal file
15
library/README.md
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
## CloudStream extension library
|
||||||
|
|
||||||
|
This is the official API surface for all CloudStream plugins.
|
||||||
|
|
||||||
|
To ensure that all plugins work on both the stable release and pre-release we must have
|
||||||
|
binary compatibility on all changes. All new changes must be marked with `@Prerelease` to
|
||||||
|
prevent accidental usage among extension developers.
|
||||||
|
|
||||||
|
We use Kotlin binary compatibility validation using:
|
||||||
|
|
||||||
|
``./gradlew checkKotlinAbi``
|
||||||
|
|
||||||
|
If you for some reason must update the binary compatibility then manually edit `api/jvm/library.api` or use:
|
||||||
|
|
||||||
|
``./gradlew updateKotlinAbi``
|
||||||
7484
library/api/jvm/library.api
Normal file
7484
library/api/jvm/library.api
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -69,13 +69,11 @@ kotlin {
|
||||||
implementation(libs.rhino) // Run JavaScript
|
implementation(libs.rhino) // Run JavaScript
|
||||||
implementation(libs.tmdb.java) // TMDB API v3 Wrapper Made with RetroFit
|
implementation(libs.tmdb.java) // TMDB API v3 Wrapper Made with RetroFit
|
||||||
implementation(libs.bundles.cryptography) // Cryptography
|
implementation(libs.bundles.cryptography) // Cryptography
|
||||||
|
|
||||||
// Deprecated; will be removed once extensions have time to migrate from using it
|
|
||||||
implementation("me.xdrop:fuzzywuzzy:1.4.0")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
commonTest.dependencies {
|
commonTest.dependencies {
|
||||||
implementation(libs.kotlin.test)
|
implementation(libs.kotlin.test)
|
||||||
|
implementation(libs.kotlinx.coroutines.test)
|
||||||
}
|
}
|
||||||
|
|
||||||
val jvmCommonMain by creating {
|
val jvmCommonMain by creating {
|
||||||
|
|
@ -89,6 +87,18 @@ kotlin {
|
||||||
androidMain { dependsOn(jvmCommonMain) }
|
androidMain { dependsOn(jvmCommonMain) }
|
||||||
jvmMain { dependsOn(jvmCommonMain) }
|
jvmMain { dependsOn(jvmCommonMain) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(org.jetbrains.kotlin.gradle.dsl.abi.ExperimentalAbiValidation::class)
|
||||||
|
// https://kotlinlang.org/docs/gradle-binary-compatibility-validation.html
|
||||||
|
abiValidation {
|
||||||
|
enabled.set(true)
|
||||||
|
this.filters {
|
||||||
|
exclude {
|
||||||
|
annotatedWith.add("com.lagradost.cloudstream3.Prerelease")
|
||||||
|
annotatedWith.add("com.lagradost.cloudstream3.InternalAPI")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType<KotlinJvmCompile> {
|
tasks.withType<KotlinJvmCompile> {
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,20 @@
|
||||||
package com.lagradost.cloudstream3.utils
|
package com.lagradost.cloudstream3.utils
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import androidx.annotation.AnyThread
|
import androidx.annotation.AnyThread
|
||||||
import androidx.annotation.MainThread
|
import androidx.annotation.MainThread
|
||||||
|
|
||||||
|
@SuppressLint("ThreadConstraint") // mainLooper.isCurrentThread does not switch the context
|
||||||
@AnyThread
|
@AnyThread
|
||||||
actual fun runOnMainThreadNative(@MainThread work: () -> Unit) {
|
actual fun runOnMainThreadNative(@MainThread work: () -> Unit) {
|
||||||
val mainHandler = Handler(Looper.getMainLooper())
|
val mainLooper = Looper.getMainLooper()
|
||||||
mainHandler.post {
|
if (mainLooper.isCurrentThread) {
|
||||||
|
// Do the work directly if we already are on the main thread, no need to enqueue it
|
||||||
work()
|
work()
|
||||||
|
} else {
|
||||||
|
// Otherwise post it to the other main thread
|
||||||
|
Handler(mainLooper).post(work)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,8 @@ import kotlinx.datetime.format.byUnicodePattern
|
||||||
import kotlinx.datetime.format.char
|
import kotlinx.datetime.format.char
|
||||||
import kotlinx.datetime.format.parse
|
import kotlinx.datetime.format.parse
|
||||||
import kotlinx.datetime.toInstant
|
import kotlinx.datetime.toInstant
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import kotlin.io.encoding.Base64
|
import kotlin.io.encoding.Base64
|
||||||
import kotlin.jvm.JvmName
|
import kotlin.jvm.JvmName
|
||||||
|
|
@ -95,7 +97,6 @@ class ErrorLoadingException(message: String? = null) : Exception(message)
|
||||||
|
|
||||||
//val baseHeader = mapOf("User-Agent" to USER_AGENT)
|
//val baseHeader = mapOf("User-Agent" to USER_AGENT)
|
||||||
|
|
||||||
@Prerelease
|
|
||||||
val json = Json {
|
val json = Json {
|
||||||
encodeDefaults = true
|
encodeDefaults = true
|
||||||
explicitNulls = false
|
explicitNulls = false
|
||||||
|
|
@ -325,7 +326,7 @@ object APIHolder {
|
||||||
).toJson().toRequestBody(RequestBodyTypes.JSON.toMediaTypeOrNull())
|
).toJson().toRequestBody(RequestBodyTypes.JSON.toMediaTypeOrNull())
|
||||||
|
|
||||||
return app.post("https://graphql.anilist.co", requestBody = data)
|
return app.post("https://graphql.anilist.co", requestBody = data)
|
||||||
.parsedSafe()
|
.parsedSafe<AniSearch>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -393,18 +394,19 @@ const val PROVIDER_STATUS_SLOW = 2
|
||||||
const val PROVIDER_STATUS_OK = 1
|
const val PROVIDER_STATUS_OK = 1
|
||||||
const val PROVIDER_STATUS_DOWN = 0
|
const val PROVIDER_STATUS_DOWN = 0
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class ProvidersInfoJson(
|
data class ProvidersInfoJson(
|
||||||
@JsonProperty("name") var name: String,
|
@JsonProperty("name") @SerialName("name") var name: String,
|
||||||
@JsonProperty("url") var url: String,
|
@JsonProperty("url") @SerialName("url") var url: String,
|
||||||
@JsonProperty("credentials") var credentials: String? = null,
|
@JsonProperty("credentials") @SerialName("credentials") var credentials: String? = null,
|
||||||
@JsonProperty("status") var status: Int,
|
@JsonProperty("status") @SerialName("status") var status: Int,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class SettingsJson(
|
data class SettingsJson(
|
||||||
@JsonProperty("enableAdult") var enableAdult: Boolean = false,
|
@JsonProperty("enableAdult") @SerialName("enableAdult") var enableAdult: Boolean = false,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
data class MainPageData(
|
data class MainPageData(
|
||||||
val name: String,
|
val name: String,
|
||||||
val data: String,
|
val data: String,
|
||||||
|
|
@ -797,13 +799,10 @@ fun fixTitle(str: String): String {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Deprecated(
|
||||||
* Get rhino context in a safe way as it needs to be initialized on the main thread.
|
message = "Use newJsContext or evalJs instead.",
|
||||||
*
|
level = DeprecationLevel.WARNING,
|
||||||
* Make sure you get the scope using: val scope: Scriptable = rhino.initSafeStandardObjects()
|
)
|
||||||
*
|
|
||||||
* Use like the following: rhino.evaluateString(scope, js, "JavaScript", 1, null)
|
|
||||||
**/
|
|
||||||
suspend fun getRhinoContext(): org.mozilla.javascript.Context {
|
suspend fun getRhinoContext(): org.mozilla.javascript.Context {
|
||||||
return Coroutines.mainWork {
|
return Coroutines.mainWork {
|
||||||
val rhino = org.mozilla.javascript.Context.enter()
|
val rhino = org.mozilla.javascript.Context.enter()
|
||||||
|
|
@ -870,10 +869,10 @@ enum class DubStatus(val id: Int) {
|
||||||
* of this as a decimal class specifically for ratings.
|
* of this as a decimal class specifically for ratings.
|
||||||
* */
|
* */
|
||||||
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
|
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
|
||||||
|
@Serializable
|
||||||
class Score private constructor(
|
class Score private constructor(
|
||||||
/** Decimal between [0, 10^9] representing the min score and max score respectively */
|
/** Decimal between [0, 10^9] representing the min score and max score respectively */
|
||||||
@JsonProperty("data")
|
@JsonProperty("data") @SerialName("data") private val data: Int,
|
||||||
private val data: Int,
|
|
||||||
) {
|
) {
|
||||||
override fun hashCode(): Int = this.data.hashCode()
|
override fun hashCode(): Int = this.data.hashCode()
|
||||||
override fun equals(other: Any?): Boolean = other is Score && this.data == other.data
|
override fun equals(other: Any?): Boolean = other is Score && this.data == other.data
|
||||||
|
|
@ -1093,7 +1092,6 @@ enum class TvType(value: Int?) {
|
||||||
|
|
||||||
Audio(16),
|
Audio(16),
|
||||||
Podcast(17),
|
Podcast(17),
|
||||||
@Prerelease
|
|
||||||
Video(18),
|
Video(18),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1199,9 +1197,10 @@ suspend fun newSubtitleFile(
|
||||||
* @see newAudioFile
|
* @see newAudioFile
|
||||||
* */
|
* */
|
||||||
@ConsistentCopyVisibility
|
@ConsistentCopyVisibility
|
||||||
|
@Serializable
|
||||||
data class AudioFile internal constructor(
|
data class AudioFile internal constructor(
|
||||||
var url: String,
|
@JsonProperty("url") @SerialName("url") var url: String,
|
||||||
var headers: Map<String, String>? = null
|
@JsonProperty("headers") @SerialName("headers") var headers: Map<String, String>? = null,
|
||||||
)
|
)
|
||||||
|
|
||||||
/** Creates an AudioFile with optional initializer for setting additional properties.
|
/** Creates an AudioFile with optional initializer for setting additional properties.
|
||||||
|
|
@ -1824,7 +1823,7 @@ interface LoadResponse {
|
||||||
|
|
||||||
/** Read the id string to get all other ids */
|
/** Read the id string to get all other ids */
|
||||||
fun readIdFromString(idString: String?): Map<SimklSyncServices, String> {
|
fun readIdFromString(idString: String?): Map<SimklSyncServices, String> {
|
||||||
return tryParseJson(idString) ?: return emptyMap()
|
return tryParseJson<Map<SimklSyncServices, String>>(idString) ?: return emptyMap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun LoadResponse.isMovie(): Boolean {
|
fun LoadResponse.isMovie(): Boolean {
|
||||||
|
|
@ -2178,10 +2177,11 @@ data class NextAiring(
|
||||||
* @param name To be shown next to the season like "Season $displaySeason $name" but if displaySeason is null then "$name"
|
* @param name To be shown next to the season like "Season $displaySeason $name" but if displaySeason is null then "$name"
|
||||||
* @param displaySeason What to be displayed next to the season name, if null then the name is the only thing shown.
|
* @param displaySeason What to be displayed next to the season name, if null then the name is the only thing shown.
|
||||||
* */
|
* */
|
||||||
|
@Serializable
|
||||||
data class SeasonData(
|
data class SeasonData(
|
||||||
val season: Int,
|
@JsonProperty("season") @SerialName("season") val season: Int,
|
||||||
val name: String? = null,
|
@JsonProperty("name") @SerialName("name") val name: String? = null,
|
||||||
val displaySeason: Int? = null, // will use season if null
|
@JsonProperty("displaySeason") @SerialName("displaySeason") val displaySeason: Int? = null, // will use season if null
|
||||||
)
|
)
|
||||||
|
|
||||||
/** Abstract interface of EpisodeResponse */
|
/** Abstract interface of EpisodeResponse */
|
||||||
|
|
@ -2551,21 +2551,18 @@ fun Episode.addDate(date: String?, format: String = "yyyy-MM-dd") {
|
||||||
}.onFailure { logError(it) }.getOrNull()
|
}.onFailure { logError(it) }.getOrNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Prerelease
|
|
||||||
fun Episode.addDate(date: LocalDate?) {
|
fun Episode.addDate(date: LocalDate?) {
|
||||||
this.date = date?.atStartOfDayIn(TimeZone.currentSystemDefault())?.toEpochMilliseconds()
|
this.date = date?.atStartOfDayIn(TimeZone.currentSystemDefault())?.toEpochMilliseconds()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Prerelease
|
|
||||||
fun Episode.addDate(date: Instant?) {
|
fun Episode.addDate(date: Instant?) {
|
||||||
this.date = date?.toEpochMilliseconds()
|
this.date = date?.toEpochMilliseconds()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecate after next stable
|
@Deprecated(
|
||||||
/* @Deprecated(
|
|
||||||
message = "Use addDate with LocalDate, Instant, or String instead.",
|
message = "Use addDate with LocalDate, Instant, or String instead.",
|
||||||
level = DeprecationLevel.WARNING,
|
level = DeprecationLevel.WARNING,
|
||||||
) */
|
)
|
||||||
fun Episode.addDate(date: java.util.Date?) {
|
fun Episode.addDate(date: java.util.Date?) {
|
||||||
this.date = date?.time
|
this.date = date?.time
|
||||||
}
|
}
|
||||||
|
|
@ -2703,7 +2700,6 @@ fun fetchUrls(text: String?): List<String> {
|
||||||
return linkRegex.findAll(text).map { it.value.trim().removeSurrounding("\"") }.toList()
|
return linkRegex.findAll(text).map { it.value.trim().removeSurrounding("\"") }.toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Prerelease
|
|
||||||
fun isUpcoming(dateString: String?): Boolean {
|
fun isUpcoming(dateString: String?): Boolean {
|
||||||
return runCatching {
|
return runCatching {
|
||||||
val fmt = DateTimeComponents.Format {
|
val fmt = DateTimeComponents.Format {
|
||||||
|
|
@ -2739,32 +2735,38 @@ data class Tracker(
|
||||||
val cover: String? = null,
|
val cover: String? = null,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class AniSearch(
|
data class AniSearch(
|
||||||
@JsonProperty("data") var data: Data? = Data()
|
@JsonProperty("data") @SerialName("data") var data: Data? = Data(),
|
||||||
) {
|
) {
|
||||||
|
@Serializable
|
||||||
data class Data(
|
data class Data(
|
||||||
@JsonProperty("Page") var page: Page? = Page()
|
@JsonProperty("Page") @SerialName("Page") var page: Page? = Page(),
|
||||||
) {
|
) {
|
||||||
|
@Serializable
|
||||||
data class Page(
|
data class Page(
|
||||||
@JsonProperty("media") var media: ArrayList<Media> = arrayListOf()
|
@JsonProperty("media") @SerialName("media") var media: ArrayList<Media> = arrayListOf(),
|
||||||
) {
|
) {
|
||||||
|
@Serializable
|
||||||
data class Media(
|
data class Media(
|
||||||
@JsonProperty("title") var title: Title? = null,
|
@JsonProperty("title") @SerialName("title") var title: Title? = null,
|
||||||
@JsonProperty("id") var id: Int? = null,
|
@JsonProperty("id") @SerialName("id") var id: Int? = null,
|
||||||
@JsonProperty("idMal") var idMal: Int? = null,
|
@JsonProperty("idMal") @SerialName("idMal") var idMal: Int? = null,
|
||||||
@JsonProperty("seasonYear") var seasonYear: Int? = null,
|
@JsonProperty("seasonYear") @SerialName("seasonYear") var seasonYear: Int? = null,
|
||||||
@JsonProperty("format") var format: String? = null,
|
@JsonProperty("format") @SerialName("format") var format: String? = null,
|
||||||
@JsonProperty("coverImage") var coverImage: CoverImage? = null,
|
@JsonProperty("coverImage") @SerialName("coverImage") var coverImage: CoverImage? = null,
|
||||||
@JsonProperty("bannerImage") var bannerImage: String? = null,
|
@JsonProperty("bannerImage") @SerialName("bannerImage") var bannerImage: String? = null,
|
||||||
) {
|
) {
|
||||||
|
@Serializable
|
||||||
data class CoverImage(
|
data class CoverImage(
|
||||||
@JsonProperty("extraLarge") var extraLarge: String? = null,
|
@JsonProperty("extraLarge") @SerialName("extraLarge") var extraLarge: String? = null,
|
||||||
@JsonProperty("large") var large: String? = null,
|
@JsonProperty("large") @SerialName("large") var large: String? = null,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class Title(
|
data class Title(
|
||||||
@JsonProperty("romaji") var romaji: String? = null,
|
@JsonProperty("romaji") @SerialName("romaji") var romaji: String? = null,
|
||||||
@JsonProperty("english") var english: String? = null,
|
@JsonProperty("english") @SerialName("english") var english: String? = null,
|
||||||
) {
|
) {
|
||||||
fun isMatchingTitles(title: String?): Boolean {
|
fun isMatchingTitles(title: String?): Boolean {
|
||||||
if (title == null) return false
|
if (title == null) return false
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,6 @@ var app = Requests(responseParser = jsonResponseParser).apply {
|
||||||
|
|
||||||
/** Same as the default app networking helper, but this instance ignores SSL certificates.
|
/** Same as the default app networking helper, but this instance ignores SSL certificates.
|
||||||
* This should NEVER be used for sensitive networking operations such as logins. Only use this when required. */
|
* This should NEVER be used for sensitive networking operations such as logins. Only use this when required. */
|
||||||
@Prerelease
|
|
||||||
@UnsafeSSL
|
@UnsafeSSL
|
||||||
var insecureApp = Requests(responseParser = jsonResponseParser).apply {
|
var insecureApp = Requests(responseParser = jsonResponseParser).apply {
|
||||||
defaultHeaders = mapOf("user-agent" to USER_AGENT)
|
defaultHeaders = mapOf("user-agent" to USER_AGENT)
|
||||||
|
|
|
||||||
|
|
@ -86,15 +86,15 @@ open class ByseSX : ExtractorApi() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(DelicateCryptographyApi::class)
|
@OptIn(DelicateCryptographyApi::class)
|
||||||
private fun decryptPlayback(playback: Playback): String? {
|
private suspend fun decryptPlayback(playback: Playback): String? {
|
||||||
val keyBytes = buildAesKey(playback)
|
val keyBytes = buildAesKey(playback)
|
||||||
val ivBytes = b64UrlDecode(playback.iv)
|
val ivBytes = b64UrlDecode(playback.iv)
|
||||||
val cipherBytes = b64UrlDecode(playback.payload)
|
val cipherBytes = b64UrlDecode(playback.payload)
|
||||||
|
|
||||||
val aesKey = aesGcm.keyDecoder().decodeFromByteArrayBlocking(AES.Key.Format.RAW, keyBytes)
|
val aesKey = aesGcm.keyDecoder().decodeFromByteArray(AES.Key.Format.RAW, keyBytes)
|
||||||
// 128-bit GCM tag (default)
|
// 128-bit GCM tag (default)
|
||||||
val cipher = aesKey.cipher()
|
val cipher = aesKey.cipher()
|
||||||
val plainBytes = cipher.decryptWithIvBlocking(ivBytes, cipherBytes)
|
val plainBytes = cipher.decryptWithIv(ivBytes, cipherBytes)
|
||||||
|
|
||||||
var jsonStr = plainBytes.decodeToString()
|
var jsonStr = plainBytes.decodeToString()
|
||||||
if (jsonStr.startsWith("\uFEFF")) jsonStr = jsonStr.substring(1)
|
if (jsonStr.startsWith("\uFEFF")) jsonStr = jsonStr.substring(1)
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,6 @@ class MyVidPlay : DoodLaExtractor() {
|
||||||
override var mainUrl = "https://myvidplay.com"
|
override var mainUrl = "https://myvidplay.com"
|
||||||
}
|
}
|
||||||
|
|
||||||
@Prerelease
|
|
||||||
class Playmogo : DoodLaExtractor() {
|
class Playmogo : DoodLaExtractor() {
|
||||||
override var mainUrl = "https://playmogo.com"
|
override var mainUrl = "https://playmogo.com"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,35 +8,33 @@ import com.lagradost.cloudstream3.utils.Qualities
|
||||||
import com.lagradost.cloudstream3.utils.newExtractorLink
|
import com.lagradost.cloudstream3.utils.newExtractorLink
|
||||||
|
|
||||||
open class EmturbovidExtractor : ExtractorApi() {
|
open class EmturbovidExtractor : ExtractorApi() {
|
||||||
override var name = "Emturbovid"
|
override val name = "Emturbovid"
|
||||||
override var mainUrl = "https://emturbovid.com"
|
override val mainUrl = "https://emturbovid.com"
|
||||||
override val requiresReferer = false
|
override val requiresReferer = false
|
||||||
|
|
||||||
override suspend fun getUrl(url: String, referer: String?): List<ExtractorLink>? {
|
override suspend fun getUrl(url: String, referer: String?): List<ExtractorLink>? {
|
||||||
val response = app.get(
|
val response = app.get(url, referer = referer ?: "$mainUrl/")
|
||||||
url, referer = referer ?: "$mainUrl/"
|
val playerScript = response.document
|
||||||
)
|
.select("script")
|
||||||
val playerScript =
|
.first { it.data().contains("var urlPlay") }
|
||||||
response.document.selectXpath("//script[contains(text(),'var urlPlay')]")
|
.html()
|
||||||
.html()
|
|
||||||
|
|
||||||
val sources = mutableListOf<ExtractorLink>()
|
val sources = mutableListOf<ExtractorLink>()
|
||||||
if (playerScript.isNotBlank()) {
|
if (playerScript.isNotBlank()) {
|
||||||
val m3u8Url =
|
val m3u8Url = playerScript.substringAfter("var urlPlay = '").substringBefore("'")
|
||||||
playerScript.substringAfter("var urlPlay = '").substringBefore("'")
|
|
||||||
|
|
||||||
sources.add(
|
sources.add(
|
||||||
newExtractorLink(
|
newExtractorLink(
|
||||||
source = name,
|
source = name,
|
||||||
name = name,
|
name = name,
|
||||||
url = m3u8Url,
|
url = m3u8Url,
|
||||||
type = ExtractorLinkType.M3U8
|
type = ExtractorLinkType.M3U8,
|
||||||
) {
|
) {
|
||||||
this.referer = "$mainUrl/"
|
this.referer = "$mainUrl/"
|
||||||
this.quality = Qualities.Unknown.value
|
this.quality = Qualities.Unknown.value
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return sources
|
return sources
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ import com.lagradost.cloudstream3.utils.newExtractorLink
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@Prerelease
|
|
||||||
class Firestream : ExtractorApi() {
|
class Firestream : ExtractorApi() {
|
||||||
override val name: String = "Firestream"
|
override val name: String = "Firestream"
|
||||||
override val mainUrl: String = "https://firestream.to"
|
override val mainUrl: String = "https://firestream.to"
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ import com.lagradost.cloudstream3.utils.newExtractorLink
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@Prerelease
|
|
||||||
open class Flyfile : ExtractorApi() {
|
open class Flyfile : ExtractorApi() {
|
||||||
override val name: String = "FlyFile"
|
override val name: String = "FlyFile"
|
||||||
override val mainUrl: String = "https://flyfile.app"
|
override val mainUrl: String = "https://flyfile.app"
|
||||||
|
|
|
||||||
|
|
@ -133,12 +133,12 @@ open class Rabbitstream : ExtractorApi() {
|
||||||
return extractedKey to sources
|
return extractedKey to sources
|
||||||
}
|
}
|
||||||
|
|
||||||
private inline fun <reified T> decryptMapped(input: String, key: String): T? {
|
private inline suspend fun <reified T> decryptMapped(input: String, key: String): T? {
|
||||||
val decrypt = decrypt(input, key)
|
val decrypt = decrypt(input, key)
|
||||||
return AppUtils.tryParseJson(decrypt)
|
return AppUtils.tryParseJson(decrypt)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun decrypt(input: String, key: String): String {
|
private suspend fun decrypt(input: String, key: String): String {
|
||||||
return decryptSourceUrl(
|
return decryptSourceUrl(
|
||||||
generateKey(
|
generateKey(
|
||||||
salt = base64DecodeArray(input).copyOfRange(8, 16),
|
salt = base64DecodeArray(input).copyOfRange(8, 16),
|
||||||
|
|
@ -147,7 +147,7 @@ open class Rabbitstream : ExtractorApi() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun generateKey(salt: ByteArray, secret: ByteArray): ByteArray {
|
private suspend fun generateKey(salt: ByteArray, secret: ByteArray): ByteArray {
|
||||||
var key = md5(secret + salt)
|
var key = md5(secret + salt)
|
||||||
var currentKey = key
|
var currentKey = key
|
||||||
while (currentKey.size < 48) {
|
while (currentKey.size < 48) {
|
||||||
|
|
@ -157,18 +157,18 @@ open class Rabbitstream : ExtractorApi() {
|
||||||
return currentKey
|
return currentKey
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun md5(input: ByteArray): ByteArray =
|
private suspend fun md5(input: ByteArray): ByteArray =
|
||||||
md5Hasher.hashBlocking(input)
|
md5Hasher.hash(input)
|
||||||
|
|
||||||
@OptIn(DelicateCryptographyApi::class)
|
@OptIn(DelicateCryptographyApi::class)
|
||||||
private fun decryptSourceUrl(decryptionKey: ByteArray, sourceUrl: String): String {
|
private suspend fun decryptSourceUrl(decryptionKey: ByteArray, sourceUrl: String): String {
|
||||||
val cipherData = base64DecodeArray(sourceUrl)
|
val cipherData = base64DecodeArray(sourceUrl)
|
||||||
val encrypted = cipherData.copyOfRange(16, cipherData.size)
|
val encrypted = cipherData.copyOfRange(16, cipherData.size)
|
||||||
val keyBytes = decryptionKey.copyOfRange(0, 32)
|
val keyBytes = decryptionKey.copyOfRange(0, 32)
|
||||||
val ivBytes = decryptionKey.copyOfRange(32, decryptionKey.size)
|
val ivBytes = decryptionKey.copyOfRange(32, decryptionKey.size)
|
||||||
|
|
||||||
val aesKey = aesCbc.keyDecoder().decodeFromByteArrayBlocking(AES.Key.Format.RAW, keyBytes)
|
val aesKey = aesCbc.keyDecoder().decodeFromByteArray(AES.Key.Format.RAW, keyBytes)
|
||||||
val decryptedData = aesKey.cipher(padding = true).decryptWithIvBlocking(ivBytes, encrypted)
|
val decryptedData = aesKey.cipher(padding = true).decryptWithIv(ivBytes, encrypted)
|
||||||
return decryptedData.decodeToString()
|
return decryptedData.decodeToString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@ import com.lagradost.cloudstream3.app
|
||||||
import com.lagradost.cloudstream3.utils.ExtractorApi
|
import com.lagradost.cloudstream3.utils.ExtractorApi
|
||||||
import com.lagradost.cloudstream3.utils.ExtractorLink
|
import com.lagradost.cloudstream3.utils.ExtractorLink
|
||||||
import com.lagradost.cloudstream3.utils.Qualities
|
import com.lagradost.cloudstream3.utils.Qualities
|
||||||
|
import com.lagradost.cloudstream3.utils.evalJs
|
||||||
import com.lagradost.cloudstream3.utils.newExtractorLink
|
import com.lagradost.cloudstream3.utils.newExtractorLink
|
||||||
import org.mozilla.javascript.Context
|
|
||||||
|
|
||||||
class Watchadsontape : StreamTape() {
|
class Watchadsontape : StreamTape() {
|
||||||
override var mainUrl = "https://watchadsontape.com"
|
override var mainUrl = "https://watchadsontape.com"
|
||||||
|
|
@ -30,24 +30,14 @@ open class StreamTape : ExtractorApi() {
|
||||||
|
|
||||||
override suspend fun getUrl(url: String, referer: String?): List<ExtractorLink>? {
|
override suspend fun getUrl(url: String, referer: String?): List<ExtractorLink>? {
|
||||||
with(app.get(url)) {
|
with(app.get(url)) {
|
||||||
var result =
|
val result =
|
||||||
this.document.select("script").firstOrNull { it.html().contains("botlink').innerHTML") }
|
this.document.select("script").firstOrNull { it.html().contains("botlink').innerHTML") }
|
||||||
?.html()?.lines()?.firstOrNull{ it.contains("botlink').innerHTML") }?.let {
|
?.html()?.lines()?.firstOrNull { it.contains("botlink').innerHTML") }?.let {
|
||||||
val scriptContent =
|
val scriptContent = it.substringAfter(").innerHTML").replaceFirst("=", "var url =")
|
||||||
it.substringAfter(").innerHTML").replaceFirst("=", "var url =")
|
evalJs(scriptContent, "url")?.toString()
|
||||||
val rhino = Context.enter()
|
|
||||||
rhino.setInterpretedMode(true)
|
|
||||||
val scope = rhino.initStandardObjects()
|
|
||||||
var result = ""
|
|
||||||
try {
|
|
||||||
rhino.evaluateString(scope, scriptContent, "url", 1, null)
|
|
||||||
result = scope.get("url", scope).toString()
|
|
||||||
}finally {
|
|
||||||
rhino.close()
|
|
||||||
}
|
|
||||||
result
|
|
||||||
}
|
}
|
||||||
if(!result.isNullOrEmpty()){
|
|
||||||
|
if (!result.isNullOrEmpty()) {
|
||||||
val extractedUrl = "https:${result}&stream=1"
|
val extractedUrl = "https:${result}&stream=1"
|
||||||
return listOf(
|
return listOf(
|
||||||
newExtractorLink(
|
newExtractorLink(
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@ class Ewish : StreamWishExtractor() {
|
||||||
override val mainUrl = "https://embedwish.com"
|
override val mainUrl = "https://embedwish.com"
|
||||||
}
|
}
|
||||||
|
|
||||||
@Prerelease
|
|
||||||
class Hgcloudto : StreamWishExtractor() {
|
class Hgcloudto : StreamWishExtractor() {
|
||||||
override val name = "Hgcloud"
|
override val name = "Hgcloud"
|
||||||
override val mainUrl = "https://Hgcloud.to"
|
override val mainUrl = "https://Hgcloud.to"
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ import com.lagradost.cloudstream3.utils.ExtractorLink
|
||||||
import com.lagradost.cloudstream3.utils.ExtractorLinkType
|
import com.lagradost.cloudstream3.utils.ExtractorLinkType
|
||||||
import com.lagradost.cloudstream3.utils.newExtractorLink
|
import com.lagradost.cloudstream3.utils.newExtractorLink
|
||||||
|
|
||||||
@Prerelease
|
|
||||||
open class Streamcash: ExtractorApi() {
|
open class Streamcash: ExtractorApi() {
|
||||||
override val name: String = "Streamcash"
|
override val name: String = "Streamcash"
|
||||||
override val mainUrl: String = "https://streamcash.to"
|
override val mainUrl: String = "https://streamcash.to"
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,6 @@ package com.lagradost.cloudstream3.extractors
|
||||||
import com.lagradost.cloudstream3.utils.ExtractorLink
|
import com.lagradost.cloudstream3.utils.ExtractorLink
|
||||||
import com.lagradost.cloudstream3.app
|
import com.lagradost.cloudstream3.app
|
||||||
import com.lagradost.cloudstream3.utils.*
|
import com.lagradost.cloudstream3.utils.*
|
||||||
import org.mozilla.javascript.Context
|
|
||||||
import org.mozilla.javascript.EvaluatorException
|
|
||||||
import org.mozilla.javascript.Scriptable
|
|
||||||
|
|
||||||
open class Userload : ExtractorApi() {
|
open class Userload : ExtractorApi() {
|
||||||
override var name = "Userload"
|
override var name = "Userload"
|
||||||
|
|
@ -32,20 +29,11 @@ open class Userload : ExtractorApi() {
|
||||||
return array
|
return array
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun evaluateMath(mathExpression : String): String {
|
private suspend fun evaluateMath(mathExpression: String): String {
|
||||||
val rhino = Context.enter()
|
return jsValueToString(evalJs("eval($mathExpression)"))
|
||||||
rhino.initStandardObjects()
|
|
||||||
rhino.setInterpretedMode(true)
|
|
||||||
val scope: Scriptable = rhino.initStandardObjects()
|
|
||||||
return try {
|
|
||||||
rhino.evaluateString(scope, "eval($mathExpression)", "JavaScript", 1, null).toString()
|
|
||||||
}
|
|
||||||
catch (e: EvaluatorException){
|
|
||||||
""
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun decodeVideoJs(text: String): List<String> {
|
private suspend fun decodeVideoJs(text: String): List<String> {
|
||||||
text.replace("""\s+|/\*.*?\*/""".toRegex(), "")
|
text.replace("""\s+|/\*.*?\*/""".toRegex(), "")
|
||||||
val data = text.split("""+(゚Д゚)[゚o゚]""")[1]
|
val data = text.split("""+(゚Д゚)[゚o゚]""")[1]
|
||||||
val chars = data.split("""+ (゚Д゚)[゚ε゚]+""").drop(1)
|
val chars = data.split("""+ (゚Д゚)[゚ε゚]+""").drop(1)
|
||||||
|
|
@ -68,22 +56,16 @@ open class Userload : ExtractorApi() {
|
||||||
subchar.add(splitInput(v).map { evaluateMath(it).substringBefore(".") }.toString().filter { it.isDigit() })
|
subchar.add(splitInput(v).map { evaluateMath(it).substringBefore(".") }.toString().filter { it.isDigit() })
|
||||||
}
|
}
|
||||||
var txtresult = ""
|
var txtresult = ""
|
||||||
subchar.forEach{
|
subchar.forEach {
|
||||||
txtresult = txtresult.plus(it.toInt(8).toChar())
|
txtresult = txtresult.plus(it.toInt(8).toChar())
|
||||||
}
|
}
|
||||||
val val1 = Regex(""""morocco="((.|\\n)*?)"&mycountry="""").find(txtresult)?.groups?.get(1)?.value.toString().drop(1).dropLast(1)
|
val val1 = Regex(""""morocco="((.|\\n)*?)"&mycountry="""").find(txtresult)?.groups?.get(1)?.value.toString().drop(1).dropLast(1)
|
||||||
val val2 = txtresult.substringAfter("""&mycountry="+""").substringBefore(")")
|
val val2 = txtresult.substringAfter("""&mycountry="+""").substringBefore(")")
|
||||||
|
|
||||||
return listOf(
|
return listOf(val1, val2)
|
||||||
val1,
|
|
||||||
val2
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getUrl(url: String, referer: String?): List<ExtractorLink>? {
|
override suspend fun getUrl(url: String, referer: String?): List<ExtractorLink>? {
|
||||||
|
|
||||||
val extractedLinksList: MutableList<ExtractorLink> = mutableListOf()
|
val extractedLinksList: MutableList<ExtractorLink> = mutableListOf()
|
||||||
|
|
||||||
val response = app.get(url).text
|
val response = app.get(url).text
|
||||||
|
|
@ -113,4 +95,4 @@ open class Userload : ExtractorApi() {
|
||||||
|
|
||||||
return extractedLinksList
|
return extractedLinksList
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,9 @@ import com.lagradost.cloudstream3.utils.ExtractorApi
|
||||||
import com.lagradost.cloudstream3.utils.ExtractorLink
|
import com.lagradost.cloudstream3.utils.ExtractorLink
|
||||||
import com.lagradost.cloudstream3.utils.newExtractorLink
|
import com.lagradost.cloudstream3.utils.newExtractorLink
|
||||||
|
|
||||||
@Prerelease
|
|
||||||
open class Vids : ExtractorApi() {
|
open class Vids : ExtractorApi() {
|
||||||
override val name: String = "Vids"
|
override val name: String = "Vids"
|
||||||
override val mainUrl: String = " https://vids.st"
|
override val mainUrl: String = "https://vids.st"
|
||||||
override val requiresReferer: Boolean = false
|
override val requiresReferer: Boolean = false
|
||||||
|
|
||||||
private val streamUrlRegex = Regex("""const url = "(.*?)";""")
|
private val streamUrlRegex = Regex("""const url = "(.*?)";""")
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import dev.whyoleg.cryptography.CryptographyProvider
|
||||||
import dev.whyoleg.cryptography.DelicateCryptographyApi
|
import dev.whyoleg.cryptography.DelicateCryptographyApi
|
||||||
import dev.whyoleg.cryptography.algorithms.AES
|
import dev.whyoleg.cryptography.algorithms.AES
|
||||||
import dev.whyoleg.cryptography.algorithms.MD5
|
import dev.whyoleg.cryptography.algorithms.MD5
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
|
@ -20,8 +21,7 @@ object AesHelper {
|
||||||
private val md5Hasher = provider.get(MD5).hasher()
|
private val md5Hasher = provider.get(MD5).hasher()
|
||||||
|
|
||||||
@OptIn(DelicateCryptographyApi::class)
|
@OptIn(DelicateCryptographyApi::class)
|
||||||
@Prerelease
|
suspend fun cryptoAESHandler(
|
||||||
fun cryptoAESHandler(
|
|
||||||
data: String,
|
data: String,
|
||||||
pass: ByteArray,
|
pass: ByteArray,
|
||||||
encrypt: Boolean = true,
|
encrypt: Boolean = true,
|
||||||
|
|
@ -35,22 +35,21 @@ object AesHelper {
|
||||||
saltLength = parse.s.length / 2,
|
saltLength = parse.s.length / 2,
|
||||||
) ?: return null
|
) ?: return null
|
||||||
|
|
||||||
val aesKey = aesCbc.keyDecoder().decodeFromByteArrayBlocking(AES.Key.Format.RAW, key)
|
val aesKey = aesCbc.keyDecoder().decodeFromByteArray(AES.Key.Format.RAW, key)
|
||||||
val cipher = aesKey.cipher(padding = padding)
|
val cipher = aesKey.cipher(padding = padding)
|
||||||
|
|
||||||
return if (!encrypt) {
|
return if (!encrypt) {
|
||||||
val plainBytes = cipher.decryptWithIvBlocking(iv, base64DecodeArray(parse.ct))
|
val plainBytes = cipher.decryptWithIv(iv, base64DecodeArray(parse.ct))
|
||||||
plainBytes.decodeToString()
|
plainBytes.decodeToString()
|
||||||
} else {
|
} else {
|
||||||
base64Encode(cipher.encryptWithIvBlocking(iv, parse.ct.encodeToByteArray()))
|
base64Encode(cipher.encryptWithIv(iv, parse.ct.encodeToByteArray()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecate after next stable
|
@Deprecated(
|
||||||
/* @Deprecated(
|
|
||||||
message = "Set padding = false for no padding",
|
message = "Set padding = false for no padding",
|
||||||
level = DeprecationLevel.WARNING,
|
level = DeprecationLevel.WARNING,
|
||||||
) */
|
)
|
||||||
fun cryptoAESHandler(
|
fun cryptoAESHandler(
|
||||||
data: String,
|
data: String,
|
||||||
pass: ByteArray,
|
pass: ByteArray,
|
||||||
|
|
@ -60,7 +59,7 @@ object AesHelper {
|
||||||
// If it ends with NoPadding (e.g. "AES/CBC/NoPadding"), then it
|
// If it ends with NoPadding (e.g. "AES/CBC/NoPadding"), then it
|
||||||
// doesn't have padding, otherwise we treat as if it does.
|
// doesn't have padding, otherwise we treat as if it does.
|
||||||
val hasPadding = !padding.endsWith("NoPadding")
|
val hasPadding = !padding.endsWith("NoPadding")
|
||||||
return cryptoAESHandler(data, pass, encrypt, hasPadding)
|
return runBlocking { cryptoAESHandler(data, pass, encrypt, hasPadding) }
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://stackoverflow.com/a/41434590/8166854
|
// https://stackoverflow.com/a/41434590/8166854
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ object GogoHelper {
|
||||||
* @param id base64Decode(show_id) + IV
|
* @param id base64Decode(show_id) + IV
|
||||||
* @return the encryption key
|
* @return the encryption key
|
||||||
*/
|
*/
|
||||||
private fun getKey(id: String): String? {
|
private fun getEncryptionKey(id: String): String? {
|
||||||
return safe {
|
return safe {
|
||||||
id.map {
|
id.map {
|
||||||
it.code.toString(16)
|
it.code.toString(16)
|
||||||
|
|
@ -39,7 +39,7 @@ object GogoHelper {
|
||||||
// https://github.com/saikou-app/saikou/blob/45d0a99b8a72665a29a1eadfb38c506b842a29d7/app/src/main/java/ani/saikou/parsers/anime/extractors/GogoCDN.kt#L97
|
// https://github.com/saikou-app/saikou/blob/45d0a99b8a72665a29a1eadfb38c506b842a29d7/app/src/main/java/ani/saikou/parsers/anime/extractors/GogoCDN.kt#L97
|
||||||
// No Licence on the function
|
// No Licence on the function
|
||||||
@OptIn(DelicateCryptographyApi::class)
|
@OptIn(DelicateCryptographyApi::class)
|
||||||
private fun cryptoHandler(
|
private suspend fun cryptoHandler(
|
||||||
string: String,
|
string: String,
|
||||||
iv: String,
|
iv: String,
|
||||||
secretKeyString: String,
|
secretKeyString: String,
|
||||||
|
|
@ -47,14 +47,14 @@ object GogoHelper {
|
||||||
): String {
|
): String {
|
||||||
val ivBytes = iv.encodeToByteArray()
|
val ivBytes = iv.encodeToByteArray()
|
||||||
val keyBytes = secretKeyString.encodeToByteArray()
|
val keyBytes = secretKeyString.encodeToByteArray()
|
||||||
val aesKey = aesCbc.keyDecoder().decodeFromByteArrayBlocking(AES.Key.Format.RAW, keyBytes)
|
val aesKey = aesCbc.keyDecoder().decodeFromByteArray(AES.Key.Format.RAW, keyBytes)
|
||||||
val cipher = aesKey.cipher(padding = true)
|
val cipher = aesKey.cipher(padding = true)
|
||||||
|
|
||||||
return if (!encrypt) {
|
return if (!encrypt) {
|
||||||
val plainBytes = cipher.decryptWithIvBlocking(ivBytes, base64DecodeArray(string))
|
val plainBytes = cipher.decryptWithIv(ivBytes, base64DecodeArray(string))
|
||||||
plainBytes.decodeToString()
|
plainBytes.decodeToString()
|
||||||
} else {
|
} else {
|
||||||
base64Encode(cipher.encryptWithIvBlocking(ivBytes, string.encodeToByteArray()))
|
base64Encode(cipher.encryptWithIv(ivBytes, string.encodeToByteArray()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,7 +64,7 @@ object GogoHelper {
|
||||||
* @param iv secret iv from site, required non-null if isUsingAdaptiveKeys is off
|
* @param iv secret iv from site, required non-null if isUsingAdaptiveKeys is off
|
||||||
* @param secretKey secret key for decryption from site, required non-null if isUsingAdaptiveKeys is off
|
* @param secretKey secret key for decryption from site, required non-null if isUsingAdaptiveKeys is off
|
||||||
* @param secretDecryptKey secret key to decrypt the response json, required non-null if isUsingAdaptiveKeys is off
|
* @param secretDecryptKey secret key to decrypt the response json, required non-null if isUsingAdaptiveKeys is off
|
||||||
* @param isUsingAdaptiveKeys generates keys from IV and ID, see getKey()
|
* @param isUsingAdaptiveKeys generates keys from IV and ID, see [getEncryptionKey]
|
||||||
* @param isUsingAdaptiveData generate encrypt-ajax data based on $("script[data-name='episode']")[0].dataset.value
|
* @param isUsingAdaptiveData generate encrypt-ajax data based on $("script[data-name='episode']")[0].dataset.value
|
||||||
*/
|
*/
|
||||||
suspend fun extractVidstream(
|
suspend fun extractVidstream(
|
||||||
|
|
@ -89,7 +89,7 @@ object GogoHelper {
|
||||||
val foundIv = iv ?: (document ?: app.get(iframeUrl).document.also { document = it })
|
val foundIv = iv ?: (document ?: app.get(iframeUrl).document.also { document = it })
|
||||||
.select("""div.wrapper[class*=container]""")
|
.select("""div.wrapper[class*=container]""")
|
||||||
.attr("class").split("-").lastOrNull() ?: return@safeApiCall
|
.attr("class").split("-").lastOrNull() ?: return@safeApiCall
|
||||||
val foundKey = secretKey ?: getKey(base64Decode(id) + foundIv) ?: return@safeApiCall
|
val foundKey = secretKey ?: getEncryptionKey(base64Decode(id) + foundIv) ?: return@safeApiCall
|
||||||
val foundDecryptKey = secretDecryptKey ?: foundKey
|
val foundDecryptKey = secretDecryptKey ?: foundKey
|
||||||
|
|
||||||
val url = Url(iframeUrl)
|
val url = Url(iframeUrl)
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlin.collections.orEmpty
|
import kotlin.collections.orEmpty
|
||||||
|
|
||||||
@Prerelease
|
|
||||||
object JwPlayerHelper {
|
object JwPlayerHelper {
|
||||||
private val sourceRegex = Regex(""""?sources"?:\s*(\[.*?\])""")
|
private val sourceRegex = Regex(""""?sources"?:\s*(\[.*?\])""")
|
||||||
private val tracksRegex = Regex(""""?tracks"?:\s*(\[.*?\])""")
|
private val tracksRegex = Regex(""""?tracks"?:\s*(\[.*?\])""")
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,10 @@ import com.lagradost.cloudstream3.newTvSeriesLoadResponse
|
||||||
import com.lagradost.cloudstream3.newTvSeriesSearchResponse
|
import com.lagradost.cloudstream3.newTvSeriesSearchResponse
|
||||||
import com.lagradost.cloudstream3.utils.AppUtils.parseJson
|
import com.lagradost.cloudstream3.utils.AppUtils.parseJson
|
||||||
import com.lagradost.cloudstream3.utils.AppUtils.toJson
|
import com.lagradost.cloudstream3.utils.AppUtils.toJson
|
||||||
|
import kotlinx.serialization.ExperimentalSerializationApi
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
import kotlinx.serialization.json.JsonNames
|
||||||
|
|
||||||
open class TraktProvider : MainAPI() {
|
open class TraktProvider : MainAPI() {
|
||||||
override var name = "Trakt"
|
override var name = "Trakt"
|
||||||
|
|
@ -46,7 +50,6 @@ open class TraktProvider : MainAPI() {
|
||||||
)
|
)
|
||||||
|
|
||||||
private val traktApiUrl = "https://api.trakt.tv"
|
private val traktApiUrl = "https://api.trakt.tv"
|
||||||
|
|
||||||
private val traktClientId: String = BuildConfig.TRAKT_CLIENT_ID
|
private val traktClientId: String = BuildConfig.TRAKT_CLIENT_ID
|
||||||
|
|
||||||
override val mainPage = mainPageOf(
|
override val mainPage = mainPageOf(
|
||||||
|
|
@ -58,16 +61,21 @@ open class TraktProvider : MainAPI() {
|
||||||
|
|
||||||
override suspend fun getMainPage(page: Int, request: MainPageRequest): HomePageResponse {
|
override suspend fun getMainPage(page: Int, request: MainPageRequest): HomePageResponse {
|
||||||
val apiResponse = getApi("${request.data}?extended=full,images&page=$page")
|
val apiResponse = getApi("${request.data}?extended=full,images&page=$page")
|
||||||
|
|
||||||
val results = parseJson<List<MediaDetails>>(apiResponse).map { element ->
|
val results = parseJson<List<MediaDetails>>(apiResponse).map { element ->
|
||||||
element.toSearchResponse()
|
element.toSearchResponse()
|
||||||
}
|
}
|
||||||
|
|
||||||
return newHomePageResponse(request.name, results)
|
return newHomePageResponse(request.name, results)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun MediaDetails.toSearchResponse(): SearchResponse {
|
private fun MediaDetails.toSearchResponse(): SearchResponse {
|
||||||
|
val media = this.media ?: MediaSummary(
|
||||||
val media = this.media ?: this
|
title = this.title,
|
||||||
|
year = this.year,
|
||||||
|
ids = this.ids,
|
||||||
|
rating = this.rating,
|
||||||
|
images = this.images,
|
||||||
|
)
|
||||||
val mediaType = if (media.ids?.tvdb == null) TvType.Movie else TvType.TvSeries
|
val mediaType = if (media.ids?.tvdb == null) TvType.Movie else TvType.TvSeries
|
||||||
val poster = media.images?.poster?.firstOrNull()
|
val poster = media.images?.poster?.firstOrNull()
|
||||||
return if (mediaType == TvType.Movie) {
|
return if (mediaType == TvType.Movie) {
|
||||||
|
|
@ -75,7 +83,7 @@ open class TraktProvider : MainAPI() {
|
||||||
name = media.title ?: "",
|
name = media.title ?: "",
|
||||||
url = Data(
|
url = Data(
|
||||||
type = mediaType,
|
type = mediaType,
|
||||||
mediaDetails = media,
|
mediaDetails = this,
|
||||||
).toJson(),
|
).toJson(),
|
||||||
type = TvType.Movie,
|
type = TvType.Movie,
|
||||||
) {
|
) {
|
||||||
|
|
@ -87,7 +95,7 @@ open class TraktProvider : MainAPI() {
|
||||||
name = media.title ?: "",
|
name = media.title ?: "",
|
||||||
url = Data(
|
url = Data(
|
||||||
type = mediaType,
|
type = mediaType,
|
||||||
mediaDetails = media,
|
mediaDetails = this,
|
||||||
).toJson(),
|
).toJson(),
|
||||||
type = TvType.TvSeries,
|
type = TvType.TvSeries,
|
||||||
) {
|
) {
|
||||||
|
|
@ -98,9 +106,7 @@ open class TraktProvider : MainAPI() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun search(query: String, page: Int): SearchResponseList? {
|
override suspend fun search(query: String, page: Int): SearchResponseList? {
|
||||||
val apiResponse =
|
val apiResponse = getApi("$traktApiUrl/search/movie,show?extended=full,images&limit=20&page=$page&query=$query")
|
||||||
getApi("$traktApiUrl/search/movie,show?extended=full,images&limit=20&page=$page&query=$query")
|
|
||||||
|
|
||||||
return newSearchResponseList(parseJson<List<MediaDetails>>(apiResponse).map { element ->
|
return newSearchResponseList(parseJson<List<MediaDetails>>(apiResponse).map { element ->
|
||||||
element.toSearchResponse()
|
element.toSearchResponse()
|
||||||
})
|
})
|
||||||
|
|
@ -115,9 +121,7 @@ open class TraktProvider : MainAPI() {
|
||||||
val backDropUrl = fixPath(mediaDetails?.images?.fanart?.firstOrNull())
|
val backDropUrl = fixPath(mediaDetails?.images?.fanart?.firstOrNull())
|
||||||
val logoUrl = fixPath(mediaDetails?.images?.logo?.firstOrNull())
|
val logoUrl = fixPath(mediaDetails?.images?.logo?.firstOrNull())
|
||||||
|
|
||||||
val resActor =
|
val resActor = getApi("$traktApiUrl/$moviesOrShows/${mediaDetails?.ids?.trakt}/people?extended=full,images")
|
||||||
getApi("$traktApiUrl/$moviesOrShows/${mediaDetails?.ids?.trakt}/people?extended=full,images")
|
|
||||||
|
|
||||||
val actors = parseJson<People>(resActor).cast?.map {
|
val actors = parseJson<People>(resActor).cast?.map {
|
||||||
ActorData(
|
ActorData(
|
||||||
Actor(
|
Actor(
|
||||||
|
|
@ -128,9 +132,7 @@ open class TraktProvider : MainAPI() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val resRelated =
|
val resRelated = getApi("$traktApiUrl/$moviesOrShows/${mediaDetails?.ids?.trakt}/related?extended=full,images&limit=20")
|
||||||
getApi("$traktApiUrl/$moviesOrShows/${mediaDetails?.ids?.trakt}/related?extended=full,images&limit=20")
|
|
||||||
|
|
||||||
val relatedMedia = parseJson<List<MediaDetails>>(resRelated).map { it.toSearchResponse() }
|
val relatedMedia = parseJson<List<MediaDetails>>(resRelated).map { it.toSearchResponse() }
|
||||||
|
|
||||||
val isCartoon =
|
val isCartoon =
|
||||||
|
|
@ -142,7 +144,6 @@ open class TraktProvider : MainAPI() {
|
||||||
val uniqueUrl = data.mediaDetails?.ids?.trakt?.toJson() ?: data.toJson()
|
val uniqueUrl = data.mediaDetails?.ids?.trakt?.toJson() ?: data.toJson()
|
||||||
|
|
||||||
if (data.type == TvType.Movie) {
|
if (data.type == TvType.Movie) {
|
||||||
|
|
||||||
val linkData = LinkData(
|
val linkData = LinkData(
|
||||||
id = mediaDetails?.ids?.tmdb,
|
id = mediaDetails?.ids?.tmdb,
|
||||||
traktId = mediaDetails?.ids?.trakt,
|
traktId = mediaDetails?.ids?.trakt,
|
||||||
|
|
@ -156,7 +157,7 @@ open class TraktProvider : MainAPI() {
|
||||||
year = mediaDetails?.year,
|
year = mediaDetails?.year,
|
||||||
orgTitle = mediaDetails?.title,
|
orgTitle = mediaDetails?.title,
|
||||||
isAnime = isAnime,
|
isAnime = isAnime,
|
||||||
//jpTitle = later if needed as it requires another network request,
|
// jpTitle = later if needed as it requires another network request,
|
||||||
airedDate = mediaDetails?.released
|
airedDate = mediaDetails?.released
|
||||||
?: mediaDetails?.firstAired,
|
?: mediaDetails?.firstAired,
|
||||||
isAsian = isAsian,
|
isAsian = isAsian,
|
||||||
|
|
@ -190,7 +191,6 @@ open class TraktProvider : MainAPI() {
|
||||||
addTMDbId(mediaDetails.ids?.tmdb.toString())
|
addTMDbId(mediaDetails.ids?.tmdb.toString())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
val resSeasons =
|
val resSeasons =
|
||||||
getApi("$traktApiUrl/shows/${mediaDetails?.ids?.trakt.toString()}/seasons?extended=full,images,episodes")
|
getApi("$traktApiUrl/shows/${mediaDetails?.ids?.trakt.toString()}/seasons?extended=full,images,episodes")
|
||||||
val episodes = mutableListOf<Episode>()
|
val episodes = mutableListOf<Episode>()
|
||||||
|
|
@ -198,9 +198,7 @@ open class TraktProvider : MainAPI() {
|
||||||
var nextAir: NextAiring? = null
|
var nextAir: NextAiring? = null
|
||||||
|
|
||||||
seasons.forEach { season ->
|
seasons.forEach { season ->
|
||||||
|
|
||||||
season.episodes?.map { episode ->
|
season.episodes?.map { episode ->
|
||||||
|
|
||||||
val linkData = LinkData(
|
val linkData = LinkData(
|
||||||
id = mediaDetails?.ids?.tmdb,
|
id = mediaDetails?.ids?.tmdb,
|
||||||
traktId = mediaDetails?.ids?.trakt,
|
traktId = mediaDetails?.ids?.trakt,
|
||||||
|
|
@ -234,8 +232,7 @@ open class TraktProvider : MainAPI() {
|
||||||
this.episode = episode.number
|
this.episode = episode.number
|
||||||
this.description = episode.overview
|
this.description = episode.overview
|
||||||
this.runTime = episode.runtime
|
this.runTime = episode.runtime
|
||||||
this.posterUrl = fixPath( episode.images?.screenshot?.firstOrNull())
|
this.posterUrl = fixPath(episode.images?.screenshot?.firstOrNull())
|
||||||
//this.rating = episode.rating?.times(10)?.roundToInt()
|
|
||||||
this.score = Score.from10(episode.rating)
|
this.score = Score.from10(episode.rating)
|
||||||
|
|
||||||
this.addDate(episode.firstAired, "yyyy-MM-dd'T'HH:mm:ss.SSSXXX")
|
this.addDate(episode.firstAired, "yyyy-MM-dd'T'HH:mm:ss.SSSXXX")
|
||||||
|
|
@ -307,143 +304,164 @@ open class TraktProvider : MainAPI() {
|
||||||
return "https://$url"
|
return "https://$url"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class Data(
|
data class Data(
|
||||||
val type: TvType? = null,
|
@JsonProperty("type") @SerialName("type") val type: TvType? = null,
|
||||||
val mediaDetails: MediaDetails? = null,
|
@JsonProperty("mediaDetails") @SerialName("mediaDetails") val mediaDetails: MediaDetails? = null,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class MediaSummary(
|
||||||
|
@JsonProperty("title") @SerialName("title") val title: String? = null,
|
||||||
|
@JsonProperty("year") @SerialName("year") val year: Int? = null,
|
||||||
|
@JsonProperty("ids") @SerialName("ids") val ids: Ids? = null,
|
||||||
|
@JsonProperty("rating") @SerialName("rating") val rating: Double? = null,
|
||||||
|
@JsonProperty("images") @SerialName("images") val images: Images? = null,
|
||||||
|
)
|
||||||
|
|
||||||
|
@OptIn(ExperimentalSerializationApi::class) // JsonNames is an experimental annotation for now
|
||||||
|
@Serializable
|
||||||
data class MediaDetails(
|
data class MediaDetails(
|
||||||
@JsonProperty("title") val title: String? = null,
|
@JsonProperty("title") @SerialName("title") val title: String? = null,
|
||||||
@JsonProperty("year") val year: Int? = null,
|
@JsonProperty("year") @SerialName("year") val year: Int? = null,
|
||||||
@JsonProperty("ids") val ids: Ids? = null,
|
@JsonProperty("ids") @SerialName("ids") val ids: Ids? = null,
|
||||||
@JsonProperty("tagline") val tagline: String? = null,
|
@JsonProperty("tagline") @SerialName("tagline") val tagline: String? = null,
|
||||||
@JsonProperty("overview") val overview: String? = null,
|
@JsonProperty("overview") @SerialName("overview") val overview: String? = null,
|
||||||
@JsonProperty("released") val released: String? = null,
|
@JsonProperty("released") @SerialName("released") val released: String? = null,
|
||||||
@JsonProperty("runtime") val runtime: Int? = null,
|
@JsonProperty("runtime") @SerialName("runtime") val runtime: Int? = null,
|
||||||
@JsonProperty("country") val country: String? = null,
|
@JsonProperty("country") @SerialName("country") val country: String? = null,
|
||||||
@JsonProperty("updatedAt") val updatedAt: String? = null,
|
@JsonProperty("updatedAt") @SerialName("updatedAt") val updatedAt: String? = null,
|
||||||
@JsonProperty("trailer") val trailer: String? = null,
|
@JsonProperty("trailer") @SerialName("trailer") val trailer: String? = null,
|
||||||
@JsonProperty("homepage") val homepage: String? = null,
|
@JsonProperty("homepage") @SerialName("homepage") val homepage: String? = null,
|
||||||
@JsonProperty("status") val status: String? = null,
|
@JsonProperty("status") @SerialName("status") val status: String? = null,
|
||||||
@JsonProperty("rating") val rating: Double? = null,
|
@JsonProperty("rating") @SerialName("rating") val rating: Double? = null,
|
||||||
@JsonProperty("votes") val votes: Long? = null,
|
@JsonProperty("votes") @SerialName("votes") val votes: Long? = null,
|
||||||
@JsonProperty("comment_count") val commentCount: Long? = null,
|
@JsonProperty("comment_count") @SerialName("comment_count") val commentCount: Long? = null,
|
||||||
@JsonProperty("language") val language: String? = null,
|
@JsonProperty("language") @SerialName("language") val language: String? = null,
|
||||||
@JsonProperty("languages") val languages: List<String>? = null,
|
@JsonProperty("languages") @SerialName("languages") val languages: List<String>? = null,
|
||||||
@JsonProperty("available_translations") val availableTranslations: List<String>? = null,
|
@JsonProperty("available_translations") @SerialName("available_translations") val availableTranslations: List<String>? = null,
|
||||||
@JsonProperty("genres") val genres: List<String>? = null,
|
@JsonProperty("genres") @SerialName("genres") val genres: List<String>? = null,
|
||||||
@JsonProperty("certification") val certification: String? = null,
|
@JsonProperty("certification") @SerialName("certification") val certification: String? = null,
|
||||||
@JsonProperty("aired_episodes") val airedEpisodes: Int? = null,
|
@JsonProperty("aired_episodes") @SerialName("aired_episodes") val airedEpisodes: Int? = null,
|
||||||
@JsonProperty("first_aired") val firstAired: String? = null,
|
@JsonProperty("first_aired") @SerialName("first_aired") val firstAired: String? = null,
|
||||||
@JsonProperty("airs") val airs: Airs? = null,
|
@JsonProperty("airs") @SerialName("airs") val airs: Airs? = null,
|
||||||
@JsonProperty("network") val network: String? = null,
|
@JsonProperty("network") @SerialName("network") val network: String? = null,
|
||||||
@JsonProperty("images") val images: Images? = null,
|
@JsonProperty("images") @SerialName("images") val images: Images? = null,
|
||||||
@JsonProperty("movie") @JsonAlias("show") val media: MediaDetails? = null
|
@JsonProperty("media") @JsonAlias("movie", "show") @SerialName("media") @JsonNames("movie", "show") val media: MediaSummary? = null,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class Airs(
|
data class Airs(
|
||||||
@JsonProperty("day") val day: String? = null,
|
@JsonProperty("day") @SerialName("day") val day: String? = null,
|
||||||
@JsonProperty("time") val time: String? = null,
|
@JsonProperty("time") @SerialName("time") val time: String? = null,
|
||||||
@JsonProperty("timezone") val timezone: String? = null,
|
@JsonProperty("timezone") @SerialName("timezone") val timezone: String? = null,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class Ids(
|
data class Ids(
|
||||||
@JsonProperty("trakt") val trakt: Int? = null,
|
@JsonProperty("trakt") @SerialName("trakt") val trakt: Int? = null,
|
||||||
@JsonProperty("slug") val slug: String? = null,
|
@JsonProperty("slug") @SerialName("slug") val slug: String? = null,
|
||||||
@JsonProperty("tvdb") val tvdb: Int? = null,
|
@JsonProperty("tvdb") @SerialName("tvdb") val tvdb: Int? = null,
|
||||||
@JsonProperty("imdb") val imdb: String? = null,
|
@JsonProperty("imdb") @SerialName("imdb") val imdb: String? = null,
|
||||||
@JsonProperty("tmdb") val tmdb: Int? = null,
|
@JsonProperty("tmdb") @SerialName("tmdb") val tmdb: Int? = null,
|
||||||
@JsonProperty("tvrage") val tvrage: String? = null,
|
@JsonProperty("tvrage") @SerialName("tvrage") val tvrage: String? = null,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class Images(
|
data class Images(
|
||||||
@JsonProperty("poster") val poster: List<String>? = null,
|
@JsonProperty("poster") @SerialName("poster") val poster: List<String>? = null,
|
||||||
@JsonProperty("fanart") val fanart: List<String>? = null,
|
@JsonProperty("fanart") @SerialName("fanart") val fanart: List<String>? = null,
|
||||||
@JsonProperty("logo") val logo: List<String>? = null,
|
@JsonProperty("logo") @SerialName("logo") val logo: List<String>? = null,
|
||||||
@JsonProperty("clearart") val clearArt: List<String>? = null,
|
@JsonProperty("clearart") @SerialName("clearart") val clearArt: List<String>? = null,
|
||||||
@JsonProperty("banner") val banner: List<String>? = null,
|
@JsonProperty("banner") @SerialName("banner") val banner: List<String>? = null,
|
||||||
@JsonProperty("thumb") val thumb: List<String>? = null,
|
@JsonProperty("thumb") @SerialName("thumb") val thumb: List<String>? = null,
|
||||||
@JsonProperty("screenshot") val screenshot: List<String>? = null,
|
@JsonProperty("screenshot") @SerialName("screenshot") val screenshot: List<String>? = null,
|
||||||
@JsonProperty("headshot") val headshot: List<String>? = null,
|
@JsonProperty("headshot") @SerialName("headshot") val headshot: List<String>? = null,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class People(
|
data class People(
|
||||||
@JsonProperty("cast") val cast: List<Cast>? = null,
|
@JsonProperty("cast") @SerialName("cast") val cast: List<Cast>? = null,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class Cast(
|
data class Cast(
|
||||||
@JsonProperty("character") val character: String? = null,
|
@JsonProperty("character") @SerialName("character") val character: String? = null,
|
||||||
@JsonProperty("characters") val characters: List<String>? = null,
|
@JsonProperty("characters") @SerialName("characters") val characters: List<String>? = null,
|
||||||
@JsonProperty("episode_count") val episodeCount: Long? = null,
|
@JsonProperty("episode_count") @SerialName("episode_count") val episodeCount: Long? = null,
|
||||||
@JsonProperty("person") val person: Person? = null,
|
@JsonProperty("person") @SerialName("person") val person: Person? = null,
|
||||||
@JsonProperty("images") val images: Images? = null,
|
@JsonProperty("images") @SerialName("images") val images: Images? = null,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class Person(
|
data class Person(
|
||||||
@JsonProperty("name") val name: String? = null,
|
@JsonProperty("name") @SerialName("name") val name: String? = null,
|
||||||
@JsonProperty("ids") val ids: Ids? = null,
|
@JsonProperty("ids") @SerialName("ids") val ids: Ids? = null,
|
||||||
@JsonProperty("images") val images: Images? = null,
|
@JsonProperty("images") @SerialName("images") val images: Images? = null,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class Seasons(
|
data class Seasons(
|
||||||
@JsonProperty("aired_episodes") val airedEpisodes: Int? = null,
|
@JsonProperty("aired_episodes") @SerialName("aired_episodes") val airedEpisodes: Int? = null,
|
||||||
@JsonProperty("episode_count") val episodeCount: Int? = null,
|
@JsonProperty("episode_count") @SerialName("episode_count") val episodeCount: Int? = null,
|
||||||
@JsonProperty("episodes") val episodes: List<TraktEpisode>? = null,
|
@JsonProperty("episodes") @SerialName("episodes") val episodes: List<TraktEpisode>? = null,
|
||||||
@JsonProperty("first_aired") val firstAired: String? = null,
|
@JsonProperty("first_aired") @SerialName("first_aired") val firstAired: String? = null,
|
||||||
@JsonProperty("ids") val ids: Ids? = null,
|
@JsonProperty("ids") @SerialName("ids") val ids: Ids? = null,
|
||||||
@JsonProperty("images") val images: Images? = null,
|
@JsonProperty("images") @SerialName("images") val images: Images? = null,
|
||||||
@JsonProperty("network") val network: String? = null,
|
@JsonProperty("network") @SerialName("network") val network: String? = null,
|
||||||
@JsonProperty("number") val number: Int? = null,
|
@JsonProperty("number") @SerialName("number") val number: Int? = null,
|
||||||
@JsonProperty("overview") val overview: String? = null,
|
@JsonProperty("overview") @SerialName("overview") val overview: String? = null,
|
||||||
@JsonProperty("rating") val rating: Double? = null,
|
@JsonProperty("rating") @SerialName("rating") val rating: Double? = null,
|
||||||
@JsonProperty("title") val title: String? = null,
|
@JsonProperty("title") @SerialName("title") val title: String? = null,
|
||||||
@JsonProperty("updated_at") val updatedAt: String? = null,
|
@JsonProperty("updated_at") @SerialName("updated_at") val updatedAt: String? = null,
|
||||||
@JsonProperty("votes") val votes: Int? = null,
|
@JsonProperty("votes") @SerialName("votes") val votes: Int? = null,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class TraktEpisode(
|
data class TraktEpisode(
|
||||||
@JsonProperty("available_translations") val availableTranslations: List<String>? = null,
|
@JsonProperty("available_translations") @SerialName("available_translations") val availableTranslations: List<String>? = null,
|
||||||
@JsonProperty("comment_count") val commentCount: Int? = null,
|
@JsonProperty("comment_count") @SerialName("comment_count") val commentCount: Int? = null,
|
||||||
@JsonProperty("episode_type") val episodeType: String? = null,
|
@JsonProperty("episode_type") @SerialName("episode_type") val episodeType: String? = null,
|
||||||
@JsonProperty("first_aired") val firstAired: String? = null,
|
@JsonProperty("first_aired") @SerialName("first_aired") val firstAired: String? = null,
|
||||||
@JsonProperty("ids") val ids: Ids? = null,
|
@JsonProperty("ids") @SerialName("ids") val ids: Ids? = null,
|
||||||
@JsonProperty("images") val images: Images? = null,
|
@JsonProperty("images") @SerialName("images") val images: Images? = null,
|
||||||
@JsonProperty("number") val number: Int? = null,
|
@JsonProperty("number") @SerialName("number") val number: Int? = null,
|
||||||
@JsonProperty("number_abs") val numberAbs: Int? = null,
|
@JsonProperty("number_abs") @SerialName("number_abs") val numberAbs: Int? = null,
|
||||||
@JsonProperty("overview") val overview: String? = null,
|
@JsonProperty("overview") @SerialName("overview") val overview: String? = null,
|
||||||
@JsonProperty("rating") val rating: Double? = null,
|
@JsonProperty("rating") @SerialName("rating") val rating: Double? = null,
|
||||||
@JsonProperty("runtime") val runtime: Int? = null,
|
@JsonProperty("runtime") @SerialName("runtime") val runtime: Int? = null,
|
||||||
@JsonProperty("season") val season: Int? = null,
|
@JsonProperty("season") @SerialName("season") val season: Int? = null,
|
||||||
@JsonProperty("title") val title: String? = null,
|
@JsonProperty("title") @SerialName("title") val title: String? = null,
|
||||||
@JsonProperty("updated_at") val updatedAt: String? = null,
|
@JsonProperty("updated_at") @SerialName("updated_at") val updatedAt: String? = null,
|
||||||
@JsonProperty("votes") val votes: Int? = null,
|
@JsonProperty("votes") @SerialName("votes") val votes: Int? = null,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class LinkData(
|
data class LinkData(
|
||||||
@JsonProperty("id") val id: Int? = null,
|
@JsonProperty("id") @SerialName("id") val id: Int? = null,
|
||||||
@JsonProperty("trakt_id") val traktId: Int? = null,
|
@JsonProperty("trakt_id") @SerialName("trakt_id") val traktId: Int? = null,
|
||||||
@JsonProperty("trakt_slug") val traktSlug: String? = null,
|
@JsonProperty("trakt_slug") @SerialName("trakt_slug") val traktSlug: String? = null,
|
||||||
@JsonProperty("tmdb_id") val tmdbId: Int? = null,
|
@JsonProperty("tmdb_id") @SerialName("tmdb_id") val tmdbId: Int? = null,
|
||||||
@JsonProperty("imdb_id") val imdbId: String? = null,
|
@JsonProperty("imdb_id") @SerialName("imdb_id") val imdbId: String? = null,
|
||||||
@JsonProperty("tvdb_id") val tvdbId: Int? = null,
|
@JsonProperty("tvdb_id") @SerialName("tvdb_id") val tvdbId: Int? = null,
|
||||||
@JsonProperty("tvrage_id") val tvrageId: String? = null,
|
@JsonProperty("tvrage_id") @SerialName("tvrage_id") val tvrageId: String? = null,
|
||||||
@JsonProperty("type") val type: String? = null,
|
@JsonProperty("type") @SerialName("type") val type: String? = null,
|
||||||
@JsonProperty("season") val season: Int? = null,
|
@JsonProperty("season") @SerialName("season") val season: Int? = null,
|
||||||
@JsonProperty("episode") val episode: Int? = null,
|
@JsonProperty("episode") @SerialName("episode") val episode: Int? = null,
|
||||||
@JsonProperty("ani_id") val aniId: String? = null,
|
@JsonProperty("ani_id") @SerialName("ani_id") val aniId: String? = null,
|
||||||
@JsonProperty("anime_id") val animeId: String? = null,
|
@JsonProperty("anime_id") @SerialName("anime_id") val animeId: String? = null,
|
||||||
@JsonProperty("title") val title: String? = null,
|
@JsonProperty("title") @SerialName("title") val title: String? = null,
|
||||||
@JsonProperty("year") val year: Int? = null,
|
@JsonProperty("year") @SerialName("year") val year: Int? = null,
|
||||||
@JsonProperty("org_title") val orgTitle: String? = null,
|
@JsonProperty("org_title") @SerialName("org_title") val orgTitle: String? = null,
|
||||||
@JsonProperty("is_anime") val isAnime: Boolean = false,
|
@JsonProperty("is_anime") @SerialName("is_anime") val isAnime: Boolean = false,
|
||||||
@JsonProperty("aired_year") val airedYear: Int? = null,
|
@JsonProperty("aired_year") @SerialName("aired_year") val airedYear: Int? = null,
|
||||||
@JsonProperty("last_season") val lastSeason: Int? = null,
|
@JsonProperty("last_season") @SerialName("last_season") val lastSeason: Int? = null,
|
||||||
@JsonProperty("eps_title") val epsTitle: String? = null,
|
@JsonProperty("eps_title") @SerialName("eps_title") val epsTitle: String? = null,
|
||||||
@JsonProperty("jp_title") val jpTitle: String? = null,
|
@JsonProperty("jp_title") @SerialName("jp_title") val jpTitle: String? = null,
|
||||||
@JsonProperty("date") val date: String? = null,
|
@JsonProperty("date") @SerialName("date") val date: String? = null,
|
||||||
@JsonProperty("aired_date") val airedDate: String? = null,
|
@JsonProperty("aired_date") @SerialName("aired_date") val airedDate: String? = null,
|
||||||
@JsonProperty("is_asian") val isAsian: Boolean = false,
|
@JsonProperty("is_asian") @SerialName("is_asian") val isAsian: Boolean = false,
|
||||||
@JsonProperty("is_bollywood") val isBollywood: Boolean = false,
|
@JsonProperty("is_bollywood") @SerialName("is_bollywood") val isBollywood: Boolean = false,
|
||||||
@JsonProperty("is_cartoon") val isCartoon: Boolean = false,
|
@JsonProperty("is_cartoon") @SerialName("is_cartoon") val isCartoon: Boolean = false,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -68,16 +68,14 @@ object Coroutines {
|
||||||
* If you want to iterate over the list then you need to do:
|
* If you want to iterate over the list then you need to do:
|
||||||
* list.withLock { code here }
|
* list.withLock { code here }
|
||||||
*/
|
*/
|
||||||
@Prerelease
|
|
||||||
fun <T> atomicListOf(vararg items: T): AtomicMutableList<T> {
|
fun <T> atomicListOf(vararg items: T): AtomicMutableList<T> {
|
||||||
return AtomicMutableList(items.toMutableList())
|
return AtomicMutableList(items.toMutableList())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecate after next stable
|
@Deprecated(
|
||||||
/*@Deprecated(
|
|
||||||
message = "Use atomicListOf() instead.",
|
message = "Use atomicListOf() instead.",
|
||||||
replaceWith = ReplaceWith("atomicListOf(*items)"),
|
replaceWith = ReplaceWith("atomicListOf(*items)"),
|
||||||
level = DeprecationLevel.WARNING,
|
level = DeprecationLevel.WARNING,
|
||||||
)*/
|
)
|
||||||
fun <T> threadSafeListOf(vararg items: T): MutableList<T> = atomicListOf(*items)
|
fun <T> threadSafeListOf(vararg items: T): MutableList<T> = atomicListOf(*items)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -328,6 +328,9 @@ import io.ktor.http.decodeURLPart
|
||||||
import kotlinx.coroutines.coroutineScope
|
import kotlinx.coroutines.coroutineScope
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.ensureActive
|
import kotlinx.coroutines.ensureActive
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
import kotlinx.serialization.Transient
|
||||||
import kotlin.coroutines.cancellation.CancellationException
|
import kotlin.coroutines.cancellation.CancellationException
|
||||||
import kotlin.uuid.ExperimentalUuidApi
|
import kotlin.uuid.ExperimentalUuidApi
|
||||||
import kotlin.uuid.Uuid
|
import kotlin.uuid.Uuid
|
||||||
|
|
@ -418,6 +421,7 @@ enum class ExtractorLinkType {
|
||||||
MAGNET;
|
MAGNET;
|
||||||
|
|
||||||
// See https://www.iana.org/assignments/media-types/media-types.xhtml
|
// See https://www.iana.org/assignments/media-types/media-types.xhtml
|
||||||
|
@JsonIgnore
|
||||||
fun getMimeType(): String {
|
fun getMimeType(): String {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
VIDEO -> "video/mp4"
|
VIDEO -> "video/mp4"
|
||||||
|
|
@ -685,26 +689,27 @@ open class DrmExtractorLink private constructor(
|
||||||
* @property audioTracks List of separate audio tracks that can be used with this video
|
* @property audioTracks List of separate audio tracks that can be used with this video
|
||||||
* @see newExtractorLink
|
* @see newExtractorLink
|
||||||
* */
|
* */
|
||||||
|
@Serializable
|
||||||
open class ExtractorLink
|
open class ExtractorLink
|
||||||
@Deprecated("Use newExtractorLink", level = DeprecationLevel.WARNING)
|
@Deprecated("Use newExtractorLink", level = DeprecationLevel.WARNING)
|
||||||
constructor(
|
constructor(
|
||||||
open val source: String,
|
@SerialName("source") open val source: String,
|
||||||
open val name: String,
|
@SerialName("name") open val name: String,
|
||||||
override val url: String,
|
@SerialName("url") override val url: String,
|
||||||
override var referer: String,
|
@SerialName("referer") override var referer: String,
|
||||||
open var quality: Int,
|
@SerialName("quality") open var quality: Int,
|
||||||
override var headers: Map<String, String> = mapOf(),
|
@SerialName("headers") override var headers: Map<String, String> = mapOf(),
|
||||||
/** Used for getExtractorVerifierJob() */
|
/** Used for getExtractorVerifierJob() */
|
||||||
open var extractorData: String? = null,
|
@SerialName("extractorData") open var extractorData: String? = null,
|
||||||
open var type: ExtractorLinkType,
|
@SerialName("type") open var type: ExtractorLinkType,
|
||||||
/** List of separate audio tracks that can be merged with this video */
|
/** List of separate audio tracks that can be merged with this video */
|
||||||
open var audioTracks: List<AudioFile> = emptyList(),
|
@SerialName("audioTracks") open var audioTracks: List<AudioFile> = emptyList(),
|
||||||
) : IDownloadableMinimum {
|
) : IDownloadableMinimum {
|
||||||
val isM3u8: Boolean get() = type == ExtractorLinkType.M3U8
|
@get:JsonIgnore val isM3u8: Boolean get() = type == ExtractorLinkType.M3U8
|
||||||
val isDash: Boolean get() = type == ExtractorLinkType.DASH
|
@get:JsonIgnore val isDash: Boolean get() = type == ExtractorLinkType.DASH
|
||||||
|
|
||||||
// Cached video size
|
// Cached video size
|
||||||
private var videoSize: Long? = null
|
@Transient private var videoSize: Long? = null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get video size in bytes with one head request. Only available for ExtractorLinkType.Video
|
* Get video size in bytes with one head request. Only available for ExtractorLinkType.Video
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -28,7 +28,6 @@ import com.lagradost.cloudstream3.Prerelease
|
||||||
import kotlin.math.round
|
import kotlin.math.round
|
||||||
|
|
||||||
// Taken from https://github.com/terrakok/FuzzyKot/blob/f794d43/fuzzykot/src/commonMain/kotlin/com/github/terrakok/fuzzykot/Levenshtein.kt
|
// Taken from https://github.com/terrakok/FuzzyKot/blob/f794d43/fuzzykot/src/commonMain/kotlin/com/github/terrakok/fuzzykot/Levenshtein.kt
|
||||||
@Prerelease
|
|
||||||
object Levenshtein {
|
object Levenshtein {
|
||||||
fun ratio(s1: String, s2: String, processor: (String) -> String = { it }): Int {
|
fun ratio(s1: String, s2: String, processor: (String) -> String = { it }): Int {
|
||||||
val p1 = processor(s1)
|
val p1 = processor(s1)
|
||||||
|
|
|
||||||
|
|
@ -234,6 +234,10 @@ object M3u8Helper2 {
|
||||||
body.close()
|
body.close()
|
||||||
if (tsData.isEmpty()) throw ErrorLoadingException("no data")
|
if (tsData.isEmpty()) throw ErrorLoadingException("no data")
|
||||||
|
|
||||||
|
// Some sources respond with "error 404" or similar, this checks for small responses that
|
||||||
|
// looks like ASCII
|
||||||
|
if (tsData.size < 128 && tsData.all { it >= 0 }) throw ErrorLoadingException("ASCII found instead of data")
|
||||||
|
|
||||||
return if (isEncrypted) {
|
return if (isEncrypted) {
|
||||||
getDecrypted(encryptionData, tsData, encryptionIv, index)
|
getDecrypted(encryptionData, tsData, encryptionIv, index)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -5,30 +5,26 @@ import io.ktor.http.decodeURLQueryComponent
|
||||||
import io.ktor.http.encodeURLParameter
|
import io.ktor.http.encodeURLParameter
|
||||||
|
|
||||||
object StringUtils {
|
object StringUtils {
|
||||||
@Prerelease
|
|
||||||
fun String.decodeUrl(): String {
|
fun String.decodeUrl(): String {
|
||||||
return this.decodeURLQueryComponent()
|
return this.decodeURLQueryComponent()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Prerelease
|
|
||||||
fun String.encodeUrl(): String {
|
fun String.encodeUrl(): String {
|
||||||
return this.encodeURLParameter()
|
return this.encodeURLParameter()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecate after next stable
|
@Deprecated(
|
||||||
|
|
||||||
/* @Deprecated(
|
|
||||||
message = "Use Ktor 'Url' naming convention instead.",
|
message = "Use Ktor 'Url' naming convention instead.",
|
||||||
replaceWith = ReplaceWith("this.encodeUrl()"),
|
replaceWith = ReplaceWith("this.encodeUrl()"),
|
||||||
level = DeprecationLevel.WARNING,
|
level = DeprecationLevel.WARNING,
|
||||||
) */
|
)
|
||||||
fun String.encodeUri(): String = encodeUrl()
|
fun String.encodeUri(): String = encodeUrl()
|
||||||
|
|
||||||
/* @Deprecated(
|
@Deprecated(
|
||||||
message = "Use Ktor 'Url' naming convention instead.",
|
message = "Use Ktor 'Url' naming convention instead.",
|
||||||
replaceWith = ReplaceWith("this.decodeUrl()"),
|
replaceWith = ReplaceWith("this.decodeUrl()"),
|
||||||
level = DeprecationLevel.WARNING,
|
level = DeprecationLevel.WARNING,
|
||||||
) */
|
)
|
||||||
fun String.decodeUri(): String = decodeUrl()
|
fun String.decodeUri(): String = decodeUrl()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
package com.lagradost.cloudstream3.utils.serializers
|
||||||
|
|
||||||
|
import com.lagradost.cloudstream3.Prerelease
|
||||||
|
import kotlinx.serialization.KSerializer
|
||||||
|
import kotlinx.serialization.descriptors.PrimitiveKind
|
||||||
|
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
|
||||||
|
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||||
|
import kotlinx.serialization.encoding.Decoder
|
||||||
|
import kotlinx.serialization.encoding.Encoder
|
||||||
|
import kotlinx.serialization.json.JsonDecoder
|
||||||
|
import kotlinx.serialization.json.JsonPrimitive
|
||||||
|
import kotlinx.serialization.json.doubleOrNull
|
||||||
|
import kotlinx.serialization.json.intOrNull
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replicates Jackson's ACCEPT_FLOAT_AS_INT behaviour for Int fields.
|
||||||
|
* A floating-point JSON number is truncated to Int by dropping the
|
||||||
|
* fractional part, exactly like Jackson's default truncation behaviour.
|
||||||
|
*
|
||||||
|
* Usage:
|
||||||
|
*
|
||||||
|
* @Serializable
|
||||||
|
* data class MyData(
|
||||||
|
* @Serializable(with = FloatAsIntSerializer::class)
|
||||||
|
* @SerialName("count") val count: Int = 0,
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
@Prerelease
|
||||||
|
object FloatAsIntSerializer : KSerializer<Int> {
|
||||||
|
|
||||||
|
override val descriptor: SerialDescriptor =
|
||||||
|
PrimitiveSerialDescriptor("FloatAsInt", PrimitiveKind.INT)
|
||||||
|
|
||||||
|
override fun deserialize(decoder: Decoder): Int {
|
||||||
|
val jsonDecoder = decoder as? JsonDecoder ?: return decoder.decodeInt()
|
||||||
|
val element = jsonDecoder.decodeJsonElement()
|
||||||
|
if (element !is JsonPrimitive) return 0
|
||||||
|
return element.intOrNull ?: element.doubleOrNull?.toInt() ?: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun serialize(encoder: Encoder, value: Int) = encoder.encodeInt(value)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
package com.lagradost.cloudstream3.utils.serializers
|
||||||
|
|
||||||
|
import com.lagradost.cloudstream3.Prerelease
|
||||||
|
import kotlinx.serialization.KSerializer
|
||||||
|
import kotlinx.serialization.descriptors.PrimitiveKind
|
||||||
|
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
|
||||||
|
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||||
|
import kotlinx.serialization.encoding.Decoder
|
||||||
|
import kotlinx.serialization.encoding.Encoder
|
||||||
|
import kotlinx.serialization.json.JsonDecoder
|
||||||
|
import kotlinx.serialization.json.JsonPrimitive
|
||||||
|
import kotlinx.serialization.json.doubleOrNull
|
||||||
|
import kotlinx.serialization.json.longOrNull
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replicates Jackson's ACCEPT_FLOAT_AS_INT behaviour for Long fields.
|
||||||
|
* A floating-point JSON number is truncated to Long by dropping the
|
||||||
|
* fractional part, exactly like Jackson's default truncation behaviour.
|
||||||
|
*
|
||||||
|
* Usage:
|
||||||
|
*
|
||||||
|
* @Serializable
|
||||||
|
* data class MyData(
|
||||||
|
* @Serializable(with = FloatAsLongSerializer::class)
|
||||||
|
* @SerialName("timestamp") val timestamp: Long = 0L,
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
@Prerelease
|
||||||
|
object FloatAsLongSerializer : KSerializer<Long> {
|
||||||
|
|
||||||
|
override val descriptor: SerialDescriptor =
|
||||||
|
PrimitiveSerialDescriptor("FloatAsLong", PrimitiveKind.LONG)
|
||||||
|
|
||||||
|
override fun deserialize(decoder: Decoder): Long {
|
||||||
|
val jsonDecoder = decoder as? JsonDecoder ?: return decoder.decodeLong()
|
||||||
|
val element = jsonDecoder.decodeJsonElement()
|
||||||
|
if (element !is JsonPrimitive) return 0L
|
||||||
|
return element.longOrNull ?: element.doubleOrNull?.toLong() ?: 0L
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun serialize(encoder: Encoder, value: Long) = encoder.encodeLong(value)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,75 @@
|
||||||
|
package com.lagradost.cloudstream3.utils.serializers
|
||||||
|
|
||||||
|
import com.lagradost.cloudstream3.Prerelease
|
||||||
|
import kotlinx.serialization.KSerializer
|
||||||
|
import kotlinx.serialization.json.JsonArray
|
||||||
|
import kotlinx.serialization.json.JsonElement
|
||||||
|
import kotlinx.serialization.json.JsonNull
|
||||||
|
import kotlinx.serialization.json.JsonObject
|
||||||
|
import kotlinx.serialization.json.JsonPrimitive
|
||||||
|
import kotlinx.serialization.json.JsonTransformingSerializer
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Composable deserialize transformer that applies multiple Jackson-equivalent
|
||||||
|
* behaviours to specific fields by key. Pass only the sets you need; all
|
||||||
|
* default to empty (no-op).
|
||||||
|
*
|
||||||
|
* Behaviours (applied in order per field):
|
||||||
|
* singleValueAsListKeys ACCEPT_SINGLE_VALUE_AS_ARRAY
|
||||||
|
* emptyStringAsNullKeys ACCEPT_EMPTY_STRING_AS_NULL_OBJECT
|
||||||
|
* emptyArrayAsNullKeys ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT
|
||||||
|
*
|
||||||
|
* Usage:
|
||||||
|
*
|
||||||
|
* @OptIn(ExperimentalSerializationApi::class) // KeepGeneratedSerializer is an experimental annotation for now
|
||||||
|
* @KeepGeneratedSerializer
|
||||||
|
* @Serializable(with = MyData.Serializer::class)
|
||||||
|
* data class MyData(
|
||||||
|
* @SerialName("title") val title: String? = null,
|
||||||
|
* @SerialName("tags") val tags: List<String>? = null,
|
||||||
|
* @SerialName("meta") val meta: MyMeta? = null,
|
||||||
|
* ) {
|
||||||
|
* object Serializer : JsonTransformSerializer<MyData>(
|
||||||
|
* MyData.generatedSerializer(),
|
||||||
|
* singleValueAsListKeys = setOf("tags"),
|
||||||
|
* emptyStringAsNullKeys = setOf("title", "tags"),
|
||||||
|
* emptyArrayAsNullKeys = setOf("tags", "meta"),
|
||||||
|
* )
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
@Prerelease
|
||||||
|
abstract class JsonTransformSerializer<T : Any>(
|
||||||
|
tSerializer: KSerializer<T>,
|
||||||
|
private val singleValueAsListKeys: Set<String> = emptySet(),
|
||||||
|
private val emptyArrayAsNullKeys: Set<String> = emptySet(),
|
||||||
|
private val emptyStringAsNullKeys: Set<String> = emptySet(),
|
||||||
|
) : JsonTransformingSerializer<T>(tSerializer) {
|
||||||
|
|
||||||
|
override fun transformDeserialize(element: JsonElement): JsonElement {
|
||||||
|
if (element !is JsonObject) return element
|
||||||
|
return JsonObject(element.mapValues { (key, value) ->
|
||||||
|
var result = value
|
||||||
|
if (key in singleValueAsListKeys) {
|
||||||
|
result = when (result) {
|
||||||
|
is JsonArray -> result
|
||||||
|
JsonNull -> JsonArray(emptyList())
|
||||||
|
else -> JsonArray(listOf(result))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key in emptyStringAsNullKeys) {
|
||||||
|
if (result is JsonPrimitive && result.isString && result.content.isEmpty()) {
|
||||||
|
result = JsonNull
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key in emptyArrayAsNullKeys) {
|
||||||
|
if (result is JsonArray && result.isEmpty()) {
|
||||||
|
result = JsonNull
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -17,24 +17,22 @@ import kotlinx.serialization.json.JsonTransformingSerializer
|
||||||
*
|
*
|
||||||
* Usage:
|
* Usage:
|
||||||
*
|
*
|
||||||
* @OptIn(ExperimentalSerializationApi::class)
|
* @OptIn(ExperimentalSerializationApi::class) // KeepGeneratedSerializer is an experimental annotation for now
|
||||||
* @KeepGeneratedSerializer
|
* @KeepGeneratedSerializer
|
||||||
* @Serializable(with = MyData.Serializer::class)
|
* @Serializable(with = MyData.Serializer::class)
|
||||||
* data class MyData(
|
* data class MyData(
|
||||||
* val tags: List<String> = emptyList(),
|
* @SerialName("tags") val tags: List<String> = emptyList(),
|
||||||
* val title: String = "",
|
* @SerialName("title") val title: String = "",
|
||||||
* val meta: Map<String, String> = emptyMap(),
|
* @SerialName("meta") val meta: Map<String, String> = emptyMap(),
|
||||||
* ) {
|
* ) {
|
||||||
* object Serializer : NonEmptySerializer<MyData>(MyData.generatedSerializer())
|
* object Serializer : NonEmptySerializer<MyData>(MyData.generatedSerializer())
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
@Prerelease
|
|
||||||
abstract class NonEmptySerializer<T : Any>(tSerializer: KSerializer<T>) :
|
abstract class NonEmptySerializer<T : Any>(tSerializer: KSerializer<T>) :
|
||||||
JsonTransformingSerializer<T>(tSerializer) {
|
JsonTransformingSerializer<T>(tSerializer) {
|
||||||
|
|
||||||
override fun transformSerialize(element: JsonElement): JsonElement {
|
override fun transformSerialize(element: JsonElement): JsonElement {
|
||||||
if (element !is JsonObject) return element
|
if (element !is JsonObject) return element
|
||||||
|
|
||||||
return JsonObject(element.filterValues { value ->
|
return JsonObject(element.filterValues { value ->
|
||||||
when (value) {
|
when (value) {
|
||||||
is JsonPrimitive -> value.content.isNotEmpty()
|
is JsonPrimitive -> value.content.isNotEmpty()
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
package com.lagradost.cloudstream3.utils.serializers
|
||||||
|
|
||||||
|
import com.lagradost.cloudstream3.Prerelease
|
||||||
|
import kotlinx.serialization.ExperimentalSerializationApi
|
||||||
|
import kotlinx.serialization.KSerializer
|
||||||
|
import kotlinx.serialization.builtins.serializer
|
||||||
|
import kotlinx.serialization.descriptors.PrimitiveKind
|
||||||
|
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
|
||||||
|
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||||
|
import kotlinx.serialization.encoding.Decoder
|
||||||
|
import kotlinx.serialization.encoding.Encoder
|
||||||
|
import kotlinx.serialization.json.JsonDecoder
|
||||||
|
import kotlinx.serialization.json.JsonNull
|
||||||
|
import kotlinx.serialization.json.JsonPrimitive
|
||||||
|
import kotlinx.serialization.json.decodeFromJsonElement
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience serializer for nullable String fields that combines
|
||||||
|
* ACCEPT_EMPTY_STRING_AS_NULL_OBJECT with null passthrough.
|
||||||
|
* An empty JSON string (`""`) or JSON null is decoded as null.
|
||||||
|
*
|
||||||
|
* Usage:
|
||||||
|
*
|
||||||
|
* @Serializable
|
||||||
|
* data class MyData(
|
||||||
|
* @Serializable(with = NullableStringSerializer::class)
|
||||||
|
* @SerialName("title") val title: String? = null,
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
@Prerelease
|
||||||
|
object NullableStringSerializer : KSerializer<String?> {
|
||||||
|
|
||||||
|
override val descriptor: SerialDescriptor =
|
||||||
|
PrimitiveSerialDescriptor("NullableString", PrimitiveKind.STRING)
|
||||||
|
|
||||||
|
override fun deserialize(decoder: Decoder): String? {
|
||||||
|
val jsonDecoder = decoder as? JsonDecoder ?: return decoder.decodeString()
|
||||||
|
return when (val element = jsonDecoder.decodeJsonElement()) {
|
||||||
|
is JsonPrimitive -> element.content.ifEmpty { null }
|
||||||
|
JsonNull -> null
|
||||||
|
else -> jsonDecoder.json.decodeFromJsonElement(String.serializer(), element)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun serialize(encoder: Encoder, value: String?) {
|
||||||
|
@OptIn(ExperimentalSerializationApi::class) // encodeNull is experimental for now
|
||||||
|
if (value == null) encoder.encodeNull() else encoder.encodeString(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -12,12 +12,12 @@ import kotlinx.serialization.json.JsonTransformingSerializer
|
||||||
*
|
*
|
||||||
* Usage:
|
* Usage:
|
||||||
*
|
*
|
||||||
* @OptIn(ExperimentalSerializationApi::class)
|
* @OptIn(ExperimentalSerializationApi::class) // KeepGeneratedSerializer is an experimental annotation for now
|
||||||
* @KeepGeneratedSerializer
|
* @KeepGeneratedSerializer
|
||||||
* @Serializable(with = MyData.Serializer::class)
|
* @Serializable(with = MyData.Serializer::class)
|
||||||
* data class MyData(
|
* data class MyData(
|
||||||
* val fieldA: String = "",
|
* @SerialName("fieldA") val fieldA: String = "",
|
||||||
* val fieldB: String = "",
|
* @SerialName("fieldB") val fieldB: String = "",
|
||||||
* ) {
|
* ) {
|
||||||
* object Serializer : WriteOnlySerializer<MyData>(
|
* object Serializer : WriteOnlySerializer<MyData>(
|
||||||
* MyData.generatedSerializer(),
|
* MyData.generatedSerializer(),
|
||||||
|
|
@ -25,7 +25,6 @@ import kotlinx.serialization.json.JsonTransformingSerializer
|
||||||
* )
|
* )
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
@Prerelease
|
|
||||||
abstract class WriteOnlySerializer<T : Any>(
|
abstract class WriteOnlySerializer<T : Any>(
|
||||||
tSerializer: KSerializer<T>,
|
tSerializer: KSerializer<T>,
|
||||||
private val keysToIgnore: Set<String>,
|
private val keysToIgnore: Set<String>,
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,602 @@
|
||||||
|
package com.lagradost.cloudstream3.utils.serializers
|
||||||
|
|
||||||
|
import com.lagradost.cloudstream3.utils.AppUtils.parseJson
|
||||||
|
import com.lagradost.cloudstream3.utils.AppUtils.toJson
|
||||||
|
import kotlinx.serialization.ExperimentalSerializationApi
|
||||||
|
import kotlinx.serialization.KeepGeneratedSerializer
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
import kotlin.test.assertFalse
|
||||||
|
import kotlin.test.assertNull
|
||||||
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
|
@OptIn(ExperimentalSerializationApi::class) // KeepGeneratedSerializer is an experimental annotation for now
|
||||||
|
@KeepGeneratedSerializer
|
||||||
|
@Serializable(with = NonEmptyData.Serializer::class)
|
||||||
|
data class NonEmptyData(
|
||||||
|
@SerialName("title") val title: String = "",
|
||||||
|
@SerialName("tags") val tags: List<String> = emptyList(),
|
||||||
|
@SerialName("meta") val meta: Map<String, String> = emptyMap(),
|
||||||
|
@SerialName("name") val name: String = "hello",
|
||||||
|
) {
|
||||||
|
object Serializer : NonEmptySerializer<NonEmptyData>(NonEmptyData.generatedSerializer())
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalSerializationApi::class) // KeepGeneratedSerializer is an experimental annotation for now
|
||||||
|
@KeepGeneratedSerializer
|
||||||
|
@Serializable(with = WriteOnlyData.Serializer::class)
|
||||||
|
data class WriteOnlyData(
|
||||||
|
@SerialName("fieldA") val fieldA: String = "",
|
||||||
|
@SerialName("fieldB") val fieldB: String = "",
|
||||||
|
) {
|
||||||
|
object Serializer : WriteOnlySerializer<WriteOnlyData>(
|
||||||
|
WriteOnlyData.generatedSerializer(),
|
||||||
|
setOf("fieldB"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalSerializationApi::class) // KeepGeneratedSerializer is an experimental annotation for now
|
||||||
|
@KeepGeneratedSerializer
|
||||||
|
@Serializable(with = MultiWriteOnly.Serializer::class)
|
||||||
|
data class MultiWriteOnly(
|
||||||
|
@SerialName("fieldA") val fieldA: String = "",
|
||||||
|
@SerialName("fieldB") val fieldB: String = "",
|
||||||
|
@SerialName("fieldC") val fieldC: String = "",
|
||||||
|
) {
|
||||||
|
object Serializer : WriteOnlySerializer<MultiWriteOnly>(
|
||||||
|
MultiWriteOnly.generatedSerializer(),
|
||||||
|
setOf("fieldB", "fieldC"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalSerializationApi::class) // KeepGeneratedSerializer is an experimental annotation for now
|
||||||
|
@KeepGeneratedSerializer
|
||||||
|
@Serializable(with = SingleValueData.Serializer::class)
|
||||||
|
data class SingleValueData(
|
||||||
|
@SerialName("tags") val tags: List<String> = emptyList(),
|
||||||
|
@SerialName("nums") val nums: List<Int> = emptyList(),
|
||||||
|
) {
|
||||||
|
object Serializer : JsonTransformSerializer<SingleValueData>(
|
||||||
|
SingleValueData.generatedSerializer(),
|
||||||
|
singleValueAsListKeys = setOf("tags", "nums"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class NestedMeta(
|
||||||
|
@SerialName("key") val key: String = "",
|
||||||
|
)
|
||||||
|
|
||||||
|
@OptIn(ExperimentalSerializationApi::class) // KeepGeneratedSerializer is an experimental annotation for now
|
||||||
|
@KeepGeneratedSerializer
|
||||||
|
@Serializable(with = EmptyArrayData.Serializer::class)
|
||||||
|
data class EmptyArrayData(
|
||||||
|
@SerialName("meta") val meta: NestedMeta? = null,
|
||||||
|
@SerialName("other") val other: String = "hello",
|
||||||
|
) {
|
||||||
|
object Serializer : JsonTransformSerializer<EmptyArrayData>(
|
||||||
|
EmptyArrayData.generatedSerializer(),
|
||||||
|
emptyArrayAsNullKeys = setOf("meta"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalSerializationApi::class) // KeepGeneratedSerializer is an experimental annotation for now
|
||||||
|
@KeepGeneratedSerializer
|
||||||
|
@Serializable(with = EmptyStringData.Serializer::class)
|
||||||
|
data class EmptyStringData(
|
||||||
|
@SerialName("title") val title: String? = null,
|
||||||
|
@SerialName("episode") val episode: NestedMeta? = null,
|
||||||
|
@SerialName("keep") val keep: String? = "hello",
|
||||||
|
) {
|
||||||
|
object Serializer : JsonTransformSerializer<EmptyStringData>(
|
||||||
|
EmptyStringData.generatedSerializer(),
|
||||||
|
emptyStringAsNullKeys = setOf("title", "episode", "keep"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalSerializationApi::class) // KeepGeneratedSerializer is an experimental annotation for now
|
||||||
|
@KeepGeneratedSerializer
|
||||||
|
@Serializable(with = SingleValueOrNullData.Serializer::class)
|
||||||
|
data class SingleValueOrNullData(
|
||||||
|
@SerialName("tags") val tags: List<String>? = null,
|
||||||
|
@SerialName("nums") val nums: List<Int>? = null,
|
||||||
|
@SerialName("other") val other: String = "hello",
|
||||||
|
) {
|
||||||
|
object Serializer : JsonTransformSerializer<SingleValueOrNullData>(
|
||||||
|
SingleValueOrNullData.generatedSerializer(),
|
||||||
|
singleValueAsListKeys = setOf("tags", "nums"),
|
||||||
|
emptyArrayAsNullKeys = setOf("tags", "nums"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalSerializationApi::class) // KeepGeneratedSerializer is an experimental annotation for now
|
||||||
|
@KeepGeneratedSerializer
|
||||||
|
@Serializable(with = NullableFieldsData.Serializer::class)
|
||||||
|
data class NullableFieldsData(
|
||||||
|
@SerialName("title") val title: String? = null,
|
||||||
|
@SerialName("meta") val meta: NestedMeta? = null,
|
||||||
|
@SerialName("other") val other: String = "hello",
|
||||||
|
) {
|
||||||
|
object Serializer : JsonTransformSerializer<NullableFieldsData>(
|
||||||
|
NullableFieldsData.generatedSerializer(),
|
||||||
|
emptyStringAsNullKeys = setOf("title"),
|
||||||
|
emptyArrayAsNullKeys = setOf("meta"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalSerializationApi::class) // KeepGeneratedSerializer is an experimental annotation for now
|
||||||
|
@KeepGeneratedSerializer
|
||||||
|
@Serializable(with = SingleValueOrEmptyStringData.Serializer::class)
|
||||||
|
data class SingleValueOrEmptyStringData(
|
||||||
|
@SerialName("tags") val tags: List<String> = emptyList(),
|
||||||
|
@SerialName("title") val title: String? = null,
|
||||||
|
) {
|
||||||
|
object Serializer : JsonTransformSerializer<SingleValueOrEmptyStringData>(
|
||||||
|
SingleValueOrEmptyStringData.generatedSerializer(),
|
||||||
|
singleValueAsListKeys = setOf("tags"),
|
||||||
|
emptyStringAsNullKeys = setOf("title"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalSerializationApi::class) // KeepGeneratedSerializer is an experimental annotation for now
|
||||||
|
@KeepGeneratedSerializer
|
||||||
|
@Serializable(with = AllTransformsData.Serializer::class)
|
||||||
|
data class AllTransformsData(
|
||||||
|
@SerialName("tags") val tags: List<String>? = null,
|
||||||
|
@SerialName("title") val title: String? = null,
|
||||||
|
@SerialName("meta") val meta: NestedMeta? = null,
|
||||||
|
@SerialName("other") val other: String = "hello",
|
||||||
|
) {
|
||||||
|
object Serializer : JsonTransformSerializer<AllTransformsData>(
|
||||||
|
AllTransformsData.generatedSerializer(),
|
||||||
|
singleValueAsListKeys = setOf("tags"),
|
||||||
|
emptyArrayAsNullKeys = setOf("tags", "meta"),
|
||||||
|
emptyStringAsNullKeys = setOf("title", "tags"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class FloatIntData(
|
||||||
|
@Serializable(with = FloatAsIntSerializer::class)
|
||||||
|
@SerialName("count") val count: Int = 0,
|
||||||
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class FloatLongData(
|
||||||
|
@Serializable(with = FloatAsLongSerializer::class)
|
||||||
|
@SerialName("timestamp") val timestamp: Long = 0L,
|
||||||
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class NullableStringData(
|
||||||
|
@Serializable(with = NullableStringSerializer::class)
|
||||||
|
@SerialName("title") val title: String? = null,
|
||||||
|
)
|
||||||
|
|
||||||
|
class SerializersTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun nonEmptySerializerOmitsEmptyStrings() {
|
||||||
|
val data = NonEmptyData(title = "", name = "hello")
|
||||||
|
val result = data.toJson()
|
||||||
|
assertFalse(result.contains("title"))
|
||||||
|
assertTrue(result.contains("name"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun nonEmptySerializerOmitsEmptyLists() {
|
||||||
|
val data = NonEmptyData(tags = emptyList(), name = "hello")
|
||||||
|
val result = data.toJson()
|
||||||
|
assertFalse(result.contains("tags"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun nonEmptySerializerOmitsEmptyMaps() {
|
||||||
|
val data = NonEmptyData(meta = emptyMap(), name = "hello")
|
||||||
|
val result = data.toJson()
|
||||||
|
assertFalse(result.contains("meta"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun nonEmptySerializerKeepsNonEmptyFields() {
|
||||||
|
val data = NonEmptyData(title = "hello", tags = listOf("a"), meta = mapOf("k" to "v"))
|
||||||
|
val result = data.toJson()
|
||||||
|
assertTrue(result.contains("title"))
|
||||||
|
assertTrue(result.contains("tags"))
|
||||||
|
assertTrue(result.contains("meta"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun nonEmptySerializerDoesNotAffectDeserialization() {
|
||||||
|
val input = """{"title":"hello","tags":["a"],"meta":{"k":"v"},"name":"world"}"""
|
||||||
|
val result = parseJson<NonEmptyData>(input)
|
||||||
|
assertEquals("hello", result.title)
|
||||||
|
assertEquals(listOf("a"), result.tags)
|
||||||
|
assertEquals(mapOf("k" to "v"), result.meta)
|
||||||
|
assertEquals("world", result.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun writeOnlySerializerOmitsFieldOnSerialize() {
|
||||||
|
val data = WriteOnlyData(fieldA = "hello", fieldB = "secret")
|
||||||
|
val result = data.toJson()
|
||||||
|
assertTrue(result.contains("fieldA"))
|
||||||
|
assertFalse(result.contains("fieldB"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun writeOnlySerializerDeserializesNormally() {
|
||||||
|
val input = """{"fieldA":"hello","fieldB":"secret"}"""
|
||||||
|
val result = parseJson<WriteOnlyData>(input)
|
||||||
|
assertEquals("hello", result.fieldA)
|
||||||
|
assertEquals("secret", result.fieldB)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun writeOnlySerializerDeserializesMissingAsDefault() {
|
||||||
|
val input = """{"fieldA":"hello"}"""
|
||||||
|
val result = parseJson<WriteOnlyData>(input)
|
||||||
|
assertEquals("hello", result.fieldA)
|
||||||
|
assertEquals("", result.fieldB)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun writeOnlySerializerHandlesMultipleKeys() {
|
||||||
|
val data = MultiWriteOnly(fieldA = "hello", fieldB = "secret1", fieldC = "secret2")
|
||||||
|
val result = data.toJson()
|
||||||
|
assertTrue(result.contains("fieldA"))
|
||||||
|
assertFalse(result.contains("fieldB"))
|
||||||
|
assertFalse(result.contains("fieldC"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun singleValueAsListDecodesArrayNormally() {
|
||||||
|
val input = """{"tags":["a","b"],"nums":[1,2]}"""
|
||||||
|
val result = parseJson<SingleValueData>(input)
|
||||||
|
assertEquals(listOf("a", "b"), result.tags)
|
||||||
|
assertEquals(listOf(1, 2), result.nums)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun singleValueAsListWrapsBareStringInList() {
|
||||||
|
val input = """{"tags":"a","nums":[1]}"""
|
||||||
|
val result = parseJson<SingleValueData>(input)
|
||||||
|
assertEquals(listOf("a"), result.tags)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun singleValueAsListWrapsBareIntInList() {
|
||||||
|
val input = """{"tags":[],"nums":42}"""
|
||||||
|
val result = parseJson<SingleValueData>(input)
|
||||||
|
assertEquals(listOf(42), result.nums)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun singleValueAsListDecodesNullAsEmptyList() {
|
||||||
|
val input = """{"tags":null,"nums":[]}"""
|
||||||
|
val result = parseJson<SingleValueData>(input)
|
||||||
|
assertEquals(emptyList<String>(), result.tags)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun singleValueAsListRoundtripsCorrectly() {
|
||||||
|
val data = SingleValueData(tags = listOf("x", "y"), nums = listOf(1, 2))
|
||||||
|
val encoded = data.toJson()
|
||||||
|
val decoded = parseJson<SingleValueData>(encoded)
|
||||||
|
assertEquals(data, decoded)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun emptyArrayAsNullDecodesEmptyArrayAsNull() {
|
||||||
|
val input = """{"meta":[],"other":"hello"}"""
|
||||||
|
val result = parseJson<EmptyArrayData>(input)
|
||||||
|
assertNull(result.meta)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun emptyArrayAsNullDecodesNullAsNull() {
|
||||||
|
val input = """{"meta":null,"other":"hello"}"""
|
||||||
|
val result = parseJson<EmptyArrayData>(input)
|
||||||
|
assertNull(result.meta)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun emptyArrayAsNullDecodesObjectNormally() {
|
||||||
|
val input = """{"meta":{"key":"value"},"other":"hello"}"""
|
||||||
|
val result = parseJson<EmptyArrayData>(input)
|
||||||
|
assertEquals(NestedMeta("value"), result.meta)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun emptyArrayAsNullDoesNotAffectOtherFields() {
|
||||||
|
val input = """{"meta":[],"other":"world"}"""
|
||||||
|
val result = parseJson<EmptyArrayData>(input)
|
||||||
|
assertEquals("world", result.other)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun emptyArrayAsNullRoundtripsCorrectly() {
|
||||||
|
val data = EmptyArrayData(meta = NestedMeta("test"), other = "hello")
|
||||||
|
val encoded = data.toJson()
|
||||||
|
val decoded = parseJson<EmptyArrayData>(encoded)
|
||||||
|
assertEquals(data, decoded)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun emptyStringAsNullDecodesEmptyStringAsNull() {
|
||||||
|
val input = """{"title":"","episode":null,"keep":"hello"}"""
|
||||||
|
val result = parseJson<EmptyStringData>(input)
|
||||||
|
assertNull(result.title)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun emptyStringAsNullDecodesNullAsNull() {
|
||||||
|
val input = """{"title":null,"episode":null,"keep":"hello"}"""
|
||||||
|
val result = parseJson<EmptyStringData>(input)
|
||||||
|
assertNull(result.title)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun emptyStringAsNullKeepsNonEmptyString() {
|
||||||
|
val input = """{"title":"hello","episode":null,"keep":"world"}"""
|
||||||
|
val result = parseJson<EmptyStringData>(input)
|
||||||
|
assertEquals("hello", result.title)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun emptyStringAsNullDecodesObjectNormally() {
|
||||||
|
val input = """{"title":null,"episode":{"key":"value"},"keep":"hello"}"""
|
||||||
|
val result = parseJson<EmptyStringData>(input)
|
||||||
|
assertEquals(NestedMeta("value"), result.episode)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun emptyStringAsNullDoesNotAffectNonEmptyFields() {
|
||||||
|
val input = """{"title":"","episode":null,"keep":"world"}"""
|
||||||
|
val result = parseJson<EmptyStringData>(input)
|
||||||
|
assertEquals("world", result.keep)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun emptyStringAsNullRoundtripsCorrectly() {
|
||||||
|
val data = EmptyStringData(title = "hello", episode = NestedMeta("x"), keep = "world")
|
||||||
|
val encoded = data.toJson()
|
||||||
|
val decoded = parseJson<EmptyStringData>(encoded)
|
||||||
|
assertEquals(data, decoded)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun singleValueOrNullWrapsBareValueInList() {
|
||||||
|
val input = """{"tags":"a","nums":1,"other":"hello"}"""
|
||||||
|
val result = parseJson<SingleValueOrNullData>(input)
|
||||||
|
assertEquals(listOf("a"), result.tags)
|
||||||
|
assertEquals(listOf(1), result.nums)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun singleValueOrNullTreatsEmptyArrayAsNull() {
|
||||||
|
val input = """{"tags":[],"nums":[],"other":"hello"}"""
|
||||||
|
val result = parseJson<SingleValueOrNullData>(input)
|
||||||
|
assertNull(result.tags)
|
||||||
|
assertNull(result.nums)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun singleValueOrNullDecodesArrayNormally() {
|
||||||
|
val input = """{"tags":["a","b"],"nums":[1,2],"other":"hello"}"""
|
||||||
|
val result = parseJson<SingleValueOrNullData>(input)
|
||||||
|
assertEquals(listOf("a", "b"), result.tags)
|
||||||
|
assertEquals(listOf(1, 2), result.nums)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun singleValueOrNullDoesNotAffectOtherFields() {
|
||||||
|
val input = """{"tags":[],"nums":[],"other":"world"}"""
|
||||||
|
val result = parseJson<SingleValueOrNullData>(input)
|
||||||
|
assertEquals("world", result.other)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun nullableFieldsEmptyStringBecomesNull() {
|
||||||
|
val input = """{"title":"","meta":{"key":"value"},"other":"hello"}"""
|
||||||
|
val result = parseJson<NullableFieldsData>(input)
|
||||||
|
assertNull(result.title)
|
||||||
|
assertEquals(NestedMeta("value"), result.meta)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun nullableFieldsEmptyArrayBecomesNull() {
|
||||||
|
val input = """{"title":"hello","meta":[],"other":"hello"}"""
|
||||||
|
val result = parseJson<NullableFieldsData>(input)
|
||||||
|
assertEquals("hello", result.title)
|
||||||
|
assertNull(result.meta)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun nullableFieldsBothNullAtOnce() {
|
||||||
|
val input = """{"title":"","meta":[],"other":"hello"}"""
|
||||||
|
val result = parseJson<NullableFieldsData>(input)
|
||||||
|
assertNull(result.title)
|
||||||
|
assertNull(result.meta)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun nullableFieldsDoesNotAffectOtherFields() {
|
||||||
|
val input = """{"title":"","meta":[],"other":"world"}"""
|
||||||
|
val result = parseJson<NullableFieldsData>(input)
|
||||||
|
assertEquals("world", result.other)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun nullableFieldsRoundtripsCorrectly() {
|
||||||
|
val data = NullableFieldsData(title = "hello", meta = NestedMeta("x"), other = "world")
|
||||||
|
val encoded = data.toJson()
|
||||||
|
val decoded = parseJson<NullableFieldsData>(encoded)
|
||||||
|
assertEquals(data, decoded)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun singleValueOrEmptyStringWrapsBareString() {
|
||||||
|
val input = """{"tags":"a","title":"hello"}"""
|
||||||
|
val result = parseJson<SingleValueOrEmptyStringData>(input)
|
||||||
|
assertEquals(listOf("a"), result.tags)
|
||||||
|
assertEquals("hello", result.title)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun singleValueOrEmptyStringTurnsEmptyTitleToNull() {
|
||||||
|
val input = """{"tags":["a"],"title":""}"""
|
||||||
|
val result = parseJson<SingleValueOrEmptyStringData>(input)
|
||||||
|
assertEquals(listOf("a"), result.tags)
|
||||||
|
assertNull(result.title)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun singleValueOrEmptyStringRoundtripsCorrectly() {
|
||||||
|
val data = SingleValueOrEmptyStringData(tags = listOf("x"), title = "hello")
|
||||||
|
val encoded = data.toJson()
|
||||||
|
val decoded = parseJson<SingleValueOrEmptyStringData>(encoded)
|
||||||
|
assertEquals(data, decoded)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun allTransformsWrapsBareStringInList() {
|
||||||
|
val input = """{"tags":"a","title":"hello","meta":{"key":"value"},"other":"world"}"""
|
||||||
|
val result = parseJson<AllTransformsData>(input)
|
||||||
|
assertEquals(listOf("a"), result.tags)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun allTransformsEmptyArrayTagsBecomesNull() {
|
||||||
|
val input = """{"tags":[],"title":"hello","meta":{"key":"value"},"other":"world"}"""
|
||||||
|
val result = parseJson<AllTransformsData>(input)
|
||||||
|
assertNull(result.tags)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun allTransformsEmptyMetaBecomesNull() {
|
||||||
|
val input = """{"tags":["a"],"title":"hello","meta":[],"other":"world"}"""
|
||||||
|
val result = parseJson<AllTransformsData>(input)
|
||||||
|
assertNull(result.meta)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun allTransformsEmptyTitleBecomesNull() {
|
||||||
|
val input = """{"tags":["a"],"title":"","meta":{"key":"value"},"other":"world"}"""
|
||||||
|
val result = parseJson<AllTransformsData>(input)
|
||||||
|
assertNull(result.title)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun allTransformsAllNullAtOnce() {
|
||||||
|
val input = """{"tags":[],"title":"","meta":[],"other":"world"}"""
|
||||||
|
val result = parseJson<AllTransformsData>(input)
|
||||||
|
assertNull(result.tags)
|
||||||
|
assertNull(result.title)
|
||||||
|
assertNull(result.meta)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun allTransformsDoesNotAffectOtherFields() {
|
||||||
|
val input = """{"tags":[],"title":"","meta":[],"other":"world"}"""
|
||||||
|
val result = parseJson<AllTransformsData>(input)
|
||||||
|
assertEquals("world", result.other)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun allTransformsRoundtripsCorrectly() {
|
||||||
|
val data = AllTransformsData(tags = listOf("a"), title = "hello", meta = NestedMeta("x"), other = "world")
|
||||||
|
val encoded = data.toJson()
|
||||||
|
val decoded = parseJson<AllTransformsData>(encoded)
|
||||||
|
assertEquals(data, decoded)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun floatAsIntTruncatesFloat() {
|
||||||
|
val input = """{"count":3.9}"""
|
||||||
|
val result = parseJson<FloatIntData>(input)
|
||||||
|
assertEquals(3, result.count)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun floatAsIntDecodesIntNormally() {
|
||||||
|
val input = """{"count":42}"""
|
||||||
|
val result = parseJson<FloatIntData>(input)
|
||||||
|
assertEquals(42, result.count)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun floatAsIntHandlesNegativeFloat() {
|
||||||
|
val input = """{"count":-2.7}"""
|
||||||
|
val result = parseJson<FloatIntData>(input)
|
||||||
|
assertEquals(-2, result.count)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun floatAsIntRoundtripsCorrectly() {
|
||||||
|
val data = FloatIntData(count = 7)
|
||||||
|
val encoded = data.toJson()
|
||||||
|
val decoded = parseJson<FloatIntData>(encoded)
|
||||||
|
assertEquals(data, decoded)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun floatAsLongTruncatesFloat() {
|
||||||
|
val input = """{"timestamp":1234567890.9}"""
|
||||||
|
val result = parseJson<FloatLongData>(input)
|
||||||
|
assertEquals(1234567890L, result.timestamp)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun floatAsLongDecodesLongNormally() {
|
||||||
|
val input = """{"timestamp":9999999999}"""
|
||||||
|
val result = parseJson<FloatLongData>(input)
|
||||||
|
assertEquals(9999999999L, result.timestamp)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun floatAsLongHandlesNegativeFloat() {
|
||||||
|
val input = """{"timestamp":-100.6}"""
|
||||||
|
val result = parseJson<FloatLongData>(input)
|
||||||
|
assertEquals(-100L, result.timestamp)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun floatAsLongRoundtripsCorrectly() {
|
||||||
|
val data = FloatLongData(timestamp = 1700000000L)
|
||||||
|
val encoded = data.toJson()
|
||||||
|
val decoded = parseJson<FloatLongData>(encoded)
|
||||||
|
assertEquals(data, decoded)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun nullableStringDecodesEmptyStringAsNull() {
|
||||||
|
val input = """{"title":""}"""
|
||||||
|
val result = parseJson<NullableStringData>(input)
|
||||||
|
assertNull(result.title)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun nullableStringDecodesNullAsNull() {
|
||||||
|
val input = """{"title":null}"""
|
||||||
|
val result = parseJson<NullableStringData>(input)
|
||||||
|
assertNull(result.title)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun nullableStringKeepsNonEmptyString() {
|
||||||
|
val input = """{"title":"hello"}"""
|
||||||
|
val result = parseJson<NullableStringData>(input)
|
||||||
|
assertEquals("hello", result.title)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun nullableStringRoundtripsCorrectly() {
|
||||||
|
val data = NullableStringData(title = "world")
|
||||||
|
val encoded = data.toJson()
|
||||||
|
val decoded = parseJson<NullableStringData>(encoded)
|
||||||
|
assertEquals(data, decoded)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue