代码拉取完成,页面将自动刷新
同步操作将从 LanRenZhiNeng/懒人原神AI 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import time
import pyautogui
import requests
from lanrentools import moni
class BiLiBiLiDanMu():
def __init__(self,roomid="22744134"):
'''
简单版弹幕获取
:param roomid:
'''
pyautogui.PAUSE = 0.01
pyautogui.FAILSAFE = False
self.roomid=roomid
self.danmu_olds=[]
self.jishi=0
self.zanting=False
self.headers={
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/108.0.1462.42'
}
def get_danmu_new(self):
url="https://api.live.bilibili.com/xlive/web-room/v1/dM/gethistory?roomid="+self.roomid+"&room_type=0"
danmu_new=[]
res=requests.get(url,headers=self.headers)
if res.status_code==200:
for item in res.json()["data"]["room"]:
if item not in self.danmu_olds:
#print(item["dm_type"],item["nickname"],f"({item['uid']})",item["text"])
danmu_new.append(item)
if self.danmu_olds==[]:
self.danmu_olds +=danmu_new
if len(self.danmu_olds) >= 200:
self.danmu_olds = self.danmu_olds[50:]
return []
else:
self.danmu_olds +=danmu_new
if len(self.danmu_olds) >= 200:
self.danmu_olds = self.danmu_olds[50:]
return danmu_new
def zheng_gu(self,danmus):
is_cmd=False
for item in danmus:
if "W" in item["text"] or "w" in item["text"] or "前" == item["text"]or "上" == item["text"]:
is_cmd=True
print(f'弹幕操作:{item["nickname"]} 按下 W 2秒')
pyautogui.keyDown("w")
time.sleep(2)
pyautogui.keyUp("w")
elif "A" in item["text"] or "a" in item["text"] or "左" == item["text"]:
is_cmd = True
print(f'弹幕操作:{item["nickname"]} 按下 A 2秒')
pyautogui.keyDown("a")
time.sleep(2)
pyautogui.keyUp("a")
elif "S" in item["text"] or "s" in item["text"] or "后" == item["text"]or "下" == item["text"]:
is_cmd = True
print(f'弹幕操作:{item["nickname"]} 按下 S 2秒')
pyautogui.keyDown("s")
time.sleep(2)
pyautogui.keyUp("s")
elif "D" in item["text"] or "d" in item["text"] or "右" == item["text"] :
is_cmd = True
print(f'弹幕操作:{item["nickname"]} 按下 D 2秒')
pyautogui.keyDown("d")
time.sleep(2)
pyautogui.keyUp("d")
elif "X" in item["text"] or "x" in item["text"] or "松" == item["text"] or "放" == item["text"]:
is_cmd = True
print(f'弹幕操作:{item["nickname"]} 按下 X')
pyautogui.keyDown("x")
time.sleep(0.3)
pyautogui.keyUp("x")
elif "space" in item["text"] or "SPACE" in item["text"] or "Space" in item["text"] or "跳" in item["text"]:
is_cmd = True
print(f'弹幕操作:{item["nickname"]} 按一次 跳')
pyautogui.keyDown("space")
time.sleep(0.2)
pyautogui.keyUp("space")
elif "翅膀" in item["text"] or "风之翼" in item["text"] or "滑行" in item["text"]:
is_cmd = True
print(f'弹幕操作:{item["nickname"]} 开翅膀')
pyautogui.keyDown('space')
time.sleep(0.2)
pyautogui.keyUp('space')
elif "Q" in item["text"] or "q" in item["text"] or "大招" in item["text"] :
is_cmd = True
print(f'弹幕操作:{item["nickname"]} 释放大招')
pyautogui.keyDown("q")
time.sleep(0.2)
pyautogui.keyUp("q")
elif "E" in item["text"] or "e" in item["text"] or "战技" in item["text"] :
is_cmd = True
if "长按" in item["text"]:
print(f'弹幕操作:{item["nickname"]} 长按战技')
pyautogui.keyDown("e")
time.sleep(1)
pyautogui.keyUp("e")
else:
print(f'弹幕操作:{item["nickname"]} 释放战技')
pyautogui.keyDown("e")
time.sleep(0.2)
pyautogui.keyUp("e")
elif "1" in item["text"] :
is_cmd = True
print(f'弹幕操作:{item["nickname"]} 切换角色 1 ')
pyautogui.keyDown("1")
time.sleep(0.2)
pyautogui.keyUp("1")
elif "2" in item["text"] :
is_cmd = True
print(f'弹幕操作:{item["nickname"]} 切换角色 2 ')
pyautogui.keyDown("2")
time.sleep(0.2)
pyautogui.keyUp("2")
elif "3" in item["text"] :
is_cmd = True
print(f'弹幕操作:{item["nickname"]} 切换角色 3 ')
pyautogui.keyDown("3")
time.sleep(0.2)
pyautogui.keyUp("3")
elif "4" in item["text"] :
is_cmd = True
print(f'弹幕操作:{item["nickname"]} 切换角色 4 ')
pyautogui.keyDown("4")
time.sleep(0.2)
pyautogui.keyUp("4")
elif "F" == item["text"] or "f" == item["text"] or "捡" in item["text"]:
is_cmd = True
print(f'弹幕操作:{item["nickname"]} 按F')
pyautogui.keyDown("f")
time.sleep(0.2)
pyautogui.keyUp("f")
elif "k" in item["text"] or "K" in item["text"] or "打" in item["text"]:
is_cmd = True
print(f'弹幕操作:{item["nickname"]} 平A 3次')
pyautogui.leftClick()
moni.mouse_left_down()
time.sleep(0.1)
moni.mouse_left_up()
time.sleep(0.1)
moni.mouse_left_down()
time.sleep(0.1)
moni.mouse_left_up()
time.sleep(0.1)
moni.mouse_left_down()
time.sleep(0.1)
moni.mouse_left_up()
elif "shift" in item["text"] or "Shift" in item["text"] or "SHIFT" in item["text"] or "跑" in item["text"]or "冲刺" in item["text"]:
is_cmd = True
print(f'弹幕操作:{item["nickname"]} 加速 跑一次')
pyautogui.keyDown("shift")
time.sleep(0.3)
pyautogui.keyUp("shift")
elif "暂停" in item["text"] or "F8" in item["text"] or "f8" in item["text"]:
is_cmd = True
if self.zanting:
self.zanting=False
print(f'弹幕操作:{item["nickname"]} 按F8 继续')
self.jishi = 0
else:
self.zanting=True
print(f'弹幕操作:{item["nickname"]} 按F8 暂停 15秒后恢复')
self.jishi =100
pyautogui.keyDown("F8")
time.sleep(0.1)
pyautogui.keyUp("F8")
time.sleep(0.4)
pyautogui.keyUp("w")
if is_cmd==False:
time.sleep(0.2)
if __name__ == '__main__':
roomid=input("请输入直播间号:")
if len(roomid)<=4:
roomid="22744134"
danmu=BiLiBiLiDanMu(roomid)
while True:
danmu.zheng_gu(danmu.get_danmu_new())
if danmu.zanting:
danmu.jishi-=1
if danmu.jishi <=0:
print("系统操作:自动恢复AI托管")
pyautogui.keyDown("F8")
time.sleep(0.1)
pyautogui.keyUp("F8")
danmu.jishi=0
danmu.zanting=False
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。