Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
211 commits
Select commit Hold shift + click to select a range
9ba0661
Test kotlinx-serialization support
Luna712 May 13, 2026
d7db2e0
-
Luna712 May 13, 2026
94a6bc9
Add
Luna712 May 13, 2026
450e767
Update
Luna712 May 14, 2026
bcad70a
Try
Luna712 May 14, 2026
167b3ba
Update
Luna712 May 14, 2026
67a4439
-
Luna712 May 14, 2026
4329599
Fix
Luna712 May 14, 2026
4f0d867
Data class
Luna712 May 14, 2026
809e9bd
Fix
Luna712 May 14, 2026
11d07f4
No data class
Luna712 May 14, 2026
19fdb83
Add
Luna712 May 14, 2026
52e5689
add
Luna712 May 14, 2026
0e552c1
Add
Luna712 May 14, 2026
2167bf2
Add
Luna712 May 14, 2026
e26c8fc
Update
Luna712 May 14, 2026
80fff23
JsonElement
Luna712 May 14, 2026
817b5d3
Use JsonElement
Luna712 May 14, 2026
bc8efcd
Fix
Luna712 May 14, 2026
2694184
Fix
Luna712 May 14, 2026
ca8032f
Fix val
Luna712 May 14, 2026
e062e6e
Try transient
Luna712 May 14, 2026
b451213
Fix defaults
Luna712 May 14, 2026
5a9517a
Fix cast
Luna712 May 14, 2026
b913d2c
Fix defaults
Luna712 May 14, 2026
120bb73
+ExtractorLink
Luna712 May 14, 2026
2a9aca2
+SubtitleData
Luna712 May 14, 2026
52e468b
+ResultEpisode
Luna712 May 14, 2026
164331f
Transient
Luna712 May 14, 2026
8a1d1f8
+AudioFile
Luna712 May 14, 2026
35c0d65
+SeasonData
Luna712 May 14, 2026
95f553f
Add UriSerializer
Luna712 May 14, 2026
bc54724
Use UriSerializer
Luna712 May 14, 2026
cb4e6d3
Use UriSerializer
Luna712 May 14, 2026
74960ea
Fix parser
Luna712 May 14, 2026
9aeac02
Try support in DataStore
Luna712 May 14, 2026
f152393
Fix
Luna712 May 14, 2026
2494687
Fix
Luna712 May 14, 2026
e8cad16
Public
Luna712 May 14, 2026
162e23f
Try AppUtils support
Luna712 May 14, 2026
03f3905
Fix?
Luna712 May 14, 2026
1c1ee88
-
Luna712 May 14, 2026
3d893a9
-
Luna712 May 14, 2026
f9cc1d5
Fix parse
Luna712 May 14, 2026
656477c
Fix
Luna712 May 14, 2026
fda2886
Fix
Luna712 May 14, 2026
b49ca7a
Fix
Luna712 May 14, 2026
9cef364
Fix
Luna712 May 14, 2026
a1faeb4
Try fix
Luna712 May 14, 2026
a0aeb13
Fix
Luna712 May 14, 2026
0f3e2e3
-
Luna712 May 14, 2026
58244ec
Fix
Luna712 May 14, 2026
64f77aa
Merge branch 'coil-ktor' into test-kotlinx
Luna712 May 15, 2026
392caec
Merge branch 'coil-ktor' into test-kotlinx
Luna712 May 15, 2026
f465a06
Merge branch 'coil-ktor' into test-kotlinx
Luna712 May 15, 2026
56bbf25
Support
Luna712 May 15, 2026
63dc8e2
Fix
Luna712 May 15, 2026
1dea389
Merge branch 'coil-ktor' into test-kotlinx
Luna712 Jun 4, 2026
4ed9d01
Update
Luna712 Jun 4, 2026
3625dd3
Update
Luna712 Jun 4, 2026
5e052cc
-
Luna712 Jun 4, 2026
07a0231
-
Luna712 Jun 4, 2026
d3e7e67
Fix
Luna712 Jun 4, 2026
15a3ce1
Update
Luna712 Jun 6, 2026
5ba22da
Update
Luna712 Jun 6, 2026
d9617ac
Update
Luna712 Jun 6, 2026
03056da
Test
Luna712 Jun 6, 2026
593aca5
Fix
Luna712 Jun 6, 2026
d8cb28a
Update
Luna712 Jun 6, 2026
b2425bd
Try
Luna712 Jun 6, 2026
24b064d
explicitNulls = false test
Luna712 Jun 6, 2026
7789057
Try some changes
Luna712 Jun 6, 2026
8b9a62b
Add Array
Luna712 Jun 6, 2026
6c46bce
Support mixed types
Luna712 Jun 6, 2026
9a3acda
Try fallback
Luna712 Jun 6, 2026
6413d4e
test
Luna712 Jun 6, 2026
3b58609
Test
Luna712 Jun 6, 2026
69afa64
Try fixing transient
Luna712 Jun 6, 2026
25daec3
Fix parent
Luna712 Jun 6, 2026
2276194
Merge branch 'coil-ktor' into test-kotlinx
Luna712 Jun 21, 2026
019b877
Fix
Luna712 Jun 21, 2026
40fa2cb
Merge branch 'coil-ktor' into test-kotlinx
Luna712 Jun 23, 2026
749299e
Merge branch 'coil-ktor' into test-kotlinx
Luna712 Jun 23, 2026
3deb498
Update anilist
Luna712 Jun 23, 2026
3d30b97
Update
Luna712 Jun 23, 2026
08a523b
-test
Luna712 Jun 23, 2026
ac9b1af
run tests
Luna712 Jun 23, 2026
3beff90
Update MainAPI
Luna712 Jun 23, 2026
b3739c3
Try all tests at once
Luna712 Jun 23, 2026
7ac2d5f
Update
Luna712 Jun 23, 2026
76fde00
Update MDL
Luna712 Jun 23, 2026
895d5f5
Update
Luna712 Jun 23, 2026
326b71b
Fix
Luna712 Jun 23, 2026
52a017d
Fix
Luna712 Jun 23, 2026
64fa059
Fix trakt
Luna712 Jun 23, 2026
6e7bb28
Fix
Luna712 Jun 23, 2026
7af8234
Order
Luna712 Jun 23, 2026
0007b20
Try change
Luna712 Jun 23, 2026
9c87eab
Update
Luna712 Jun 23, 2026
58bc3bc
Update
Luna712 Jun 23, 2026
66b4a52
+
Luna712 Jun 23, 2026
cd268e8
-
Luna712 Jun 23, 2026
762e63e
Update
Luna712 Jun 23, 2026
430069f
Add
Luna712 Jun 23, 2026
1d8d9b6
test
Luna712 Jun 23, 2026
4ff80f5
Merge branch 'coil-ktor' into test-kotlinx
Luna712 Jun 23, 2026
0cc033e
Merge branch 'coil-ktor' into test-kotlinx
Luna712 Jun 23, 2026
2ece0b8
Merge branch 'coil-ktor' into test-kotlinx
Luna712 Jun 23, 2026
4f738a5
Fix anilist
Luna712 Jun 24, 2026
9d4d3c4
Fix trakt
Luna712 Jun 24, 2026
7e08cda
Fix anilist
Luna712 Jun 24, 2026
bbdca39
Merge branch 'coil-ktor' into test-kotlinx
Luna712 Jun 24, 2026
80d29e3
Update
Luna712 Jun 25, 2026
6c2c863
Update
Luna712 Jun 25, 2026
a440d1c
Fix
Luna712 Jun 25, 2026
939c97a
Keep JsonProperty
Luna712 Jun 25, 2026
e65b4ee
replace toKotlinObject
Luna712 Jun 25, 2026
087ec75
Update Simkl
Luna712 Jun 25, 2026
ba0bd30
Merge branch 'coil-ktor' into test-kotlinx
Luna712 Jun 25, 2026
1cb27c2
Update BackupUtils
Luna712 Jun 25, 2026
8ab4513
Update Torrent
Luna712 Jun 25, 2026
cad8b33
Update SyncUtil
Luna712 Jun 25, 2026
4e1586f
Update ControllerActivity
Luna712 Jun 25, 2026
784ca77
Fix
Luna712 Jun 25, 2026
076433a
Remove use of toKotlinObject
Luna712 Jun 25, 2026
a5b41e2
Fix
Luna712 Jun 25, 2026
f9d4b97
Update aes
Luna712 Jun 25, 2026
901dac9
Update gogohelper
Luna712 Jun 25, 2026
f12063f
Update JWPlayerHelper
Luna712 Jun 25, 2026
a70f75c
Update wcohelper
Luna712 Jun 25, 2026
b35aebf
Fix match for ExtractorAPI
Luna712 Jun 25, 2026
142654c
Try
Luna712 Jun 25, 2026
f74afe2
+
Luna712 Jun 25, 2026
e8a1bd8
Fix
Luna712 Jun 25, 2026
fd22a32
Fix subtitle
Luna712 Jun 25, 2026
0654b82
-
Luna712 Jun 25, 2026
521e7fc
Update InAppUpdater
Luna712 Jun 25, 2026
52d65af
Update DataStoreHelper
Luna712 Jun 25, 2026
12c3827
Fix
Luna712 Jun 25, 2026
d073639
WriteOnly
Luna712 Jun 25, 2026
a5aac7c
Update
Luna712 Jun 26, 2026
be71cbd
-
Luna712 Jun 26, 2026
95c0eed
Comments
Luna712 Jun 26, 2026
1088846
Skip abstract
Luna712 Jun 26, 2026
76a3926
Fix
Luna712 Jun 26, 2026
042817e
Fix
Luna712 Jun 26, 2026
694193f
Update DownloadObjects
Luna712 Jun 26, 2026
08eab05
Skip
Luna712 Jun 26, 2026
135b137
Fix
Luna712 Jun 26, 2026
5c8cbfb
Merge branch 'coil-ktor' into test-kotlinx
Luna712 Jun 26, 2026
22d8b41
-
Luna712 Jun 26, 2026
a479c88
Fix
Luna712 Jun 26, 2026
17858a0
Update DataStoreHelper
Luna712 Jun 26, 2026
e10bec1
Update
Luna712 Jun 26, 2026
b2ea5bb
logging test apputils
Luna712 Jun 26, 2026
506c89e
trace logging
Luna712 Jun 26, 2026
d9af390
Test kotlinx inline
Luna712 Jun 26, 2026
90dcd5e
Fix
Luna712 Jun 26, 2026
4e3244a
Test
Luna712 Jun 26, 2026
d6f81b5
Fix
Luna712 Jun 26, 2026
6e2001c
Revert
Luna712 Jun 26, 2026
3d85bfb
Add inline version
Luna712 Jun 26, 2026
6457624
Add inline version
Luna712 Jun 26, 2026
653190f
Add inline version
Luna712 Jun 26, 2026
8d63c64
Fix
Luna712 Jun 26, 2026
5e5e8b2
Fix
Luna712 Jun 26, 2026
89d8b5a
Fix
Luna712 Jun 26, 2026
279c5b7
Fix
Luna712 Jun 26, 2026
b24d9c7
-
Luna712 Jun 26, 2026
5ad9ddd
Fix
Luna712 Jun 26, 2026
9765430
Fix
Luna712 Jun 26, 2026
2360256
Fix
Luna712 Jun 26, 2026
fdd4f20
Update
Luna712 Jun 26, 2026
34e2ae5
Merge branch 'coil-ktor' into test-kotlinx
Luna712 Jun 30, 2026
046f11b
Try fix Smikl
Luna712 Jul 1, 2026
29e8877
Add JsonIgnore
Luna712 Jul 1, 2026
fcd9503
Cleanup
Luna712 Jul 1, 2026
614a8b0
fix
Luna712 Jul 1, 2026
648faef
Update
Luna712 Jul 2, 2026
a0cf609
Merge branch 'coil-ktor' into test-kotlinx
Luna712 Jul 2, 2026
b9fd839
Merge branch 'coil-ktor' into test-kotlinx
Luna712 Jul 2, 2026
7233ace
Update
Luna712 Jul 2, 2026
a347819
Merge branch 'coil-ktor' into test-kotlinx
Luna712 Jul 2, 2026
d7e2880
Merge branch 'coil-ktor' into test-kotlinx
Luna712 Jul 3, 2026
6327319
Update
Luna712 Jul 3, 2026
8d2bd6c
Merge branch 'coil-ktor' into test-kotlinx
Luna712 Jul 3, 2026
ce40964
Update
Luna712 Jul 3, 2026
6a1f23f
Use interface
Luna712 Jul 4, 2026
a2dd9ad
Try making LibrarySearchResponse an interface
Luna712 Jul 4, 2026
4ed1e1e
Try
Luna712 Jul 4, 2026
727aa9b
Bump
Luna712 Jul 4, 2026
ec89fca
Try
Luna712 Jul 4, 2026
36d4823
Try
Luna712 Jul 4, 2026
ccbde54
Try fix
Luna712 Jul 4, 2026
82b0b38
Test
Luna712 Jul 4, 2026
8e00bde
Test
Luna712 Jul 4, 2026
32d389c
Merge branch 'coil-ktor' into test-kotlinx
Luna712 Jul 7, 2026
c2163ce
abstract again
Luna712 Jul 7, 2026
b55512b
Merge branch 'coil-ktor' into test-kotlinx
Luna712 Jul 8, 2026
c18dde8
Merge branch 'coil-ktor' into test-kotlinx
Luna712 Jul 9, 2026
62c59db
Merge branch 'coil-ktor' into test-kotlinx
Luna712 Jul 9, 2026
e5e4b41
Merge branch 'coil-ktor' into test-kotlinx
Luna712 Jul 10, 2026
c1aee00
Merge branch 'coil-ktor' into test-kotlinx
Luna712 Jul 10, 2026
a5e29a1
-
Luna712 Jul 10, 2026
6746ab7
-
Luna712 Jul 10, 2026
2999f1f
-
Luna712 Jul 10, 2026
d41a86c
Merge branch 'coil-ktor' into test-kotlinx
Luna712 Jul 10, 2026
d7491ff
-
Luna712 Jul 10, 2026
0bdf039
Merge branch 'coil-ktor' into test-kotlinx
Luna712 Jul 12, 2026
d9ab052
-
Luna712 Jul 12, 2026
43c4892
-
Luna712 Jul 12, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
# run: ./gradlew library:checkKotlinAbi

