迁移虎牙验证码核心逻辑
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
"""虎牙滑块轨迹生成工具。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import random
|
||||
import time
|
||||
from collections.abc import Iterable
|
||||
|
||||
|
||||
def ease_out_expo(sep: float) -> float:
|
||||
"""缓出曲线,让轨迹更接近人工拖动。"""
|
||||
if sep == 1:
|
||||
return 1
|
||||
return 1 - pow(2, -10 * sep)
|
||||
|
||||
|
||||
def generate_slide_track(distance: int) -> list[list[int]]:
|
||||
"""生成虎牙滑块验证所需 travel 轨迹。"""
|
||||
if not isinstance(distance, int) or distance < 0:
|
||||
raise ValueError(f"distance 必须是大于等于 0 的整数: {distance!r}")
|
||||
|
||||
distance = distance + random.randint(10, 40)
|
||||
current_time = int(time.time() * 1000) - random.randint(1500, 2000)
|
||||
slide_x = random.randint(56, 63)
|
||||
slide_y = random.randint(210, 213)
|
||||
track = [[slide_x, slide_y, current_time]]
|
||||
|
||||
count = random.randint(40, 60)
|
||||
last_x = 0
|
||||
for index in range(count):
|
||||
x = round(ease_out_expo(index / count) * distance)
|
||||
current_time += random.randint(10, 20)
|
||||
if x == last_x:
|
||||
continue
|
||||
y = random.randint(-1, 1)
|
||||
track.append([x + slide_x, y + slide_y, current_time])
|
||||
last_x = x
|
||||
|
||||
track.append(track[-1])
|
||||
return track
|
||||
|
||||
|
||||
def format_track(points: Iterable[Iterable[int]]) -> str:
|
||||
"""把轨迹点格式化成虎牙 actData.travel 字符串。"""
|
||||
return ";".join(f"{x},{y},{t}" for x, y, t in points)
|
||||
Reference in New Issue
Block a user