diff --git "a/Scripts/\347\233\264\346\222\255ws\350\204\232\346\234\254/\347\233\264\346\222\255\345\274\271\345\271\225\347\233\221\345\220\254 \350\275\254\345\217\221\350\207\263\346\234\254\345\234\260WS\346\234\215\345\212\241\347\253\257.js" "b/Scripts/\347\233\264\346\222\255ws\350\204\232\346\234\254/\346\264\233\346\233\246 \347\233\264\346\222\255\345\274\271\345\271\225\347\233\221\345\220\254 \350\275\254\345\217\221\350\207\263\346\234\254\345\234\260WS\346\234\215\345\212\241\347\253\257.js" similarity index 84% rename from "Scripts/\347\233\264\346\222\255ws\350\204\232\346\234\254/\347\233\264\346\222\255\345\274\271\345\271\225\347\233\221\345\220\254 \350\275\254\345\217\221\350\207\263\346\234\254\345\234\260WS\346\234\215\345\212\241\347\253\257.js" rename to "Scripts/\347\233\264\346\222\255ws\350\204\232\346\234\254/\346\264\233\346\233\246 \347\233\264\346\222\255\345\274\271\345\271\225\347\233\221\345\220\254 \350\275\254\345\217\221\350\207\263\346\234\254\345\234\260WS\346\234\215\345\212\241\347\253\257.js" index 66378fbe..74b6fc42 100644 --- "a/Scripts/\347\233\264\346\222\255ws\350\204\232\346\234\254/\347\233\264\346\222\255\345\274\271\345\271\225\347\233\221\345\220\254 \350\275\254\345\217\221\350\207\263\346\234\254\345\234\260WS\346\234\215\345\212\241\347\253\257.js" +++ "b/Scripts/\347\233\264\346\222\255ws\350\204\232\346\234\254/\346\264\233\346\233\246 \347\233\264\346\222\255\345\274\271\345\271\225\347\233\221\345\220\254 \350\275\254\345\217\221\350\207\263\346\234\254\345\234\260WS\346\234\215\345\212\241\347\253\257.js" @@ -1,7 +1,7 @@ // ==UserScript== -// @name 直播弹幕监听 转发至本地WS服务端 +// @name 洛曦 直播弹幕监听 转发至本地WS服务端 // @namespace http://tampermonkey.net/ -// @version 0.10 +// @version 0.11 // @description 观察指定 DOM 节点的变化以将数据发送到连接的WebSocket服务端 // @description Github:https://github.com/Ikaros-521/AI-Vtuber/tree/main/Scripts/%E7%9B%B4%E6%92%ADws%E8%84%9A%E6%9C%AC // @author Ikaros @@ -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 @@ -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() { @@ -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)); + } + } + }); + } + }); + }); } // 配置观察选项 diff --git a/main.py b/main.py index c0401acb..58f70b99 100644 --- a/main.py +++ b/main.py @@ -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 @@ -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): diff --git a/webui.py b/webui.py index 4da00f94..3e1e4dc3 100644 --- a/webui.py +++ b/webui.py @@ -3433,6 +3433,7 @@ def save_config(): 'ks2': '快手2', 'pdd': '拼多多', 'wxlive': '微信视频号', + 'taobao': '淘宝', '1688': '1688', 'douyu': '斗鱼', 'ordinaryroad_barrage_fly': '让弹幕飞',