mirror of
https://github.com/czp3009/bilibili-api.git
synced 2026-08-13 22:43:29 +08:00
bump version
This commit is contained in:
23
build.gradle
23
build.gradle
@@ -1,8 +1,8 @@
|
|||||||
buildscript {
|
buildscript {
|
||||||
ext {
|
ext {
|
||||||
kotlin_version = '1.3.21'
|
kotlin_version = '1.3.71'
|
||||||
kotlin_coroutines_version = '1.1.1'
|
kotlin_coroutines_version = '1.3.5'
|
||||||
ktor_version = '1.1.3'
|
ktor_version = '1.3.1'
|
||||||
jvm_target = JavaVersion.VERSION_1_8
|
jvm_target = JavaVersion.VERSION_1_8
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,6 +25,7 @@ apply plugin: 'signing'
|
|||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
jcenter()
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,29 +49,29 @@ compileTestKotlin {
|
|||||||
//logging
|
//logging
|
||||||
dependencies {
|
dependencies {
|
||||||
// https://mvnrepository.com/artifact/io.github.microutils/kotlin-logging
|
// https://mvnrepository.com/artifact/io.github.microutils/kotlin-logging
|
||||||
compile group: 'io.github.microutils', name: 'kotlin-logging', version: '1.6.25'
|
compile group: 'io.github.microutils', name: 'kotlin-logging', version: '1.7.9'
|
||||||
// https://mvnrepository.com/artifact/org.slf4j/slf4j-simple
|
// https://mvnrepository.com/artifact/org.slf4j/slf4j-simple
|
||||||
testCompile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.26'
|
testCompile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.30'
|
||||||
}
|
}
|
||||||
|
|
||||||
//http
|
//http
|
||||||
dependencies {
|
dependencies {
|
||||||
// https://mvnrepository.com/artifact/com.squareup.retrofit2/retrofit
|
// https://mvnrepository.com/artifact/com.squareup.retrofit2/retrofit
|
||||||
compile group: 'com.squareup.retrofit2', name: 'retrofit', version: '2.5.0'
|
compile group: 'com.squareup.retrofit2', name: 'retrofit', version: '2.8.1'
|
||||||
// https://mvnrepository.com/artifact/com.squareup.retrofit2/converter-gson
|
// https://mvnrepository.com/artifact/com.squareup.retrofit2/converter-gson
|
||||||
compile group: 'com.squareup.retrofit2', name: 'converter-gson', version: '2.5.0'
|
compile group: 'com.squareup.retrofit2', name: 'converter-gson', version: '2.8.1'
|
||||||
// https://mvnrepository.com/artifact/com.github.salomonbrys.kotson/kotson
|
// https://mvnrepository.com/artifact/com.github.salomonbrys.kotson/kotson
|
||||||
compile group: 'com.github.salomonbrys.kotson', name: 'kotson', version: '2.5.0'
|
compile group: 'com.github.salomonbrys.kotson', name: 'kotson', version: '2.5.0'
|
||||||
// https://mvnrepository.com/artifact/com.jakewharton.retrofit/retrofit2-kotlin-coroutines-adapter
|
// https://mvnrepository.com/artifact/com.jakewharton.retrofit/retrofit2-kotlin-coroutines-adapter
|
||||||
compile group: 'com.jakewharton.retrofit', name: 'retrofit2-kotlin-coroutines-adapter', version: '0.9.2'
|
compile group: 'com.jakewharton.retrofit', name: 'retrofit2-kotlin-coroutines-adapter', version: '0.9.2'
|
||||||
// https://mvnrepository.com/artifact/com.squareup.okhttp3/logging-interceptor
|
// https://mvnrepository.com/artifact/com.squareup.okhttp3/logging-interceptor
|
||||||
compile group: 'com.squareup.okhttp3', name: 'logging-interceptor', version: '3.14.0'
|
compile group: 'com.squareup.okhttp3', name: 'logging-interceptor', version: '4.5.0'
|
||||||
}
|
}
|
||||||
|
|
||||||
//ktor
|
//ktor
|
||||||
dependencies {
|
dependencies {
|
||||||
// https://mvnrepository.com/artifact/io.ktor/ktor-client-websocket
|
// https://mvnrepository.com/artifact/io.ktor/ktor-client-websockets
|
||||||
compile group: 'io.ktor', name: 'ktor-client-websocket', version: ktor_version
|
compile group: 'io.ktor', name: 'ktor-client-websockets', version: ktor_version
|
||||||
// https://mvnrepository.com/artifact/io.ktor/ktor-client-cio
|
// https://mvnrepository.com/artifact/io.ktor/ktor-client-cio
|
||||||
compile group: 'io.ktor', name: 'ktor-client-cio', version: ktor_version
|
compile group: 'io.ktor', name: 'ktor-client-cio', version: ktor_version
|
||||||
}
|
}
|
||||||
@@ -84,7 +85,7 @@ dependencies {
|
|||||||
//unit test
|
//unit test
|
||||||
dependencies {
|
dependencies {
|
||||||
// https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter
|
// https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter
|
||||||
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter', version: '5.4.1'
|
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter', version: '5.6.1'
|
||||||
}
|
}
|
||||||
|
|
||||||
task sourcesJar(type: Jar) {
|
task sourcesJar(type: Jar) {
|
||||||
|
|||||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
|
|||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.3-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package com.hiczp.bilibili.api
|
|||||||
|
|
||||||
import com.hiczp.bilibili.api.thirdpart.commons.BoundedInputStream
|
import com.hiczp.bilibili.api.thirdpart.commons.BoundedInputStream
|
||||||
import io.ktor.util.InternalAPI
|
import io.ktor.util.InternalAPI
|
||||||
import kotlinx.io.errors.EOFException
|
import io.ktor.utils.io.errors.EOFException
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
|
|
||||||
//减少包引入
|
//减少包引入
|
||||||
|
|||||||
@@ -25,17 +25,17 @@ class PlayerInterceptor(
|
|||||||
val request = chain.request()
|
val request = chain.request()
|
||||||
|
|
||||||
//添加 header
|
//添加 header
|
||||||
val header = request.headers().newBuilder().apply {
|
val header = request.headers.newBuilder().apply {
|
||||||
add(Header.ACCEPT, "*/*")
|
add(Header.ACCEPT, "*/*")
|
||||||
add(Header.USER_AGENT, "Bilibili Freedoooooom/MarkII")
|
add(Header.USER_AGENT, "Bilibili Freedoooooom/MarkII")
|
||||||
add(Header.ACCEPT_LANGUAGE, "zh-CN,zh;q=0.8")
|
add(Header.ACCEPT_LANGUAGE, "zh-CN,zh;q=0.8")
|
||||||
}.build()
|
}.build()
|
||||||
|
|
||||||
//添加 Query Params
|
//添加 Query Params
|
||||||
val oldUrl = request.url()
|
val oldUrl = request.url
|
||||||
//如果是视频播放地址这个 API, 要用特殊的 appKey
|
//如果是视频播放地址这个 API, 要用特殊的 appKey
|
||||||
val isVideo = oldUrl.toString().startsWith(PlayerAPI.videoPlayUrl)
|
val isVideo = oldUrl.toString().startsWith(PlayerAPI.videoPlayUrl)
|
||||||
val url = StringBuilder(oldUrl.encodedQuery() ?: "").apply {
|
val url = StringBuilder(oldUrl.encodedQuery ?: "").apply {
|
||||||
//appKey
|
//appKey
|
||||||
addParamEncode(Param.APP_KEY, if (isVideo) bilibiliClientProperties.videoAppKey else bilibiliClientProperties.appKey)
|
addParamEncode(Param.APP_KEY, if (isVideo) bilibiliClientProperties.videoAppKey else bilibiliClientProperties.appKey)
|
||||||
//凭证有关
|
//凭证有关
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ package com.hiczp.bilibili.api.retrofit
|
|||||||
import okhttp3.FormBody
|
import okhttp3.FormBody
|
||||||
|
|
||||||
inline fun FormBody.forEach(block: (String, String) -> Unit) {
|
inline fun FormBody.forEach(block: (String, String) -> Unit) {
|
||||||
repeat(size()) {
|
repeat(size) {
|
||||||
block(encodedName(it), encodedValue(it))
|
block(encodedName(it), encodedValue(it))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun FormBody.raw() =
|
fun FormBody.raw() =
|
||||||
StringBuilder().apply {
|
StringBuilder().apply {
|
||||||
repeat(size()) {
|
repeat(size) {
|
||||||
if (it != 0) append('&')
|
if (it != 0) append('&')
|
||||||
append(encodedName(it))
|
append(encodedName(it))
|
||||||
append('=')
|
append('=')
|
||||||
@@ -20,14 +20,14 @@ fun FormBody.raw() =
|
|||||||
|
|
||||||
fun FormBody.sortedRaw(): String {
|
fun FormBody.sortedRaw(): String {
|
||||||
val nameAndValue = ArrayList<String>()
|
val nameAndValue = ArrayList<String>()
|
||||||
repeat(size()) {
|
repeat(size) {
|
||||||
nameAndValue.add("${encodedName(it)}=${encodedValue(it)}")
|
nameAndValue.add("${encodedName(it)}=${encodedValue(it)}")
|
||||||
}
|
}
|
||||||
return nameAndValue.sorted().joinToString(separator = "&")
|
return nameAndValue.sorted().joinToString(separator = "&")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun FormBody.containsEncodedName(name: String): Boolean {
|
fun FormBody.containsEncodedName(name: String): Boolean {
|
||||||
repeat(size()) {
|
repeat(size) {
|
||||||
if (encodedName(it) == name) return true
|
if (encodedName(it) == name) return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
@@ -35,7 +35,7 @@ fun FormBody.containsEncodedName(name: String): Boolean {
|
|||||||
|
|
||||||
fun FormBody.Builder.addAllEncoded(formBody: FormBody): FormBody.Builder {
|
fun FormBody.Builder.addAllEncoded(formBody: FormBody): FormBody.Builder {
|
||||||
with(formBody) {
|
with(formBody) {
|
||||||
repeat(size()) {
|
repeat(size) {
|
||||||
addEncoded(encodedName(it), encodedValue(it))
|
addEncoded(encodedName(it), encodedValue(it))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ private val logger = KotlinLogging.logger {}
|
|||||||
class CommonParamInterceptor(private vararg val additionParams: ParamExpression) : Interceptor {
|
class CommonParamInterceptor(private vararg val additionParams: ParamExpression) : Interceptor {
|
||||||
override fun intercept(chain: Interceptor.Chain): Response {
|
override fun intercept(chain: Interceptor.Chain): Response {
|
||||||
val request = chain.request()
|
val request = chain.request()
|
||||||
var headers = request.headers()
|
var headers = request.headers
|
||||||
var httpUrl = request.url()
|
var httpUrl = request.url
|
||||||
var body = request.body()
|
var body = request.body
|
||||||
|
|
||||||
//是否强制加到 Query(暂不存在强制加到 FormBody 的情况)
|
//是否强制加到 Query(暂不存在强制加到 FormBody 的情况)
|
||||||
var forceQuery = false
|
var forceQuery = false
|
||||||
@@ -31,8 +31,8 @@ class CommonParamInterceptor(private vararg val additionParams: ParamExpression)
|
|||||||
|
|
||||||
when {
|
when {
|
||||||
//如果是 GET 则添加到 Query
|
//如果是 GET 则添加到 Query
|
||||||
request.method() == Method.GET || forceQuery -> {
|
request.method == Method.GET || forceQuery -> {
|
||||||
httpUrl = request.url().newBuilder().apply {
|
httpUrl = request.url.newBuilder().apply {
|
||||||
additionParams.forEachNonNull { name, value ->
|
additionParams.forEachNonNull { name, value ->
|
||||||
addQueryParameter(name, value)
|
addQueryParameter(name, value)
|
||||||
}
|
}
|
||||||
@@ -60,7 +60,7 @@ class CommonParamInterceptor(private vararg val additionParams: ParamExpression)
|
|||||||
//如果方式不为 GET 且 Body 不为空或者为 FormBody 则无法添加公共参数
|
//如果方式不为 GET 且 Body 不为空或者为 FormBody 则无法添加公共参数
|
||||||
else -> {
|
else -> {
|
||||||
logger.error {
|
logger.error {
|
||||||
"Cannot add params to request: ${request.method()} ${request.url()} ${body.javaClass.simpleName}"
|
"Cannot add params to request: ${request.method} ${request.url} ${body.javaClass.simpleName}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -69,7 +69,7 @@ class CommonParamInterceptor(private vararg val additionParams: ParamExpression)
|
|||||||
request.newBuilder()
|
request.newBuilder()
|
||||||
.headers(headers)
|
.headers(headers)
|
||||||
.url(httpUrl)
|
.url(httpUrl)
|
||||||
.method(request.method(), body)
|
.method(request.method, body)
|
||||||
.build()
|
.build()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import okhttp3.Response
|
|||||||
object FailureResponseInterceptor : Interceptor {
|
object FailureResponseInterceptor : Interceptor {
|
||||||
override fun intercept(chain: Interceptor.Chain): Response {
|
override fun intercept(chain: Interceptor.Chain): Response {
|
||||||
val response = chain.proceed(chain.request())
|
val response = chain.proceed(chain.request())
|
||||||
val body = response.body()
|
val body = response.body
|
||||||
if (!response.isSuccessful || body == null || body.contentLength() == 0L) return response
|
if (!response.isSuccessful || body == null || body.contentLength() == 0L) return response
|
||||||
|
|
||||||
//获取字符集
|
//获取字符集
|
||||||
|
|||||||
@@ -21,13 +21,13 @@ private val logger = KotlinLogging.logger {}
|
|||||||
class SortAndSignInterceptor(private val appSecret: String) : Interceptor {
|
class SortAndSignInterceptor(private val appSecret: String) : Interceptor {
|
||||||
override fun intercept(chain: Interceptor.Chain): Response {
|
override fun intercept(chain: Interceptor.Chain): Response {
|
||||||
var request = chain.request()
|
var request = chain.request()
|
||||||
val url = request.url()
|
val url = request.url
|
||||||
val body = request.body()
|
val body = request.body
|
||||||
|
|
||||||
request = when {
|
request = when {
|
||||||
//判断 appKey 是否在 Query 里
|
//判断 appKey 是否在 Query 里
|
||||||
url.queryParameter(Param.APP_KEY) != null -> {
|
url.queryParameter(Param.APP_KEY) != null -> {
|
||||||
val sortedEncodedQuery = url.encodedQuery()!!.split('&').sorted().joinToString(separator = "&")
|
val sortedEncodedQuery = url.encodedQuery!!.split('&').sorted().joinToString(separator = "&")
|
||||||
request.newBuilder()
|
request.newBuilder()
|
||||||
.url(url.newBuilder()
|
.url(url.newBuilder()
|
||||||
.encodedQuery("$sortedEncodedQuery&${Param.SIGN}=${calculateSign(sortedEncodedQuery, appSecret)}")
|
.encodedQuery("$sortedEncodedQuery&${Param.SIGN}=${calculateSign(sortedEncodedQuery, appSecret)}")
|
||||||
@@ -46,7 +46,7 @@ class SortAndSignInterceptor(private val appSecret: String) : Interceptor {
|
|||||||
addEncoded(Param.SIGN, calculateSign(sortedRaw, appSecret))
|
addEncoded(Param.SIGN, calculateSign(sortedRaw, appSecret))
|
||||||
}.build()
|
}.build()
|
||||||
request.newBuilder()
|
request.newBuilder()
|
||||||
.method(request.method(), formBody)
|
.method(request.method, formBody)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user