diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/M3u8Helper.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/M3u8Helper.kt index 1fb3a72d..5c0b45de 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/M3u8Helper.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/M3u8Helper.kt @@ -88,21 +88,17 @@ object M3u8Helper2 { } } - private val defaultIvGen = sequence { - var initial = 1 + private fun defaultIv(index: Int) : ByteArray { + return toBytes16Big(index+1) + } - while (true) { - yield(toBytes16Big(initial)) - ++initial - } - }.iterator() - - fun getDecrypter( + fun getDecrypted( secretKey: ByteArray, data: ByteArray, - iv: ByteArray = "".toByteArray() + iv: ByteArray = byteArrayOf(), + index : Int, ): ByteArray { - val ivKey = if (iv.isEmpty()) defaultIvGen.next() else iv + val ivKey = if (iv.isEmpty()) defaultIv(index) else iv val c = Cipher.getInstance("AES/CBC/PKCS5Padding") val skSpec = SecretKeySpec(secretKey, "AES") val ivSpec = IvParameterSpec(ivKey) @@ -234,7 +230,7 @@ object M3u8Helper2 { if (tsData.isEmpty()) throw ErrorLoadingException("no data") return if (isEncrypted) { - getDecrypter(encryptionData, tsData, encryptionIv) + getDecrypted(encryptionData, tsData, encryptionIv, index) } else { tsData } @@ -272,13 +268,13 @@ object M3u8Helper2 { val match = ENCRYPTION_URL_IV_REGEX.find(m3u8Response)!!.groupValues - var encryptionUri = match[1] + var encryptionUri = match[2] if (isNotCompleteUrl(encryptionUri)) { encryptionUri = "${getParentLink(secondSelection.streamUrl)}/$encryptionUri" } - encryptionIv = match[2].toByteArray() + encryptionIv = match[3].toByteArray() val encryptionKeyResponse = app.get(encryptionUri, headers = headers, verify = false) encryptionData = encryptionKeyResponse.body.bytes() } diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/VideoDownloadManager.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/VideoDownloadManager.kt index ef0d9d8a..dc3eaa25 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/VideoDownloadManager.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/VideoDownloadManager.kt @@ -803,6 +803,8 @@ object VideoDownloadManager { bytesDownloaded = 0 hlsWrittenProgress = 0 hlsProgress = 0 + if (id != null) + downloadDeleteEvent(id) //internalType = DownloadType.IsStopped notify()