From a2b3eec02fa517b85e254c215e998cce254a5c48 Mon Sep 17 00:00:00 2001 From: LuftVerbot <97435834+LuftVerbot@users.noreply.github.com> Date: Wed, 18 Sep 2024 20:19:46 +0200 Subject: [PATCH] Update decryptor again There still some times was a chance that the song would skip if you paused the song long enough. This update should fix that --- .../brahmkshatriya/echo/extension/Utils.kt | 72 +++++++++---------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/ext/src/main/java/dev/brahmkshatriya/echo/extension/Utils.kt b/ext/src/main/java/dev/brahmkshatriya/echo/extension/Utils.kt index 52b48b5..4fec3e9 100644 --- a/ext/src/main/java/dev/brahmkshatriya/echo/extension/Utils.kt +++ b/ext/src/main/java/dev/brahmkshatriya/echo/extension/Utils.kt @@ -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}") }