适用 Python 控制 Virtual studio 的方法
pyvts python库
vts可以通过第三方库完成控制,该library的定义大概如下:
基础类pyvts.vts
- pyvts.vts用于完成所有对vts的控制,其中封装了所有和vts交互的函数
- vts的初始化方法如下:
info = {"plugin_name": "a","developer": "b", "authentication_token_path": "./token.txt"} pyvts.vts(plugin_info=info)
- 实例化之后一般的连接流程为:
await vts.connect() # start connection await vts.request_authenticate_token() # get token await vts.request_authenticate() # use token ''' do anything ''' await vts.close()
申请、存储、读取、使用token连接vts
- 使用request_authenticate_token()函数获取token之后,使用write_token()写入到本地
await vts.write_token() # 写入token
- 因此第一次连接获取token之后存储在本地,后续使用就不需要重新获取token(暂时不知道token会不会超时),不需要每次启动程序就手动在vts中授权token
import pyvts import asyncio async def get_token(myvts): await myvts.connect() print(f"申请token,在vtsGUI中授权") await myvts.request_authenticate_token() # get token print(f"获取到token:{myvts.authentic_token}") await myvts.write_token() # 写入token await myvts.close() # 断开连接 async def main_function(myvts): await myvts.connect() await myvts.read_token() await myvts.request_authenticate() # use token print(f"当前使用token:{myvts.authentic_token},连接成功") await myvts.close() if __name__ == "__main__": plugin_info = { "plugin_name": "aoko_animation_controller", "developer": "LeeShunEE", "authentication_token_path": "./token.txt" } myvts = pyvts.vts(plugin_info=plugin_info) asyncio.run(get_token(myvts)) asyncio.run(main_function(myvts))
License:
CC BY 4.0