mirror of
https://github.com/czp3009/bilibili-api.git
synced 2025-02-19 20:50:28 +08:00
发送弹幕的 API
This commit is contained in:
parent
cc94a8d0c3
commit
7526cee395
13
README.md
13
README.md
@ -331,5 +331,18 @@ danmakuList.forEach {
|
||||
|
||||
番剧的弹幕同理.
|
||||
|
||||
## 发送弹幕
|
||||
光看不发憋着慌, 我们来发送一条视频弹幕:
|
||||
|
||||
```kotlin
|
||||
bilibiliClient.mainAPI.sendDanmaku(aid = 40675923, cid = 71438168, progress = 2297, message = "2333").await()
|
||||
```
|
||||
|
||||
其中 `progress` 是播放器时间, 其他观众将看到你的弹幕在视频的此处出现, 单位为毫秒.
|
||||
|
||||
`message` 应该是有长度限制的, 但是没有测过.
|
||||
|
||||
如果不确定视频的长度, 需要从[视频播放地址的 API](#获取视频播放地址) 中的 `data.timelength` 来获得, 单位也是毫秒.
|
||||
|
||||
# License
|
||||
GPL V3
|
||||
|
@ -11,7 +11,7 @@
|
||||
<!--https://github.com/bilibili/DanmakuFlameMaster/blob/master/Sample/src/main/java/com/sample/BiliDanmukuParser.java 与现在版本不一致-->
|
||||
<!--0: 弹幕 id-->
|
||||
<!--1: 不明确(可能是弹幕池 id)-->
|
||||
<!--2: 弹幕出现时间(从视频开始播放开始计算)(ms)(不一定与弹幕发送者的播放器时间一致)-->
|
||||
<!--2: 弹幕出现时间(播放器时间)(ms)-->
|
||||
<!--3: 类型(1从右至左滚动弹幕|6从左至右滚动弹幕|5顶端固定弹幕|4底端固定弹幕|7高级弹幕|8脚本弹幕)-->
|
||||
<!--4: 字号-->
|
||||
<!--5: 颜色-->
|
||||
|
@ -146,11 +146,13 @@ interface AppAPI {
|
||||
|
||||
/**
|
||||
* 投币
|
||||
* 一个视频能投几个硬币是怎么获得的未知
|
||||
* 自制视频能投两个, 转载视频只能投一个. 是转载还是自制在获取视频页面的 API 的 copyright.
|
||||
*
|
||||
* @param multiply 投币数量
|
||||
* @param selectLike 为 1 表示投币的同时为视频点赞, 对番剧投币时, 该值总为 0
|
||||
* @param upId 该值似乎总为 0
|
||||
*
|
||||
* @see view
|
||||
*/
|
||||
@Suppress("SpellCheckingInspection")
|
||||
@POST("/x/v2/view/coin/add")
|
||||
|
@ -24,6 +24,9 @@ data class View(
|
||||
var cmConfig: CmConfig,
|
||||
@SerializedName("cms")
|
||||
var cms: List<Cm>,
|
||||
/**
|
||||
* copyright 为 1 时表示自制, 2 表示转载
|
||||
*/
|
||||
@SerializedName("copyright")
|
||||
var copyright: Int, // 1
|
||||
@SerializedName("ctime")
|
||||
|
@ -341,4 +341,37 @@ interface MainAPI {
|
||||
@Field("aid") aid: Long,
|
||||
@Field("fid") fid: String
|
||||
): Deferred<CommonResponse>
|
||||
|
||||
/**
|
||||
* 发送弹幕(视频, 番剧)
|
||||
*
|
||||
* @param oid cid
|
||||
* @param random 9 位的随机数字
|
||||
* @param progress 播放器时间(ms)
|
||||
*/
|
||||
@POST("/x/v2/dm/post")
|
||||
@FormUrlEncoded
|
||||
fun sendDanmaku(
|
||||
@Query("aid") aid: Long,
|
||||
@Query("oid") oid: Long,
|
||||
@Field("pool") pool: Int = 0,
|
||||
@Field("rnd") random: Int = (100000000..999999999).random(),
|
||||
@Field("oid") oidInBody: Long,
|
||||
@Field("fontsize") fontSize: Int = 25,
|
||||
@Field("msg") message: String,
|
||||
@Field("mode") mode: Int = 1,
|
||||
@Field("progress") progress: Long,
|
||||
@Field("color") color: Int = 16777215,
|
||||
@Field("plat") plat: Int = 2,
|
||||
@Field("screen_state") screenState: Int = 0,
|
||||
@Field("from") from: Int? = null,
|
||||
@Field("type") type: Int = 1
|
||||
): Deferred<SendDanmakuResponse>
|
||||
|
||||
/**
|
||||
* 发送弹幕的快捷方式
|
||||
*/
|
||||
@JvmDefault
|
||||
fun sendDanmaku(aid: Long, cid: Long, progress: Long, message: String) =
|
||||
sendDanmaku(aid = aid, oid = cid, oidInBody = cid, progress = progress, message = message)
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
package com.hiczp.bilibili.api.main.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class SendDanmakuResponse(
|
||||
@SerializedName("code")
|
||||
var code: Int, // 0
|
||||
@SerializedName("data")
|
||||
var `data`: Data,
|
||||
@SerializedName("message")
|
||||
var message: String, // 0
|
||||
@SerializedName("ttl")
|
||||
var ttl: Int // 1
|
||||
) {
|
||||
@Suppress("SpellCheckingInspection")
|
||||
data class Data(
|
||||
@SerializedName("dmid")
|
||||
var dmid: Long // 12699467350278148
|
||||
)
|
||||
}
|
@ -38,7 +38,7 @@ data class BangumiPlayUrl(
|
||||
@SerializedName("status")
|
||||
var status: Int, // 2
|
||||
@SerializedName("timelength")
|
||||
var timelength: Int, // 1420201
|
||||
var timelength: Long, // 1420201
|
||||
@SerializedName("video_codecid")
|
||||
var videoCodecid: Int, // 7
|
||||
@SerializedName("video_project")
|
||||
|
@ -38,7 +38,7 @@ data class VideoPlayUrl(
|
||||
@SerializedName("seek_type")
|
||||
var seekType: String, // offset
|
||||
@SerializedName("timelength")
|
||||
var timelength: Int, // 196367
|
||||
var timelength: Long, // 196367
|
||||
@SerializedName("video_codecid")
|
||||
var videoCodecid: Int, // 7
|
||||
@SerializedName("video_project")
|
||||
|
@ -0,0 +1,13 @@
|
||||
package com.hiczp.bilibili.api.test
|
||||
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class SendDanmakuTest {
|
||||
@Test
|
||||
fun sendDanmaku() {
|
||||
runBlocking {
|
||||
bilibiliClient.mainAPI.sendDanmaku(aid = 40675923, cid = 71438168, progress = 2297, message = "2333").await()
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user