From 149e2c4d60e7997658a97ef2969a5b0fa7b002a6 Mon Sep 17 00:00:00 2001 From: SuperSkidder Date: Mon, 15 Jul 2024 18:50:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=BD=91=E6=98=93?= =?UTF-8?q?=E4=BA=91=E7=99=BB=E5=BD=95=E3=80=81=E6=97=A5=E6=8E=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/music/netease/NeteaseApi.kt | 9 ++++-- .../fpsmaster/ui/click/music/MusicPanel.kt | 32 ++++++++++++++----- .../java/top/fpsmaster/utils/os/FileUtils.kt | 2 +- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/shared/java/top/fpsmaster/modules/music/netease/NeteaseApi.kt b/shared/java/top/fpsmaster/modules/music/netease/NeteaseApi.kt index 44a90fa..527a1a8 100644 --- a/shared/java/top/fpsmaster/modules/music/netease/NeteaseApi.kt +++ b/shared/java/top/fpsmaster/modules/music/netease/NeteaseApi.kt @@ -4,8 +4,10 @@ import top.fpsmaster.utils.os.HttpRequest.getWithCookie object NeteaseApi { private const val BASE_URL = "https://music.skidder.top/" + @JvmField var cookies = "" + @JvmStatic fun getVerbatimLyrics(id: String): String { val url = BASE_URL + "lyric/new?id=" + id @@ -44,9 +46,10 @@ object NeteaseApi { @JvmStatic val dailyList: String get() { - val url = BASE_URL + "recommend/songs" + val url = BASE_URL + "recommend/songs" + "?timestamp=" + System.currentTimeMillis() return getWithCookie(url, cookies) } + @JvmStatic val uniKey: String get() { @@ -62,14 +65,14 @@ object NeteaseApi { @JvmStatic fun checkLoginStatus(key: String): String { - val url = BASE_URL + "login/qr/check?key=" + key + "×tamp=" + System.currentTimeMillis() + val url = BASE_URL + "login/qr/check?key=" + key + "&noCookie=true" + "×tamp=" + System.currentTimeMillis() return getWithCookie(url, "") } @JvmStatic val anonmous: String get() { - val url = BASE_URL + "/register/anonimous" + "×tamp=" + System.currentTimeMillis() + val url = BASE_URL + "register/anonimous" + "×tamp=" + System.currentTimeMillis() return getWithCookie(url, "") } } diff --git a/shared/java/top/fpsmaster/ui/click/music/MusicPanel.kt b/shared/java/top/fpsmaster/ui/click/music/MusicPanel.kt index 8bfc0de..37d14a9 100644 --- a/shared/java/top/fpsmaster/ui/click/music/MusicPanel.kt +++ b/shared/java/top/fpsmaster/ui/click/music/MusicPanel.kt @@ -34,7 +34,7 @@ object MusicPanel { searchThread = Thread { run() } searchThread!!.start() } - private var pages = arrayOf("music.name", "music.list") + private var pages = arrayOf("music.name", "music.list", "music.daily") private var curSearch = 0 private var isWaitingLogin = false private var key: String? = null @@ -183,8 +183,12 @@ object MusicPanel { mouseY ) && Mouse.isButtonDown(0) ) isWaitingLogin = false - val resourceLocation = ResourceLocation("music/qr") - Render2DUtils.drawImage(resourceLocation, x + width / 2 - 45, y + height / 2 - 45, 90f, 90f, -1) + try { + val resourceLocation = ResourceLocation("music/qr") + Render2DUtils.drawImage(resourceLocation, x + width / 2 - 45, y + height / 2 - 45, 90f, 90f, -1) + }catch (e: Exception){ + + } var scan = "" when (code) { 801 -> scan = "music.waitscan" @@ -528,14 +532,22 @@ object MusicPanel { FPSMaster.theme.textColorTitle ) } - + private fun extractMiddleContent(input: String, prefix: String, suffix: String): String { + val startIndex = input.indexOf(prefix) + if (startIndex != -1) { + val endIndex = input.indexOf(suffix, startIndex + prefix.length) + if (endIndex != -1) { + return input.substring(startIndex + prefix.length, endIndex) + } + } + return "" + } private fun reloadImg() { loginThread = Thread { while (isWaitingLogin) { try { val loginStatus = MusicWrapper.getLoginStatus(key) code = loginStatus["code"].asInt - println(code) if (code == 802) { val element = loginStatus["nickname"] if (element != null) { @@ -544,7 +556,11 @@ object MusicPanel { } } if (code == 803) { - NeteaseApi.cookies = loginStatus["cookie"].asString + // parse cookie + var asString = loginStatus["cookie"].asString + val result = "MUSIC_U=" + extractMiddleContent(asString, "MUSIC_U=", ";")+ "; " + "NMTID=" + extractMiddleContent(asString, "NMTID=", ";") + NeteaseApi.cookies = result + saveTempValue("cookies", NeteaseApi.cookies) println("cookies: " + NeteaseApi.cookies) } @@ -564,8 +580,8 @@ object MusicPanel { val bytes = Base64.getDecoder().decode(base64) // create resource location val resourceLocation = ResourceLocation("music/qr") - val qr = File(FileUtils.cache, "/music/qr.png") - val qrf = File(FileUtils.cache, "/music") + val qr = File(FileUtils.dir, "/music/qr.png") + val qrf = File(FileUtils.dir, "/music") qrf.mkdirs() saveFileBytes("/music/qr.png", bytes) val textureArt = ThreadDownloadImageData(qr, null, null, null) diff --git a/shared/java/top/fpsmaster/utils/os/FileUtils.kt b/shared/java/top/fpsmaster/utils/os/FileUtils.kt index 933d6c3..911e247 100644 --- a/shared/java/top/fpsmaster/utils/os/FileUtils.kt +++ b/shared/java/top/fpsmaster/utils/os/FileUtils.kt @@ -43,7 +43,7 @@ object FileUtils { @JvmStatic fun saveFileBytes(s: String, bytes: ByteArray) { - val file = file(dir, s) + val file = File(dir, s) try { if (!file.exists()) { file.createNewFile()