From c1def3d6e2c7643a6e620fa96a979e0954fb8df0 Mon Sep 17 00:00:00 2001 From: BingZi-233 Date: Tue, 26 Dec 2023 09:01:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3show=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E4=B8=8B=E6=94=B6=E8=97=8F=E6=A3=80=E6=B5=8B=E6=97=A0=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle.properties | 2 +- .../video/internal/engine/NetworkEngine.kt | 103 ++++++------------ .../internal/engine/drive/BilibiliApiDrive.kt | 20 +++- 3 files changed, 51 insertions(+), 74 deletions(-) diff --git a/gradle.properties b/gradle.properties index 610b689..738916e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ group=online.bingiz.bilibili.video -version=1.3.12 \ No newline at end of file +version=1.3.14 \ No newline at end of file diff --git a/src/main/kotlin/online/bingiz/bilibili/video/internal/engine/NetworkEngine.kt b/src/main/kotlin/online/bingiz/bilibili/video/internal/engine/NetworkEngine.kt index 787eadb..29cd424 100644 --- a/src/main/kotlin/online/bingiz/bilibili/video/internal/engine/NetworkEngine.kt +++ b/src/main/kotlin/online/bingiz/bilibili/video/internal/engine/NetworkEngine.kt @@ -32,22 +32,16 @@ import taboolib.module.nms.NMSMap * @constructor Create empty Network engine */ object NetworkEngine { - private val client = OkHttpClient.Builder() - .addInterceptor(ReceivedCookiesInterceptor()) - .addInterceptor(UserAgentInterceptor("MinecraftPlugin $pluginId/$pluginVersion(lhby233@outlook.com)")) - .build() + private val client = OkHttpClient.Builder().addInterceptor(ReceivedCookiesInterceptor()) + .addInterceptor(UserAgentInterceptor("MinecraftPlugin $pluginId/$pluginVersion(lhby233@outlook.com)")).build() /** * Bilibili API * 哔哩哔哩API驱动 */ private val bilibiliAPI by lazy { - Retrofit.Builder() - .baseUrl("https://api.bilibili.com/x/") - .addConverterFactory(GsonConverterFactory.create()) - .client(client) - .build() - .create(BilibiliApiDrive::class.java) + Retrofit.Builder().baseUrl("https://api.bilibili.com/x/").addConverterFactory(GsonConverterFactory.create()) + .client(client).build().create(BilibiliApiDrive::class.java) } /** @@ -55,11 +49,8 @@ object NetworkEngine { * 哔哩哔哩通行证驱动API */ private val bilibiliPassportAPI by lazy { - Retrofit.Builder() - .baseUrl("https://passport.bilibili.com/x/") - .addConverterFactory(GsonConverterFactory.create()) - .client(client) - .build() + Retrofit.Builder().baseUrl("https://passport.bilibili.com/x/") + .addConverterFactory(GsonConverterFactory.create()).client(client).build() .create(BilibiliPassportDrive::class.java) } @@ -68,12 +59,8 @@ object NetworkEngine { * 哔哩哔哩网站驱动API */ private val bilibiliWebsiteAPI by lazy { - Retrofit.Builder() - .baseUrl("https://www.bilibili.com/") - .addConverterFactory(GsonConverterFactory.create()) - .client(client) - .build() - .create(BilibiliPassportDrive::class.java) + Retrofit.Builder().baseUrl("https://www.bilibili.com/").addConverterFactory(GsonConverterFactory.create()) + .client(client).build().create(BilibiliPassportDrive::class.java) } /** @@ -84,8 +71,7 @@ object NetworkEngine { fun generateBilibiliQRCodeUrl(player: ProxyPlayer) { bilibiliPassportAPI.applyQRCodeGenerate().enqueue(object : Callback> { override fun onResponse( - call: Call>, - response: Response> + call: Call>, response: Response> ) { if (response.isSuccessful) { val body = response.body() @@ -118,16 +104,13 @@ object NetworkEngine { // 这里不知道为什么会传递一些容易产生干扰的信息进来 val cookieList = list.map { it.split(";")[0] } // 将Cookie转化为JSON - val replace = - cookieList.joinToString( - ",", - prefix = "{", - postfix = "}" - ) { - "\"${ - it.replace("=", "\":\"").replace("""\u003d""", "\":\"") - }\"" - } + val replace = cookieList.joinToString( + ",", prefix = "{", postfix = "}" + ) { + "\"${ + it.replace("=", "\":\"").replace("""\u003d""", "\":\"") + }\"" + } // GSON反序列化成CookieData val cookieData = gson.fromJson(replace, CookieData::class.java) // 检查MID重复 @@ -148,12 +131,10 @@ object NetworkEngine { midCache.put(player.uniqueId, mid) player.setDataContainer("mid", mid) player.setDataContainer( - "refresh_token", - result.data.refreshToken + "refresh_token", result.data.refreshToken ) player.setDataContainer( - "timestamp", - result.data.timestamp.toString() + "timestamp", result.data.timestamp.toString() ) player.infoAsLang("GenerateUseCookieSuccess") } @@ -175,15 +156,13 @@ object NetworkEngine { Bukkit.getPlayer(player.uniqueId)?.updateInventory() } else { warningMessageAsLang( - "NetworkRequestFailureCode", - response.code() + "NetworkRequestFailureCode", response.code() ) } } } else { player.infoAsLang( - "GenerateUseCookieFailure", - response.body()?.message ?: "Bilibili未提供任何错误信息" + "GenerateUseCookieFailure", response.body()?.message ?: "Bilibili未提供任何错误信息" ) } } else { @@ -215,20 +194,13 @@ object NetworkEngine { player.warningAsLang("CookieNotFound") return } - val sessData = - cookieCache[player.uniqueId]?.let { list -> - list.SESSDATA.let { - "SESSDATA=" + it.substring(0, it.length) + ",buvid3;" - } - } ?: let { - player.warningAsLang("CookieNotFound") - return - } - bilibiliAPI.actionLikeTriple(bvid, csrf, sessData) - .enqueue(object : Callback> { + val sessData = cookieCache[player.uniqueId]?.let { list -> list.SESSDATA.let { "SESSDATA=$it" } } ?: let { + player.warningAsLang("CookieNotFound") + return + } + bilibiliAPI.actionLikeTriple(bvid, csrf, sessData).enqueue(object : Callback> { override fun onResponse( - call: Call>, - response: Response> + call: Call>, response: Response> ) { if (response.isSuccessful) { response.body()?.let { @@ -260,14 +232,12 @@ object NetworkEngine { else -> { player.infoAsLang( - "GetTripleStatusError", - response.body()?.message ?: "Bilibili未提供任何错误信息" + "GetTripleStatusError", response.body()?.message ?: "Bilibili未提供任何错误信息" ) } } } ?: player.infoAsLang( - "GetTripleStatusRefuse", - response.body()?.message ?: "Bilibili未提供任何错误信息" + "GetTripleStatusRefuse", response.body()?.message ?: "Bilibili未提供任何错误信息" ) } else { warning("请求失败") @@ -295,15 +265,14 @@ object NetworkEngine { return } } - val sessData = - cookieCache[player.uniqueId]?.let { list -> - list.SESSDATA.let { - "SESSDATA=" + it.substring(0, it.length) + ",buvid3;" - } - } ?: let { - player.warningAsLang("CookieNotFound") - return + val sessData = cookieCache[player.uniqueId]?.let { list -> + list.SESSDATA.let { + "SESSDATA=$it" } + } ?: let { + player.warningAsLang("CookieNotFound") + return + } bilibiliAPI.hasLike(sessData, bvid).execute().let { if (it.isSuccessful) { it.body()?.data?.let { count -> @@ -331,7 +300,7 @@ object NetworkEngine { bilibiliAPI.hasFavoured(sessData, bvid).execute().let { if (it.isSuccessful) { it.body()?.data?.let { - if (it.favoured.not()) { + if (it.favoured) { player.infoAsLang("GetTripleStatusFailureNotFavoured") return } diff --git a/src/main/kotlin/online/bingiz/bilibili/video/internal/engine/drive/BilibiliApiDrive.kt b/src/main/kotlin/online/bingiz/bilibili/video/internal/engine/drive/BilibiliApiDrive.kt index afb7b95..6189757 100644 --- a/src/main/kotlin/online/bingiz/bilibili/video/internal/engine/drive/BilibiliApiDrive.kt +++ b/src/main/kotlin/online/bingiz/bilibili/video/internal/engine/drive/BilibiliApiDrive.kt @@ -13,7 +13,10 @@ import retrofit2.http.* interface BilibiliApiDrive { @GET("web-interface/nav") - fun getUserInfo(@Header("Cookie") sessData: String): Call> + fun getUserInfo( + @Header("Cookie") sessData: String, + @Header("Cookie") buvid3: String = "buvid3=BUVID3" + ): Call> /** * Action like triple @@ -29,7 +32,8 @@ interface BilibiliApiDrive { fun actionLikeTriple( @Field("bvid") bvid: String, @Field("csrf") csrf: String, - @Header("Cookie") sessData: String + @Header("Cookie") sessData: String, + @Header("Cookie") buvid3: String = "buvid3=BUVID3" ): Call> /** @@ -41,8 +45,9 @@ interface BilibiliApiDrive { */ @GET("web-interface/archive/has/like") fun hasLike( + @Query("bvid") bvid: String, @Header("Cookie") sessData: String, - @Query("bvid") bvid: String + @Header("Cookie") buvid3: String = "buvid3=BUVID3" ): Call> /** @@ -54,8 +59,9 @@ interface BilibiliApiDrive { */ @GET("web-interface/archive/coins") fun hasCoins( + @Query("bvid") bvid: String, @Header("Cookie") sessData: String, - @Query("bvid") bvid: String + @Header("Cookie") buvid3: String = "buvid3=BUVID3" ): Call> /** @@ -67,8 +73,9 @@ interface BilibiliApiDrive { */ @GET("v2/fav/video/favoured") fun hasFavoured( + @Query("bvid") bvid: String, @Header("Cookie") sessData: String, - @Query("bvid") bvid: String + @Header("Cookie") buvid3: String = "buvid3=BUVID3" ): Call> /** @@ -81,7 +88,8 @@ interface BilibiliApiDrive { */ @GET("web-interface/view/detail") fun hasFollowing( + @Query("bvid") bvid: String, @Header("Cookie") sessData: String, - @Query("bvid") bvid: String + @Header("Cookie") buvid3: String = "buvid3=BUVID3" ): Call> } \ No newline at end of file