- name: Run Gradle
run: ./gradlew assemblePrereleaseDebug
run: ./gradlew assemblePrereleaseDebug lint check

- name: Upload Artifact
uses: actions/upload-artifact@v7
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class CloudStreamApp : Application(), SingletonImageLoader.Factory {
}

fun <T : Any> setKeyClass(path: String, value: T) {
context?.setKey(path, value)
context?.setKey<Any>(path, value)
}

fun removeKeys(folder: String): Int? {
Expand All @@ -132,6 +132,11 @@ class CloudStreamApp : Application(), SingletonImageLoader.Factory {
context?.setKey(path, value)
}

@JvmName("setKeyReified")
inline fun <reified T : Any> setKey(path: String, value: T) {
context?.setKey(path, value)
}

fun <T> setKey(folder: String, path: String, value: T) {
context?.setKey(folder, path, value)
}
Expand Down
149 changes: 47 additions & 102 deletions app/src/main/java/com/lagradost/cloudstream3/ui/ControllerActivity.kt

Large diffs are not rendered by default.

165 changes: 62 additions & 103 deletions app/src/main/java/com/lagradost/cloudstream3/ui/player/Torrent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.ExtractorLinkType
import com.lagradost.cloudstream3.utils.newExtractorLink
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import torrServer.TorrServer
import java.io.File
import java.net.ConnectException
Expand All @@ -32,14 +34,14 @@ object Torrent {

/** Returns true if the server is up */
private suspend fun echo(): Boolean {
if(TORRENT_SERVER_URL.isEmpty()) {
if (TORRENT_SERVER_URL.isEmpty()) {
return false
}
return try {
app.get(
"$TORRENT_SERVER_URL/echo",
).text().isNotEmpty()
} catch (e: ConnectException) {
).text.isNotEmpty()
} catch (_: ConnectException) {
// `Failed to connect to /127.0.0.1:8090` if the server is down
false
} catch (t: Throwable) {
Expand All @@ -52,7 +54,7 @@ object Torrent {
/** Gracefully shutdown the server.
* should not be used because I am unable to start it again, and the stopTorrentServer() crashes the app */
suspend fun shutdown(): Boolean {
if(TORRENT_SERVER_URL.isEmpty()) {
if (TORRENT_SERVER_URL.isEmpty()) {
return false
}
return try {
Expand All @@ -68,7 +70,7 @@ object Torrent {
/** Lists all torrents by the server */
@Throws
private suspend fun list(): Array<TorrentStatus> {
if(TORRENT_SERVER_URL.isEmpty()) {
if (TORRENT_SERVER_URL.isEmpty()) {
throw ErrorLoadingException("Not initialized")
}
return app.post(
Expand All @@ -83,7 +85,7 @@ object Torrent {

/** Drops a single torrent, (I think) this means closing the stream. Returns returns if it is successful */
private suspend fun drop(hash: String): Boolean {
if(TORRENT_SERVER_URL.isEmpty()) {
if (TORRENT_SERVER_URL.isEmpty()) {
return false
}
return try {
Expand All @@ -104,7 +106,7 @@ object Torrent {

/** Removes a single torrent from the server registry */
private suspend fun rem(hash: String): Boolean {
if(TORRENT_SERVER_URL.isEmpty()) {
if (TORRENT_SERVER_URL.isEmpty()) {
return false
}
return try {
Expand All @@ -126,7 +128,7 @@ object Torrent {

/** Removes all torrents from the server, and returns if it is successful */
suspend fun clearAll(): Boolean {
if(TORRENT_SERVER_URL.isEmpty()) {
if (TORRENT_SERVER_URL.isEmpty()) {
return true
}
return try {
Expand Down Expand Up @@ -164,10 +166,8 @@ object Torrent {
/** 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 */
@Throws
suspend fun get(
hash: String,
): TorrentStatus {
if(TORRENT_SERVER_URL.isEmpty()) {
suspend fun get(hash: String): TorrentStatus {
if (TORRENT_SERVER_URL.isEmpty()) {
throw ErrorLoadingException("Not initialized")
}
return app.post(
Expand All @@ -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*/
@Throws
private suspend fun add(url: String): TorrentStatus {
if(TORRENT_SERVER_URL.isEmpty()) {
if (TORRENT_SERVER_URL.isEmpty()) {
throw ErrorLoadingException("Not initialized")
}
return app.post(
Expand All @@ -204,7 +204,7 @@ object Torrent {
return true
}
val port = TorrServer.startTorrentServer(dir, 0)
if(port < 0) {
if (port < 0) {
return false
}
TORRENT_SERVER_URL = "http://127.0.0.1:$port"
Expand Down Expand Up @@ -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/main/web/api/route.go#L7
@Serializable
data class TorrentRequest(
@JsonProperty("action")
val action: String,
@JsonProperty("hash")
val hash: String = "",
@JsonProperty("link")
val link: String = "",
@JsonProperty("title")
val title: String = "",
@JsonProperty("poster")
val poster: String = "",
@JsonProperty("data")
val data: String = "",
@JsonProperty("save_to_db")
val saveToDB: Boolean = false,
@JsonProperty("action") @SerialName("action") val action: String,
@JsonProperty("hash") @SerialName("hash") val hash: String = "",
@JsonProperty("link") @SerialName("link") val link: String = "",
@JsonProperty("title") @SerialName("title") val title: String = "",
@JsonProperty("poster") @SerialName("poster") val poster: String = "",
@JsonProperty("data") @SerialName("data") val data: String = "",
@JsonProperty("save_to_db") @SerialName("save_to_db") val saveToDB: Boolean = false,
)

// https://github.com/Diegopyl1209/torrentserver-aniyomi/blob/c18f58e51b6738f053261bc863177078aa9c1c98/torr/state/state.go#L33
// omitempty = nullable
@Serializable
data class TorrentStatus(
@JsonProperty("title")
var title: String,
@JsonProperty("poster")
var poster: String,
@JsonProperty("data")
var data: String?,
@JsonProperty("timestamp")
var timestamp: Long,
@JsonProperty("name")
var name: String?,
@JsonProperty("hash")
var hash: String?,
@JsonProperty("stat")
var stat: Int,
@JsonProperty("stat_string")
var statString: String,
@JsonProperty("loaded_size")
var loadedSize: Long?,
@JsonProperty("torrent_size")
var torrentSize: Long?,
@JsonProperty("preloaded_bytes")
var preloadedBytes: Long?,
@JsonProperty("preload_size")
var preloadSize: Long?,
@JsonProperty("download_speed")
var downloadSpeed: Double?,
@JsonProperty("upload_speed")
var uploadSpeed: Double?,
@JsonProperty("total_peers")
var totalPeers: Int?,
@JsonProperty("pending_peers")
var pendingPeers: Int?,
@JsonProperty("active_peers")
var activePeers: Int?,
@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>?,
@JsonProperty("title") @SerialName("title") var title: String,
@JsonProperty("poster") @SerialName("poster") var poster: String,
@JsonProperty("data") @SerialName("data") var data: String?,
@JsonProperty("timestamp") @SerialName("timestamp") var timestamp: Long,
@JsonProperty("name") @SerialName("name") var name: String?,
@JsonProperty("hash") @SerialName("hash") var hash: String?,
@JsonProperty("stat") @SerialName("stat") var stat: Int,
@JsonProperty("stat_string") @SerialName("stat_string") var statString: String,
@JsonProperty("loaded_size") @SerialName("loaded_size") var loadedSize: Long?,
@JsonProperty("torrent_size") @SerialName("torrent_size") var torrentSize: Long?,
@JsonProperty("preloaded_bytes") @SerialName("preloaded_bytes") var preloadedBytes: Long?,
@JsonProperty("preload_size") @SerialName("preload_size") var preloadSize: Long?,
@JsonProperty("download_speed") @SerialName("download_speed") var downloadSpeed: Double?,
@JsonProperty("upload_speed") @SerialName("upload_speed") var uploadSpeed: Double?,
@JsonProperty("total_peers") @SerialName("total_peers") var totalPeers: Int?,
@JsonProperty("pending_peers") @SerialName("pending_peers") var pendingPeers: Int?,
@JsonProperty("active_peers") @SerialName("active_peers") var activePeers: Int?,
@JsonProperty("connected_seeders") @SerialName("connected_seeders") var connectedSeeders: Int?,
@JsonProperty("half_open_peers") @SerialName("half_open_peers") var halfOpenPeers: Int?,
@JsonProperty("bytes_written") @SerialName("bytes_written") var bytesWritten: Long?,
@JsonProperty("bytes_written_data") @SerialName("bytes_written_data") var bytesWrittenData: Long?,
@JsonProperty("bytes_read") @SerialName("bytes_read") var bytesRead: Long?,
@JsonProperty("bytes_read_data") @SerialName("bytes_read_data") var bytesReadData: Long?,
@JsonProperty("bytes_read_useful_data") @SerialName("bytes_read_useful_data") var bytesReadUsefulData: Long?,
@JsonProperty("chunks_written") @SerialName("chunks_written") var chunksWritten: Long?,
@JsonProperty("chunks_read") @SerialName("chunks_read") var chunksRead: Long?,
@JsonProperty("chunks_read_useful") @SerialName("chunks_read_useful") var chunksReadUseful: Long?,
@JsonProperty("chunks_read_wasted") @SerialName("chunks_read_wasted") var chunksReadWasted: Long?,
@JsonProperty("pieces_dirtied_good") @SerialName("pieces_dirtied_good") var piecesDirtiedGood: Long?,
@JsonProperty("pieces_dirtied_bad") @SerialName("pieces_dirtied_bad") var piecesDirtiedBad: Long?,
@JsonProperty("duration_seconds") @SerialName("duration_seconds") var durationSeconds: Double?,
@JsonProperty("bit_rate") @SerialName("bit_rate") var bitRate: String?,
@JsonProperty("file_stats") @SerialName("file_stats") var fileStats: List<TorrentFileStat>?,
@JsonProperty("trackers") @SerialName("trackers") var trackers: List<String>?,
) {
fun streamUrl(url: String): String {
val fileName =
Expand All @@ -381,12 +342,10 @@ object Torrent {
}
}

@Serializable
data class TorrentFileStat(
@JsonProperty("id")
val id: Int?,
@JsonProperty("path")
val path: String?,
@JsonProperty("length")
val length: Long?,
@JsonProperty("id") @SerialName("id") val id: Int?,
@JsonProperty("path") @SerialName("path") val path: String?,
@JsonProperty("length") @SerialName("length") val length: Long?,
)
}
}
49 changes: 39 additions & 10 deletions app/src/main/java/com/lagradost/cloudstream3/utils/DataStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.preference.PreferenceManager
import com.lagradost.cloudstream3.CloudStreamApp.Companion.getKeyClass
import com.lagradost.cloudstream3.CloudStreamApp.Companion.removeKey
import com.lagradost.cloudstream3.CloudStreamApp.Companion.setKeyClass
import com.lagradost.cloudstream3.InternalAPI
import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.utils.AppUtils.parseJson
import com.lagradost.cloudstream3.utils.AppUtils.toJsonLiteral
Expand Down Expand Up @@ -170,44 +171,72 @@ object DataStore {
}
}

fun <T> Context.setKey(path: String, value: T) {
@InternalAPI
fun Context.putStringKey(path: String, value: String?) {
try {
getSharedPrefs().edit {
putString(path, value?.toJsonLiteral())
putString(path, value)
}
} catch (e: Exception) {
logError(e)
}
}

/** Non-reified fallback for binary compat. Prefer the reified overload where possible. */
fun <T> Context.setKey(path: String, value: T) {
putStringKey(path, value?.toJsonLiteral())
}

/** Reified overload, prevents type erasure for generic types. */
@JvmName("setKeyReified")
inline fun <reified T : Any> Context.setKey(path: String, value: T) {
putStringKey(path, value.toJsonLiteral())
}

fun <T : Any> Context.getKey(path: String, valueType: Class<T>): T? {
try {
return try {
val json: String = getSharedPrefs().getString(path, null) ?: return null
return parseJson(json, valueType.kotlin)
} catch (e: Exception) {
return null
parseJson(json, valueType.kotlin)
} catch (_: Exception) {
null
}
}

fun <T> Context.setKey(folder: String, path: String, value: T) {
setKey(getFolderName(folder, path), value)
}

@Deprecated(
message = "Use parseJson<T>(this) directly instead.",
level = DeprecationLevel.ERROR,
replaceWith = ReplaceWith(
expression = "parseJson<T>(this)",
imports = ["com.lagradost.cloudstream3.utils.AppUtils.parseJson"],
),
)
inline fun <reified T : Any> String.toKotlinObject(): T {
return parseJson(this)
}

@Deprecated(
message = "Use parseJson<T>(this) directly instead.",
level = DeprecationLevel.ERROR,
replaceWith = ReplaceWith(
expression = "parseJson<T>(this)",
imports = ["com.lagradost.cloudstream3.utils.AppUtils.parseJson"],
),
)
fun <T : Any> String.toKotlinObject(valueType: Class<T>): T {
return parseJson(this, valueType.kotlin)
}

// GET KEY GIVEN PATH AND DEFAULT VALUE, NULL IF ERROR
inline fun <reified T : Any> Context.getKey(path: String, defVal: T?): T? {
try {
return try {
val json: String = getSharedPrefs().getString(path, null) ?: return defVal
return json.toKotlinObject()
} catch (e: Exception) {
return null
parseJson<T>(json)
} catch (_: Exception) {
null
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ object DownloadQueueManager {
fun init(context: Context) {
ioSafe {
_queue.collect { queue ->
setKey(QUEUE_KEY, queue)
setKey<Array<DownloadQueueWrapper>>(QUEUE_KEY, queue)
}
}

Expand Down Expand Up @@ -247,4 +247,4 @@ object DownloadQueueManager {
localQueue.copyOf()
}
}
}
}
Loading