's'
This commit is contained in:
@@ -12,7 +12,7 @@ language(zh_cn/en) = zh_cn
|
||||
是否使用代理ip(是/否) = 否
|
||||
代理地址 =
|
||||
同一时间访问网络的线程数 = 3
|
||||
循环时间(秒) = 300
|
||||
循环时间(秒) = 120
|
||||
排队读取网址时间(秒) = 0
|
||||
是否显示循环秒数 = 否
|
||||
是否显示直播源地址 = 是
|
||||
|
||||
85
main.py
85
main.py
@@ -90,7 +90,92 @@ def signal_handler(_signal, _frame):
|
||||
signal.signal(signal.SIGTERM, signal_handler)
|
||||
|
||||
|
||||
|
||||
import shutil
|
||||
|
||||
|
||||
# 全局变量(只初始化一次)
|
||||
_last_lines_count = 0
|
||||
|
||||
def _clear_lines(n: int):
|
||||
"""向上删除 n 行(不闪烁)"""
|
||||
if n <= 0:
|
||||
return
|
||||
print(f"\033[{n}A\033[K", end="", flush=True) # 上移 + 清行
|
||||
|
||||
def display_info() -> None:
|
||||
global start_display_time, _last_lines_count
|
||||
time.sleep(3) # 启动延迟
|
||||
|
||||
while True:
|
||||
try:
|
||||
lines = []
|
||||
now_str = datetime.datetime.now().strftime("%H:%M:%S")
|
||||
|
||||
# 第一行:核心状态
|
||||
lines.append(
|
||||
f"监测 {monitoring} | 并发 {max_request} | "
|
||||
f"代理 {'开' if use_proxy else '关'} | "
|
||||
f"分段 {'开' if split_video_by_time else '关'}{f':{split_time}s' if split_video_by_time else ''} | "
|
||||
f"时间文件 {'开' if create_time_file else '关'} | "
|
||||
f"质量 {video_record_quality} | 格式 {video_save_type} | "
|
||||
f"错误 {error_count} | {now_str}"
|
||||
)
|
||||
|
||||
# 第二行:录制中的直播
|
||||
if recording:
|
||||
no_repeat = list(set(recording))
|
||||
recording_str = f"正在录制 {len(no_repeat)} 个: "
|
||||
details = []
|
||||
now_dt = datetime.datetime.now()
|
||||
for name in no_repeat[:10]: # 最多显示10个,防止爆屏
|
||||
if name not in recording_time_list:
|
||||
continue
|
||||
start_time, quality = recording_time_list[name]
|
||||
duration = str(now_dt - start_time).split('.')[0]
|
||||
details.append(f"{name.split()[-1]}[{quality} {duration}]")
|
||||
recording_str += " | ".join(details)
|
||||
if len(no_repeat) > 10:
|
||||
recording_str += f" ... (+{len(no_repeat)-10})"
|
||||
lines.append(recording_str)
|
||||
else:
|
||||
if monitoring == 0:
|
||||
lines.append("没有正在监测的直播")
|
||||
else:
|
||||
lines.append(f"无录制任务 | 循环间隔 {delay_default}s")
|
||||
|
||||
# 动态清屏 + 重绘(不闪烁!)
|
||||
terminal_width, _ = shutil.get_terminal_size(fallback=(120, 24))
|
||||
display_lines = []
|
||||
for line in lines:
|
||||
if len(line) > terminal_width - 5:
|
||||
line = line[:terminal_width-8] + "..."
|
||||
display_lines.append(line)
|
||||
|
||||
# 删除旧内容 + 打印新内容
|
||||
if _last_lines_count > len(display_lines):
|
||||
_clear_lines(_last_lines_count - 1)
|
||||
print("\r" + display_lines[0])
|
||||
for line in display_lines[1:]:
|
||||
print(line)
|
||||
else:
|
||||
print("\r" + display_lines[0], end="")
|
||||
for line in display_lines[1:]:
|
||||
print(f"\n{line}", end="")
|
||||
|
||||
_last_lines_count = len(display_lines)
|
||||
print(flush=True) # 强制刷新
|
||||
|
||||
time.sleep(5)
|
||||
|
||||
except Exception as e:
|
||||
# 避免崩溃后疯狂打印错误
|
||||
try:
|
||||
print(f"\n[display_info 错误] {e}")
|
||||
except:
|
||||
pass
|
||||
time.sleep(10) # 出错了也别刷屏
|
||||
def display_info2() -> None:
|
||||
global start_display_time
|
||||
time.sleep(5)
|
||||
while True:
|
||||
|
||||
Reference in New Issue
Block a user