Skip to content

Commit

Permalink
补充:遗漏的淘宝平台配置项
Browse files Browse the repository at this point in the history
  • Loading branch information
Ikaros-521 committed Oct 31, 2024
1 parent 894b134 commit 17a1084
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name 直播弹幕监听 转发至本地WS服务端
// @name 洛曦 直播弹幕监听 转发至本地WS服务端
// @namespace http://tampermonkey.net/
// @version 0.10
// @version 0.11
// @description 观察指定 DOM 节点的变化以将数据发送到连接的WebSocket服务端
// @description Githubhttps://github.com/Ikaros-521/AI-Vtuber/tree/main/Scripts/%E7%9B%B4%E6%92%ADws%E8%84%9A%E6%9C%AC
// @author Ikaros
Expand All @@ -10,6 +10,7 @@
// @match https://live.kuaishou.com/u/*
// @match https://mobile.yangkeduo.com/*
// @match https://live.1688.com/zb/play.html*
// @match https://tbzb.taobao.com/live*
// @grant none
// @namespace https://greasyfork.org/scripts/490966
// @license GPL-3.0
Expand Down Expand Up @@ -40,6 +41,9 @@
} else if (hostname === "live.1688.com") {
console.log("当前直播平台:1688");
wsUrl = "ws://127.0.0.1:5000";
} else if (hostname === "tbzb.taobao.com") {
console.log("当前直播平台:淘宝");
wsUrl = "ws://127.0.0.1:5000";
}

function connectWebSocket() {
Expand Down Expand Up @@ -306,6 +310,58 @@
}
});
});
} else if (hostname === "tbzb.taobao.com") {
targetNode = document.querySelector("#liveComment");

// 创建观察器实例
my_observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
// 这里处理新增的DOM元素
if (mutation.type === "childList") {

mutation.addedNodes.forEach((node) => {
// 判断是否是新增的弹幕消息
if (node.classList.contains("itemWrap--EcN_tFIg")) {
// 新增的动态DOM元素处理
console.log('Added node:', node);

const spans = node.getElementsByTagName("span");

let username = "";
let content = "";

for (let span of spans) {
//console.log(span);
if (span.classList.contains("authorTitle--_Dl75ZJ6")) {
const targetSpan = span;
// 获取用户名
let tmp = targetSpan.textContent.trim().slice(0, -1);
if (tmp != "")
username = targetSpan.textContent.trim().slice(0, -1);
} else if (span.classList.contains("content--pSjaTkyl")) {
const targetSpan = span;
// 获取弹幕内容
content = targetSpan.textContent.trim();
}
}

console.log(username + ":" + content);

// 获取到弹幕数据
if (username != "" && content != "") {
const data = {
type: "comment",
username: username,
content: content,
};
console.log(data);
my_socket.send(JSON.stringify(data));
}
}
});
}
});
});
}

// 配置观察选项
Expand Down
51 changes: 1 addition & 50 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2214,55 +2214,6 @@ def _on_open_live_like(
logger.info(f"用户:{message.uname} 点了个赞")

asyncio.run(main_func())
elif platform == "douyu":
import websockets

async def on_message(websocket, path):
global last_liveroom_data, last_username_list
global global_idle_time

async for message in websocket:
# logger.info(f"收到消息: {message}")
# await websocket.send("服务器收到了你的消息: " + message)

try:
data_json = json.loads(message)
# logger.debug(data_json)
if data_json["type"] == "comment":
# logger.info(data_json)
# 闲时计数清零
idle_time_auto_clear("comment")

username = data_json["username"]
content = data_json["content"]

logger.info(f"[📧直播间弹幕消息] [{username}]:{content}")

data = {
"platform": platform,
"username": username,
"content": content,
}

my_handle.process_data(data, "comment")

# 添加用户名到最新的用户名列表
add_username_to_last_username_list(username)

except Exception as e:
logger.error(traceback.format_exc())
logger.error("数据解析错误!")
my_handle.abnormal_alarm_handle("platform")
continue

async def ws_server():
ws_url = "127.0.0.1"
ws_port = 5000
server = await websockets.serve(on_message, ws_url, ws_port)
logger.info(f"WebSocket 服务器已在 {ws_url}:{ws_port} 启动")
await server.wait_closed()

asyncio.run(ws_server())
elif platform == "dy":
import websocket

Expand Down Expand Up @@ -3203,7 +3154,7 @@ def run_live(self):
i.join()

run().run_live()
elif platform in ["pdd", "1688"]:
elif platform in ["pdd", "douyu", "1688", "taobao"]:
import websockets

async def on_message(websocket, path):
Expand Down
1 change: 1 addition & 0 deletions webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -3433,6 +3433,7 @@ def save_config():
'ks2': '快手2',
'pdd': '拼多多',
'wxlive': '微信视频号',
'taobao': '淘宝',
'1688': '1688',
'douyu': '斗鱼',
'ordinaryroad_barrage_fly': '让弹幕飞',
Expand Down

0 comments on commit 17a1084

Please sign in to comment.