20250904-初步功能已完成

This commit is contained in:
2025-09-18 13:07:11 +08:00
parent db67024157
commit d7e1d993fb
4 changed files with 158 additions and 100 deletions

View File

@@ -1,6 +1,8 @@
import math
import random
import re
import time
from typing import Tuple, List
import tidevice
import wda
@@ -70,13 +72,15 @@ class ControlUtils(object):
return True
elif session.xpath("//*[@name='nav_bar_start_back']").exists:
back = session.xpath("//*[@name='nav_bar_start_back']")
back.click()
if back.exists:
back.click()
return True
elif session.xpath(
"//Window[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]").exists:
back = session.xpath(
"//Window[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]/Other[1]")
back.click()
if back.exists:
back.click()
return True
else:
return False
@@ -129,6 +133,7 @@ class ControlUtils(object):
videoCell = session.xpath(
'(//XCUIElementTypeCollectionView//XCUIElementTypeCell[.//XCUIElementTypeImage[@name="profile_video"]])[1]')
tab = session.xpath(
'//XCUIElementTypeButton[@name="TTKProfileTabVideoButton_0" or contains(@label,"作品") or contains(@name,"作品")]'
).get(timeout=5) # 某些版本 tab.value 可能就是数量;或者 tab.label 类似 “作品 7”
@@ -204,33 +209,65 @@ class ControlUtils(object):
print(e)
return False
# 随机滑动一点点距离
@classmethod
def tap_mini_cluster(cls, center_x: int, center_y: int, session, points=5, duration_ms=60):
try:
response = session.http.post(
"touchAndHold",
data={
"x": 100,
"y": 100,+
"duration": 0.1
}
)
print(response)
return response
except Exception as e:
print(e)
return None
# 检测五分钟前和当前的状态是否相同
# @classmethod
# def compareCurrentWithPreviousState(cls,xml):
def random_micro_swipe(
cls,
center_x: int,
center_y: int,
session,
points: int = 6,
duration_ms: int = 15,
) -> None:
"""
在 (center_x, center_y) 附近做 20px 左右的不规则微滑动。
使用 facebook-wda 的 session.swipe(x1, y1, x2, y2, duration) 接口。
"""
# 1. 随机方向
angle = random.uniform(0, 2 * math.pi)
length = random.uniform(18, 22) # 20px 左右
end_x = center_x + length * math.cos(angle)
end_y = center_y + length * math.sin(angle)
# 2. 限制在 20px 圆内(防止超出)
def clamp_to_circle(x, y, cx, cy, r):
dx = x - cx
dy = y - cy
if dx * dx + dy * dy > r * r:
scale = r / math.hypot(dx, dy)
x = cx + dx * scale
y = cy + dy * scale
return int(round(x)), int(round(y))
end_x, end_y = clamp_to_circle(end_x, end_y, center_x, center_y, 20)
# 3. 加入轻微噪声,制造“不规则”曲线
noise = 3 # 最大偏移像素
mid_count = points - 2
mid_points: List[Tuple[int, int]] = []
for i in range(1, mid_count + 1):
t = i / (mid_count + 1)
# 线性插值 + 垂直方向噪声
x = center_x * (1 - t) + end_x * t
y = center_y * (1 - t) + end_y * t
perp_angle = angle + math.pi / 2 # 垂直方向
offset = random.uniform(-noise, noise)
x += offset * math.cos(perp_angle)
y += offset * math.sin(perp_angle)
x, y = clamp_to_circle(x, y, center_x, center_y, 20)
mid_points.append((int(round(x)), int(round(y))))
# 4. 构造完整轨迹
trajectory: List[Tuple[int, int]] = (
[(center_x, center_y)] + mid_points + [(end_x, end_y)]
)
# 5. 使用 facebook-wda 的 swipe 接口(逐段 swipe
# 由于总时长太短,我们一次性 swipe 到终点,但用多点轨迹模拟
# facebook-wda 支持 swipe(x1, y1, x2, y2, duration)
# 我们直接用起点 -> 终点duration 用总时长
print("开始微滑动")
session.swipe(center_x, center_y, end_x, end_y, duration_ms / 1000)
print("随机微滑动:", trajectory)