From 0a9b938cdb854a458e6d6d6b1f7c05b454d1c082 Mon Sep 17 00:00:00 2001 From: Samueli924 <454867105@qq.com> Date: Wed, 13 Nov 2024 21:01:09 +0800 Subject: [PATCH] Revert "Fix: Solve speed arg not working bug" This reverts commit 1d344c6eac927c6566aba7b31f128b6047ef57d6. --- api/base.py | 10 +++++----- api/process.py | 6 +++--- main.py | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/api/base.py b/api/base.py index c9d2aa73..214d253a 100644 --- a/api/base.py +++ b/api/base.py @@ -335,7 +335,7 @@ def study_video(self, course: Dict, job: Dict, job_info: Dict, logger.info(f"开始任务: {job['name']}, 总时长: {duration}秒") # 循环提交播放进度 - while True: # 使用 True 替代 1,更符合 Python 规范 + while not is_finished: if is_finished: playing_time = duration @@ -349,14 +349,14 @@ def study_video(self, course: Dict, job: Dict, job_info: Dict, # 计算等待时间 wait_time = get_random_seconds() - if playing_time + int(speed * wait_time) >= int(duration): - # 计算剩余时间,确保不会超过总时长 - wait_time = max(1, int((duration - playing_time) / speed)) + if playing_time + wait_time >= int(duration): + wait_time = int(duration) - playing_time is_finished = True # 显示进度 show_progress(job['name'], playing_time, wait_time, duration, speed) - playing_time += int(speed * wait_time) # 根据播放速度调整增加的时间 + playing_time += wait_time + print("\r", end="", flush=True) logger.info(f"任务完成: {job['name']}") diff --git a/api/process.py b/api/process.py index dbe920c2..7e5d9cba 100644 --- a/api/process.py +++ b/api/process.py @@ -12,10 +12,10 @@ def sec2time(sec: int): return '--:--' -def show_progress(name: str, start: int, span: int, total: int, speed: float): +def show_progress(name: str, start: int, span: int, total: int, _speed: float): start_time = time.time() - while int(time.time() - start_time) < int(span / speed): - current = start + int((time.time() - start_time) * speed) + while int(time.time() - start_time) < int(span / _speed): + current = start + int((time.time() - start_time) * _speed) percent = int(current / total * 100) length = int(percent * 40 // 100) progress = ("#" * length).ljust(40, " ") diff --git a/main.py b/main.py index e4868505..2630ddf9 100644 --- a/main.py +++ b/main.py @@ -126,7 +126,7 @@ def init_config() -> Config: parser.add_argument("-u", "--username", type=str, help="手机号账号") parser.add_argument("-p", "--password", type=str, help="登录密码") parser.add_argument("-l", "--list", type=str, help="要学习的课程ID列表") - parser.add_argument("-s", "--speed", type=float, default=1.0, help="视频播放倍速(默认1)") + parser.add_argument("-s", "--speed", type=float, default=1.0, help="视频播放倍速(默认1,最大2)") args = parser.parse_args() @@ -137,7 +137,7 @@ def init_config() -> Config: username=args.username, password=args.password, course_list=args.list.split(",") if args.list else None, - speed=max(1.0, args.speed), + speed=min(2.0, max(1.0, args.speed)), tiku_config=None )