bump version

This commit is contained in:
czp3009 2020-04-08 14:31:28 +08:00
parent 65ef6f232d
commit 10281fa1ce
8 changed files with 34 additions and 33 deletions

View File

@ -1,8 +1,8 @@
buildscript {
ext {
kotlin_version = '1.3.21'
kotlin_coroutines_version = '1.1.1'
ktor_version = '1.1.3'
kotlin_version = '1.3.71'
kotlin_coroutines_version = '1.3.5'
ktor_version = '1.3.1'
jvm_target = JavaVersion.VERSION_1_8
}
@ -25,6 +25,7 @@ apply plugin: 'signing'
repositories {
mavenCentral()
jcenter()
mavenLocal()
}
@ -48,29 +49,29 @@ compileTestKotlin {
//logging
dependencies {
// 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
testCompile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.26'
testCompile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.30'
}
//http
dependencies {
// 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
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
compile group: 'com.github.salomonbrys.kotson', name: 'kotson', version: '2.5.0'
// 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'
// 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
dependencies {
// https://mvnrepository.com/artifact/io.ktor/ktor-client-websocket
compile group: 'io.ktor', name: 'ktor-client-websocket', version: ktor_version
// https://mvnrepository.com/artifact/io.ktor/ktor-client-websockets
compile group: 'io.ktor', name: 'ktor-client-websockets', version: ktor_version
// https://mvnrepository.com/artifact/io.ktor/ktor-client-cio
compile group: 'io.ktor', name: 'ktor-client-cio', version: ktor_version
}
@ -84,7 +85,7 @@ dependencies {
//unit test
dependencies {
// 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) {

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
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

View File

@ -2,7 +2,7 @@ package com.hiczp.bilibili.api
import com.hiczp.bilibili.api.thirdpart.commons.BoundedInputStream
import io.ktor.util.InternalAPI
import kotlinx.io.errors.EOFException
import io.ktor.utils.io.errors.EOFException
import java.io.InputStream
//减少包引入

View File

@ -25,17 +25,17 @@ class PlayerInterceptor(
val request = chain.request()
//添加 header
val header = request.headers().newBuilder().apply {
val header = request.headers.newBuilder().apply {
add(Header.ACCEPT, "*/*")
add(Header.USER_AGENT, "Bilibili Freedoooooom/MarkII")
add(Header.ACCEPT_LANGUAGE, "zh-CN,zh;q=0.8")
}.build()
//添加 Query Params
val oldUrl = request.url()
val oldUrl = request.url
//如果是视频播放地址这个 API, 要用特殊的 appKey
val isVideo = oldUrl.toString().startsWith(PlayerAPI.videoPlayUrl)
val url = StringBuilder(oldUrl.encodedQuery() ?: "").apply {
val url = StringBuilder(oldUrl.encodedQuery ?: "").apply {
//appKey
addParamEncode(Param.APP_KEY, if (isVideo) bilibiliClientProperties.videoAppKey else bilibiliClientProperties.appKey)
//凭证有关

View File

@ -3,14 +3,14 @@ package com.hiczp.bilibili.api.retrofit
import okhttp3.FormBody
inline fun FormBody.forEach(block: (String, String) -> Unit) {
repeat(size()) {
repeat(size) {
block(encodedName(it), encodedValue(it))
}
}
fun FormBody.raw() =
StringBuilder().apply {
repeat(size()) {
repeat(size) {
if (it != 0) append('&')
append(encodedName(it))
append('=')
@ -20,14 +20,14 @@ fun FormBody.raw() =
fun FormBody.sortedRaw(): String {
val nameAndValue = ArrayList<String>()
repeat(size()) {
repeat(size) {
nameAndValue.add("${encodedName(it)}=${encodedValue(it)}")
}
return nameAndValue.sorted().joinToString(separator = "&")
}
fun FormBody.containsEncodedName(name: String): Boolean {
repeat(size()) {
repeat(size) {
if (encodedName(it) == name) return true
}
return false
@ -35,7 +35,7 @@ fun FormBody.containsEncodedName(name: String): Boolean {
fun FormBody.Builder.addAllEncoded(formBody: FormBody): FormBody.Builder {
with(formBody) {
repeat(size()) {
repeat(size) {
addEncoded(encodedName(it), encodedValue(it))
}
}

View File

@ -17,9 +17,9 @@ private val logger = KotlinLogging.logger {}
class CommonParamInterceptor(private vararg val additionParams: ParamExpression) : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request()
var headers = request.headers()
var httpUrl = request.url()
var body = request.body()
var headers = request.headers
var httpUrl = request.url
var body = request.body
//是否强制加到 Query(暂不存在强制加到 FormBody 的情况)
var forceQuery = false
@ -31,8 +31,8 @@ class CommonParamInterceptor(private vararg val additionParams: ParamExpression)
when {
//如果是 GET 则添加到 Query
request.method() == Method.GET || forceQuery -> {
httpUrl = request.url().newBuilder().apply {
request.method == Method.GET || forceQuery -> {
httpUrl = request.url.newBuilder().apply {
additionParams.forEachNonNull { name, value ->
addQueryParameter(name, value)
}
@ -60,7 +60,7 @@ class CommonParamInterceptor(private vararg val additionParams: ParamExpression)
//如果方式不为 GET 且 Body 不为空或者为 FormBody 则无法添加公共参数
else -> {
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()
.headers(headers)
.url(httpUrl)
.method(request.method(), body)
.method(request.method, body)
.build()
)
}

View File

@ -15,7 +15,7 @@ import okhttp3.Response
object FailureResponseInterceptor : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
val response = chain.proceed(chain.request())
val body = response.body()
val body = response.body
if (!response.isSuccessful || body == null || body.contentLength() == 0L) return response
//获取字符集

View File

@ -21,13 +21,13 @@ private val logger = KotlinLogging.logger {}
class SortAndSignInterceptor(private val appSecret: String) : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
var request = chain.request()
val url = request.url()
val body = request.body()
val url = request.url
val body = request.body
request = when {
//判断 appKey 是否在 Query 里
url.queryParameter(Param.APP_KEY) != null -> {
val sortedEncodedQuery = url.encodedQuery()!!.split('&').sorted().joinToString(separator = "&")
val sortedEncodedQuery = url.encodedQuery!!.split('&').sorted().joinToString(separator = "&")
request.newBuilder()
.url(url.newBuilder()
.encodedQuery("$sortedEncodedQuery&${Param.SIGN}=${calculateSign(sortedEncodedQuery, appSecret)}")
@ -46,7 +46,7 @@ class SortAndSignInterceptor(private val appSecret: String) : Interceptor {
addEncoded(Param.SIGN, calculateSign(sortedRaw, appSecret))
}.build()
request.newBuilder()
.method(request.method(), formBody)
.method(request.method, formBody)
.build()
}