diff --git a/dm.py b/dm.py index 52dedf0..c0698c6 100644 --- a/dm.py +++ b/dm.py @@ -144,7 +144,6 @@ class TableWidgetExample(QMainWindow): self.statusBar().showMessage("主机、端口、数据库名、用户名和密码不能为空!") QMessageBox.critical(self, "Error", "主机、端口、数据库名、用户名和密码不能为空!") return - try: socket.gethostbyname(host) except socket.error: diff --git a/getDm.py b/getDm.py new file mode 100644 index 0000000..7d497d1 --- /dev/null +++ b/getDm.py @@ -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() \ No newline at end of file