Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ tasks.withType<KotlinJvmCompile> {
optIn.addAll(
"com.lagradost.cloudstream3.InternalAPI",
"com.lagradost.cloudstream3.Prerelease",
"kotlin.uuid.ExperimentalUuidApi",
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ import java.util.concurrent.Executors
import javax.net.ssl.HttpsURLConnection
import javax.net.ssl.SSLContext
import javax.net.ssl.SSLSession
import kotlin.uuid.Uuid

const val TAG = "CS3ExoPlayer"
const val PREFERRED_AUDIO_LANGUAGE_KEY = "preferred_audio_language"
Expand Down Expand Up @@ -247,6 +248,10 @@ class CS3IPlayer : IPlayer {
}
}

private fun Uuid.toJavaUUID(): UUID {
return UUID.fromString(this.toString())
}

fun String.stripTrackId(): String {
return this.replace(Regex("""^\d+:"""), "")
}
Expand Down Expand Up @@ -1278,7 +1283,7 @@ class CS3IPlayer : IPlayer {

item.drm?.let { drm ->
when (drm.uuid) {
CLEARKEY_UUID -> {
CLEARKEY_UUID.toJavaUUID() -> {
// Use headers from DrmMetadata for media requests
val client = dataSourceFactory
?: throw IllegalArgumentException("Must supply onlineSource")
Expand All @@ -1299,8 +1304,8 @@ class CS3IPlayer : IPlayer {
.createMediaSource(item.mediaItem)
}

WIDEVINE_UUID,
PLAYREADY_UUID -> {
WIDEVINE_UUID.toJavaUUID(),
PLAYREADY_UUID.toJavaUUID() -> {
// Use headers from DrmMetadata for media requests
val client = dataSourceFactory
?: throw IllegalArgumentException("Must supply onlineSource")
Expand Down Expand Up @@ -1914,7 +1919,7 @@ class CS3IPlayer : IPlayer {
drm = DrmMetadata(
kid = link.kid,
key = link.key,
uuid = link.uuid,
uuid = link.uuid.toJavaUUID(),
kty = link.kty,
licenseUrl = link.licenseUrl,
keyRequestParameters = link.keyRequestParameters,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
@file:OptIn(ExperimentalUuidApi::class)

package com.lagradost.cloudstream3.utils

import com.fasterxml.jackson.annotation.JsonIgnore
import com.lagradost.cloudstream3.AudioFile
import com.lagradost.cloudstream3.IDownloadableMinimum
import com.lagradost.cloudstream3.Prerelease
import com.lagradost.cloudstream3.SubtitleFile
import com.lagradost.cloudstream3.USER_AGENT
import com.lagradost.cloudstream3.app
Expand Down Expand Up @@ -316,6 +319,8 @@ import org.jsoup.Jsoup
import java.net.URI
import java.util.UUID
import kotlin.coroutines.cancellation.CancellationException
import kotlin.uuid.ExperimentalUuidApi
import kotlin.uuid.Uuid

/**
* For use in the ConcatenatingMediaSource.
Expand Down Expand Up @@ -431,29 +436,29 @@ private fun inferTypeFromUrl(url: String): ExtractorLinkType {
val INFER_TYPE: ExtractorLinkType? = null

/**
* UUID for the ClearKey DRM scheme.
* [Uuid] for the ClearKey DRM scheme.
*
*
* ClearKey is supported on Android devices running Android 5.0 (API Level 21) and up.
*/
val CLEARKEY_UUID = UUID(-0x1d8e62a7567a4c37L, 0x781AB030AF78D30EL)
val CLEARKEY_UUID = Uuid.fromLongs(-0x1d8e62a7567a4c37L, 0x781AB030AF78D30EL)

/**
* UUID for the Widevine DRM scheme.
* [Uuid] for the Widevine DRM scheme.
*
*
* Widevine is supported on Android devices running Android 4.3 (API Level 18) and up.
*/
val WIDEVINE_UUID = UUID(-0x121074568629b532L, -0x5c37d8232ae2de13L)
val WIDEVINE_UUID = Uuid.fromLongs(-0x121074568629b532L, -0x5c37d8232ae2de13L)

/**
* UUID for the PlayReady DRM scheme.
* [Uuid] for the PlayReady DRM scheme.
*
*
* PlayReady is supported on all AndroidTV devices. Note that most other Android devices do not
* provide PlayReady support.
*/
val PLAYREADY_UUID = UUID(-0x65fb0f8667bfbd7aL, -0x546d19a41f77a06bL)
val PLAYREADY_UUID = Uuid.fromLongs(-0x65fb0f8667bfbd7aL, -0x546d19a41f77a06bL)

suspend fun newExtractorLink(
source: String,
Expand All @@ -476,6 +481,11 @@ suspend fun newExtractorLink(
return builder
}

// Deprecate after next stable
/* @Deprecated(
message = "Use Kotlin Uuid (kotlin.uuid.Uuid) instead of Java UUID.",
level = DeprecationLevel.WARNING,
) */
suspend fun newDrmExtractorLink(
source: String,
name: String,
Expand All @@ -484,7 +494,33 @@ suspend fun newDrmExtractorLink(
uuid: UUID,
initializer: suspend DrmExtractorLink.() -> Unit = { }
): DrmExtractorLink {
fun UUID.toKotlinUuid(): Uuid {
return Uuid.fromLongs(mostSignificantBits, leastSignificantBits)
}

@Suppress("DEPRECATION_ERROR")
val builder =
DrmExtractorLink(
source = source,
name = name,
url = url,
uuid = uuid.toKotlinUuid(),
type = type ?: INFER_TYPE
)

builder.initializer()
return builder
}

@Prerelease
suspend fun newDrmExtractorLink(
source: String,
name: String,
url: String,
type: ExtractorLinkType? = null,
uuid: Uuid,
initializer: suspend DrmExtractorLink.() -> Unit = { }
): DrmExtractorLink {
@Suppress("DEPRECATION_ERROR")
val builder =
DrmExtractorLink(
Expand All @@ -510,7 +546,7 @@ suspend fun newDrmExtractorLink(
* @property type the type of the media, use [INFER_TYPE] if you want to auto infer the type from the url
* @property kid Base64 value of The KID element (Key Id) contains the identifier of the key associated with a license.
* @property key Base64 value of Key to be used to decrypt the media file.
* @property uuid Drm UUID [WIDEVINE_UUID], [PLAYREADY_UUID], [CLEARKEY_UUID] (by default) .. etc
* @property uuid Drm [Uuid] [WIDEVINE_UUID], [PLAYREADY_UUID], [CLEARKEY_UUID] (by default) .. etc
* @property kty Key type "oct" (octet sequence) by default
* @property keyRequestParameters Parameters that will used to request the key.
* @see newDrmExtractorLink
Expand All @@ -528,7 +564,7 @@ open class DrmExtractorLink private constructor(
override var type: ExtractorLinkType,
open var kid: String? = null,
open var key: String? = null,
open var uuid: UUID,
open var uuid: Uuid,
open var kty: String? = null,
open var keyRequestParameters: HashMap<String, String>,
open var licenseUrl: String? = null,
Expand All @@ -550,7 +586,7 @@ open class DrmExtractorLink private constructor(
extractorData: String? = null,
kid: String? = null,
key: String? = null,
uuid: UUID = CLEARKEY_UUID,
uuid: Uuid = CLEARKEY_UUID,
kty: String? = "oct",
keyRequestParameters: HashMap<String, String> = hashMapOf(),
licenseUrl: String? = null,
Expand Down Expand Up @@ -585,7 +621,7 @@ open class DrmExtractorLink private constructor(
extractorData: String? = null,
kid: String? = null,
key: String? = null,
uuid: UUID = CLEARKEY_UUID,
uuid: Uuid = CLEARKEY_UUID,
kty: String? = "oct",
keyRequestParameters: HashMap<String, String> = hashMapOf(),
licenseUrl: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ object HlsPlaylistParser {
if (KEYFORMAT_WIDEVINE_PSSH_BINARY == keyFormat) {
val uriString = parseStringAttr(line, REGEX_URI, variableDefinitions)
return SchemeData(
uuid = WIDEVINE_UUID,
uuid = C.WIDEVINE_UUID,
Comment thread
Luna712 marked this conversation as resolved.
mimeType = MimeTypes.VIDEO_MP4,
data = Base64.Default.decode(uriString.substring(uriString.indexOf(',')))
)
Expand Down Expand Up @@ -2078,4 +2078,4 @@ object HlsPlaylistParser {
sessionKeyDrmInitData = sessionKeyDrmInitData
)
}
}
}