diff --git a/api/base.py b/api/base.py index 214d253a..c9d2aa73 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 not is_finished: + while True: # 使用 True 替代 1,更符合 Python 规范 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 + wait_time >= int(duration): - wait_time = int(duration) - playing_time + if playing_time + int(speed * wait_time) >= int(duration): + # 计算剩余时间,确保不会超过总时长 + wait_time = max(1, int((duration - playing_time) / speed)) is_finished = True # 显示进度 show_progress(job['name'], playing_time, wait_time, duration, speed) - playing_time += wait_time - + playing_time += int(speed * wait_time) # 根据播放速度调整增加的时间 print("\r", end="", flush=True) logger.info(f"任务完成: {job['name']}") diff --git a/api/process.py b/api/process.py index 7e5d9cba..dbe920c2 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 2630ddf9..e4868505 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,最大2)") + parser.add_argument("-s", "--speed", type=float, default=1.0, help="视频播放倍速(默认1)") 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=min(2.0, max(1.0, args.speed)), + speed=max(1.0, args.speed), tiku_config=None )