mirror of
https://github.com/czp3009/bilibili-api.git
synced 2025-02-19 20:50:28 +08:00
反查弹幕发送者 ID
This commit is contained in:
parent
7526cee395
commit
75886f5ede
@ -22,6 +22,7 @@ apply plugin: 'kotlin'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
//kotlin
|
||||
@ -71,6 +72,12 @@ dependencies {
|
||||
compile group: 'commons-io', name: 'commons-io', version: '2.6'
|
||||
}
|
||||
|
||||
//checksum
|
||||
dependencies {
|
||||
// https://mvnrepository.com/artifact/com.hiczp/crc32-crack
|
||||
compile group: 'com.hiczp', name: 'crc32-crack', version: '1.0'
|
||||
}
|
||||
|
||||
//unit test
|
||||
dependencies {
|
||||
// https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.hiczp.bilibili.api.danmaku
|
||||
|
||||
import com.hiczp.crc32crack.Crc32Cracker
|
||||
|
||||
data class Danmaku(
|
||||
/**
|
||||
* 弹幕 id
|
||||
@ -54,4 +56,11 @@ data class Danmaku(
|
||||
* 这可能表示某种特殊的输出格式
|
||||
*/
|
||||
val content: String
|
||||
)
|
||||
) {
|
||||
/**
|
||||
* 计算弹幕发送者 ID(可能有多个)
|
||||
* 第一次调用 Crc32Cracker 将花费大约 300ms 来生成反查表
|
||||
* hash 反查通常不超过 1ms
|
||||
*/
|
||||
fun calculatePossibleUserIds() = Crc32Cracker.crack(user)
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import kotlinx.coroutines.runBlocking
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class DanmakuTest {
|
||||
//339.6kib 的弹幕文件在 0.5s 内解析完毕(i5-4200H), 通常视频的弹幕不会超过这个容量
|
||||
//6250 行弹幕的解析加用户 ID 反查在 4098ms 内完成(i7-8700)
|
||||
@Test
|
||||
fun fetchAndParseDanmaku() {
|
||||
runBlocking {
|
||||
@ -13,7 +13,7 @@ class DanmakuTest {
|
||||
val responseBody = bilibiliClient.danmakuAPI.list(aid = 810872, oid = 1176840).await()
|
||||
timer {
|
||||
DanmakuParser.parse(responseBody.byteStream()).second.forEach {
|
||||
println("[${it.time}] ${it.content}")
|
||||
println("[${it.time}] ${it.calculatePossibleUserIds()} ${it.content}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user