This commit is contained in:
rainerosion 2023-10-06 12:56:00 +08:00
parent 20a60d8e6b
commit 56ba6bd562
2 changed files with 36 additions and 1 deletions

1
dm.py
View File

@ -144,7 +144,6 @@ class TableWidgetExample(QMainWindow):
self.statusBar().showMessage("主机、端口、数据库名、用户名和密码不能为空!")
QMessageBox.critical(self, "Error", "主机、端口、数据库名、用户名和密码不能为空!")
return
try:
socket.gethostbyname(host)
except socket.error:

36
getDm.py Normal file
View File

@ -0,0 +1,36 @@
import asyncio
import httpx
class DanMu():
def __init__(self):
super().__init__()
async def tencent(self, vid):
async with httpx.AsyncClient() as client:
base_url = f"https://dm.video.qq.com/barrage/base/{vid}"
res = await client.get(base_url)
if res.status_code == 200:
json_data = res.json()
segment_data = json_data.get("segment_index")
# data index
max_index = len(segment_data) - 1
# max end page
max_page = max_index * 30000
# Calculate the amount of data acquired per page
per_count = 20000 / max_index
for i in range(0, 1):
print(i)
else:
# 处理请求失败的情况
return None
async def main():
dm = DanMu()
result = await dm.tencent("p0047s9euki")
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.close()