| 平台 | 弹幕(消息) | 点赞 | 礼物 | 进入直播间 | 关注 | 原始流地址 |
|---|---|---|---|---|---|---|
| 抖音(Hack) | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| TikTok (Hack) | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
<dependency>
<groupId>cool.scx</groupId>
<artifactId>live-room-watcher</artifactId>
<version>{version}</version>
</dependency>
import cool.scx.live_room_watcher.impl.douyin_hack.DouYinHackLiveRoomWatcher;
import static cool.scx.live_room_watcher.impl.douyin_hack.DouYinHackLiveRoomInfoResolver.resolveLiveRoomInfo;
import static cool.scx.live_room_watcher.impl.douyin_hack.DouYinHackWebSocketOptionsProvider.ofPlaywright;
public class Main {
public static void main(String[] args) {
var liveRoomURL = "https://live.douyin.com/510200350291";
var cookiesStr = "xxxxxx";
System.out.println("解析 直播间 中...");
var liveRoomInfo = resolveLiveRoomInfo(liveRoomURL);
System.out.println("解析 直播间 完成 -> " + liveRoomInfo.title() + " (ID : " + liveRoomInfo.roomID() + ")");
System.out.println("[直播流地址] " + liveRoomInfo.webStreamURLs());
var liveRoomWatcher = new DouYinHackLiveRoomWatcher(ofPlaywright(liveRoomURL, cookiesStr));
liveRoomWatcher.onChat(chat -> {
System.out.println("[消息] " + chat.user().nickname() + " : " + chat.content());
}).onUser(user -> {
System.out.println("[来了] " + user.nickname());
}).onLike(like -> {
System.out.println("[点赞] " + like.user().nickname() + " x " + like.count());
}).onFollow(follow -> {
System.out.println("[关注] " + follow.user().nickname());
}).onGift(gift -> {
System.out.println("[礼物] " + gift.user().nickname() + " : " + gift.name() + " x " + gift.count());
});
liveRoomWatcher.startWatch();
}
}
这里提供一个小 Chrome 插件 "chrome-extension"
1, 安装到 Chrome 浏览器中 (相同内核都可以)
2, 打开一个抖音 直播间
3, 打开插件 复制 Cookie 字符串 和 WebSocket (最长的那个)
4, 使用 DouYinHackLiveRoomWatcher 监听 这里有两种方式
4.1, 如果使用 ofPlaywright(), 只需要 直播间页面地址 + cookie 就可以
4.2, 如果使用 ofWebSocketURL(), 需要 刚刚复制的 WebSocket 地址 + cookie
如果连接失败, 建议重试几次