Files
douyin_guaji-main/douyin_swipe_ops.py
T
Your Name e68f1dd3de feat: Refactor coverage management and enhance logging functionality
- Removed the `.coverage` file from the repository to streamline coverage management.
- Updated `.gitignore` to exclude coverage-related files and directories, ensuring a cleaner project structure.
- Introduced new scripts for checking GPU availability and detecting GUI parameter conflicts, enhancing the overall functionality of the application.
- Improved logging mechanisms across various modules to support better debugging and monitoring.
- Added comprehensive documentation for new features and updated existing markdown files for clarity.
2025-12-23 02:38:51 +08:00

107 lines
3.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from __future__ import annotations
from typing import Any
def swipe_up_switch_live(analyser: Any) -> None:
"""上滑切换到下一个直播间(基础版封装)。
采用 1080x2400 基准坐标,在屏幕中下部向上滑一段距离。
"""
try:
rx = int(getattr(analyser, "resolution_ratio_x", 1080) or 1080)
except Exception:
rx = 1080
try:
ry = int(getattr(analyser, "resolution_ratio_y", 2400) or 2400)
except Exception:
ry = 2400
device_id = getattr(analyser, "device_id", "")
# 基准坐标(1080x2400):从中下部往上滑
start_x_base = 540
start_y_base = 1700
end_x_base = 540
end_y_base = 700
start_x = start_x_base * rx // 1080
end_x = end_x_base * rx // 1080
start_y = start_y_base * ry // 2400
end_y = end_y_base * ry // 2400
try:
analyser._log_kv(
"滑动",
"swipe_up_switch_live:上滑切换直播间",
start_x=start_x_base,
start_y=start_y_base,
end_x=end_x_base,
end_y=end_y_base,
)
except Exception:
pass
# 优先调用底层 swipe,失败则静默忽略(不影响主流程)
try:
analyser.operation.swipe(device_id, start_x, start_y, end_x, end_y, 300)
except Exception:
try:
# 如果 analyser 自身提供 swipe 封装,则退回到该封装
analyser.swipe(start_x_base, start_y_base, end_x_base, end_y_base, 300)
except Exception:
pass
def swipe_down_back_live(analyser: Any) -> None:
"""下滑回退到上一个直播间(基础版封装)。
在直播间内,向下滑动(从上往下)可以回退到上一个直播间。
采用 1080x2400 基准坐标,在屏幕中上部向下滑一段距离。
注意:这是与 swipe_up_switch_live 相反的方向。
"""
try:
rx = int(getattr(analyser, "resolution_ratio_x", 1080) or 1080)
except Exception:
rx = 1080
try:
ry = int(getattr(analyser, "resolution_ratio_y", 2400) or 2400)
except Exception:
ry = 2400
device_id = getattr(analyser, "device_id", "")
# 基准坐标(1080x2400):从上方往下滑(与上滑切换相反方向)
# 回退操作:从上往下滑动(start_y < end_y)
start_x_base = 540
start_y_base = 800 # 上方起始位置
end_x_base = 540
end_y_base = 1600 # 下方结束位置
start_x = start_x_base * rx // 1080
end_x = end_x_base * rx // 1080
start_y = start_y_base * ry // 2400
end_y = end_y_base * ry // 2400
try:
analyser._log_kv(
"滑动",
"swipe_down_back_live:下滑回退到上一个直播间",
start_x=start_x_base,
start_y=start_y_base,
end_x=end_x_base,
end_y=end_y_base,
)
except Exception:
pass
# 优先调用底层 swipe,失败则静默忽略(不影响主流程)
try:
analyser.operation.swipe(device_id, start_x, start_y, end_x, end_y, 300)
except Exception:
try:
# 如果 analyser 自身提供 swipe 封装,则退回到该封装
analyser.swipe(start_x_base, start_y_base, end_x_base, end_y_base, 300)
except Exception:
pass