Skip to content

Commit

Permalink
Revert "Fix: Solve speed arg not working bug"
Browse files Browse the repository at this point in the history
This reverts commit 1d344c6.
  • Loading branch information
Samueli924 committed Nov 13, 2024
1 parent 1d344c6 commit 0a9b938
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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']}")

Expand Down
6 changes: 3 additions & 3 deletions api/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, " ")
Expand Down
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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
)

Expand Down

0 comments on commit 0a9b938

Please sign in to comment.