Skip to content

Commit

Permalink
fix: 修正show模式下收藏检测无效
Browse files Browse the repository at this point in the history
  • Loading branch information
BingZi-233 committed Dec 26, 2023
1 parent 8d178fc commit c1def3d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 74 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
group=online.bingiz.bilibili.video
version=1.3.12
version=1.3.14
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,25 @@ import taboolib.module.nms.NMSMap
* @constructor Create empty Network engine
*/
object NetworkEngine {
private val client = OkHttpClient.Builder()
.addInterceptor(ReceivedCookiesInterceptor())
.addInterceptor(UserAgentInterceptor("MinecraftPlugin $pluginId/$pluginVersion([email protected])"))
.build()
private val client = OkHttpClient.Builder().addInterceptor(ReceivedCookiesInterceptor())
.addInterceptor(UserAgentInterceptor("MinecraftPlugin $pluginId/$pluginVersion([email protected])")).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)
}

/**
* Bilibili passport API
* 哔哩哔哩通行证驱动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)
}

Expand All @@ -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)
}

/**
Expand All @@ -84,8 +71,7 @@ object NetworkEngine {
fun generateBilibiliQRCodeUrl(player: ProxyPlayer) {
bilibiliPassportAPI.applyQRCodeGenerate().enqueue(object : Callback<BilibiliResult<QRCodeGenerateData>> {
override fun onResponse(
call: Call<BilibiliResult<QRCodeGenerateData>>,
response: Response<BilibiliResult<QRCodeGenerateData>>
call: Call<BilibiliResult<QRCodeGenerateData>>, response: Response<BilibiliResult<QRCodeGenerateData>>
) {
if (response.isSuccessful) {
val body = response.body()
Expand Down Expand Up @@ -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重复
Expand All @@ -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")
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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<BilibiliResult<TripleData>> {
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<BilibiliResult<TripleData>> {
override fun onResponse(
call: Call<BilibiliResult<TripleData>>,
response: Response<BilibiliResult<TripleData>>
call: Call<BilibiliResult<TripleData>>, response: Response<BilibiliResult<TripleData>>
) {
if (response.isSuccessful) {
response.body()?.let {
Expand Down Expand Up @@ -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("请求失败")
Expand Down Expand Up @@ -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 ->
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import retrofit2.http.*
interface BilibiliApiDrive {

@GET("web-interface/nav")
fun getUserInfo(@Header("Cookie") sessData: String): Call<BilibiliResult<UserInfoData>>
fun getUserInfo(
@Header("Cookie") sessData: String,
@Header("Cookie") buvid3: String = "buvid3=BUVID3"
): Call<BilibiliResult<UserInfoData>>

/**
* Action like triple
Expand All @@ -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<BilibiliResult<TripleData>>

/**
Expand All @@ -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<BilibiliResult<Int>>

/**
Expand All @@ -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<BilibiliResult<CoinsData>>

/**
Expand All @@ -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<BilibiliResult<FavouredData>>

/**
Expand All @@ -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<BilibiliResult<FollowingData>>
}

0 comments on commit c1def3d

Please sign in to comment.