94 lines
2.3 KiB
Python
94 lines
2.3 KiB
Python
|
|
import json
|
||
|
|
import threading
|
||
|
|
import subprocess
|
||
|
|
import time
|
||
|
|
|
||
|
|
lock = threading.Lock()
|
||
|
|
|
||
|
|
|
||
|
|
def mumu_rename(id, name):
|
||
|
|
# 定义命令
|
||
|
|
command = [result1, "rename", "-v", f'{id}', "-n", f"{name}"]
|
||
|
|
|
||
|
|
# 运行命令并捕获输出,使用 utf-8 编码
|
||
|
|
result = subprocess.run(command, capture_output=True, text=True, encoding='utf-8')
|
||
|
|
|
||
|
|
|
||
|
|
def mumu_quit(id):
|
||
|
|
# 定义命令
|
||
|
|
command = [result1, "control", "-v", f'{id}', "shutdown"]
|
||
|
|
|
||
|
|
# 运行命令并捕获输出,使用 utf-8 编码
|
||
|
|
result = subprocess.run(command, capture_output=True, text=True, encoding='utf-8')
|
||
|
|
|
||
|
|
|
||
|
|
def mumu_create():
|
||
|
|
# 定义命令
|
||
|
|
command = [result1, "create", ]
|
||
|
|
|
||
|
|
# 运行命令并捕获输出,使用 utf-8 编码
|
||
|
|
result = subprocess.run(command, capture_output=True, text=True, encoding='utf-8')
|
||
|
|
|
||
|
|
# 将 JSON 字符串解析为字典
|
||
|
|
data = json.loads(result.stdout)
|
||
|
|
|
||
|
|
# 将 keys() 返回的 dict_keys 对象转换为列表
|
||
|
|
keys_list = list(data.keys())
|
||
|
|
|
||
|
|
# 获取第一个键
|
||
|
|
first_key = keys_list[0]
|
||
|
|
|
||
|
|
return first_key
|
||
|
|
|
||
|
|
|
||
|
|
def mumu_start(id):
|
||
|
|
# 定义命令
|
||
|
|
command = [result1, "control", "-v", f'{id}', "launch"]
|
||
|
|
|
||
|
|
# 运行命令并捕获输出,使用 utf-8 编码
|
||
|
|
result = subprocess.run(command, capture_output=True, text=True, encoding='utf-8')
|
||
|
|
|
||
|
|
with lock:
|
||
|
|
for i1 in range(250):
|
||
|
|
for i in mumu_get_list_all():
|
||
|
|
if i["index"] == str(id):
|
||
|
|
if i.get("adb_port"):
|
||
|
|
return i["adb_port"]
|
||
|
|
time.sleep(1)
|
||
|
|
|
||
|
|
return False
|
||
|
|
|
||
|
|
|
||
|
|
def mumu_get_list_all():
|
||
|
|
# 定义命令
|
||
|
|
command = [result1, "info", "-v", "all"]
|
||
|
|
|
||
|
|
# 运行命令并捕获输出,使用 utf-8 编码
|
||
|
|
result = subprocess.run(command, capture_output=True, text=True, encoding='utf-8')
|
||
|
|
|
||
|
|
# 检查命令是否成功执行
|
||
|
|
if result.returncode != 0:
|
||
|
|
return None
|
||
|
|
|
||
|
|
# 解析 JSON 输出
|
||
|
|
try:
|
||
|
|
info = json.loads(result.stdout)
|
||
|
|
|
||
|
|
infos = []
|
||
|
|
for i in info:
|
||
|
|
infos.append(info[i])
|
||
|
|
|
||
|
|
return infos # 返回一个包含嵌套字典的列表
|
||
|
|
except json.JSONDecodeError as e:
|
||
|
|
return None
|
||
|
|
|
||
|
|
|
||
|
|
result1 = r"MuMuManager.exe"
|
||
|
|
# if __name__ == '__main__':
|
||
|
|
# mumu_quit(id=1)
|
||
|
|
|
||
|
|
# for i in mumu_get_list_all():
|
||
|
|
# print(i)
|
||
|
|
|
||
|
|
# mumu_create()
|