Skip to content

Commit

Permalink
Update decryptor again
Browse files Browse the repository at this point in the history
There still some times was a chance that the song would skip if you paused the song long enough. This update should fix that
  • Loading branch information
LuftVerbot committed Sep 18, 2024
1 parent 09e36df commit a2b3eec
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions ext/src/main/java/dev/brahmkshatriya/echo/extension/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -101,50 +101,50 @@ suspend fun getByteStreamAudio(

scope.launch(Dispatchers.IO) {
try {
response.body.byteStream().use { byteStream ->
try {
var totalBytesRead = 0L
var counter = 0

while (totalBytesRead < contentLength) {
val buffer = ByteArray(2048)
var bytesRead: Int
var totalRead = 0

while (totalRead < buffer.size) {
bytesRead =
byteStream.read(buffer, totalRead, buffer.size - totalRead)
if (bytesRead == -1) break
totalRead += bytesRead
}
response.body.byteStream().use { byteStream ->
try {
var totalBytesRead = 0L
var counter = 0

while (totalBytesRead < contentLength) {
val buffer = ByteArray(2048)
var bytesRead: Int
var totalRead = 0

while (totalRead < buffer.size) {
bytesRead =
byteStream.read(buffer, totalRead, buffer.size - totalRead)
if (bytesRead == -1) break
totalRead += bytesRead
}

if (totalRead == 0) break
if (totalRead == 0) break

try {
if (totalRead != 2048) {
byteChannel.writeFully(buffer, 0, totalRead)
try {
if (totalRead != 2048) {
byteChannel.writeFully(buffer, 0, totalRead)
} else {
if ((counter % 3) == 0) {
val decryptedChunk = Utils.decryptBlowfish(buffer, key)
byteChannel.writeFully(decryptedChunk, 0, totalRead)
} else {
if ((counter % 3) == 0) {
val decryptedChunk = Utils.decryptBlowfish(buffer, key)
byteChannel.writeFully(decryptedChunk, 0, totalRead)
} else {
byteChannel.writeFully(buffer, 0, totalRead)
}
byteChannel.writeFully(buffer, 0, totalRead)
}
} catch (e: IOException) {
println("Channel closed while writing, aborting.")
break
}
totalBytesRead += totalRead
counter++
} catch (e: IOException) {
println("Channel closed while writing, aborting.")
break
}
} catch (e: Exception) {
e.printStackTrace()
throw IOException("Error while reading/writing stream: ${e.message}", e)
} finally {
byteChannel.close()
totalBytesRead += totalRead
counter++
}
} catch (e: Exception) {
e.printStackTrace()
throw IOException("Error while reading/writing stream: ${e.message}", e)
} finally {
byteChannel.close()
}
}
} catch (e: IOException) {
println("Exception during decryption or streaming: ${e.message}")
}
Expand Down

0 comments on commit a2b3eec

Please sign in to comment.