Skip to content

Commit 9689564

Browse files
committed
[FEAT] 兼容更多类型课程
1 parent 0455b2a commit 9689564

2 files changed

Lines changed: 21 additions & 16 deletions

File tree

AIMoocMain/main.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,53 +137,55 @@ def handle_resource(
137137

138138
# 跳过作业
139139
if file_type == "作业":
140-
self.logging.info(f"{prefix} 跳过作业")
140+
self.logging.info(f"{prefix} 跳过作业")
141141
return
142142

143143
# 跳过考试
144144
if file_type == "考试":
145-
self.logging.info(f"{prefix} 跳过考试")
145+
self.logging.info(f"{prefix} 跳过考试")
146146
return
147147

148148
# 跳过测验
149149
if file_type == "测验":
150-
self.logging.info(f"{prefix} 跳过测验")
150+
self.logging.info(f"{prefix} 跳过测验")
151151
return
152152

153153
# 已完成的课程不再处理
154154
if source_id in self.study_record_list:
155-
self.logging.info(f"{prefix} 跳过已完成的课程: {resource_name}")
155+
self.logging.info(f"{prefix} 跳过已完成的课程: {resource_name}")
156156
return
157157

158158
try:
159159
# 默认学习总数
160160
total_num = random.randint(1, 10)
161-
course_content = json.loads(node.get("fileUrl"))
162-
url_short = course_content.get("url")
161+
course_content = node.get("fileUrl", "")
162+
if course_content and course_content.strip() != "":
163+
course_content = json.loads(course_content)
164+
url_short = course_content.get("url")
163165
# mp3 时长接口无法查询,本地获取
164166
if file_type == "audio":
165167
mp3_duration = get_mp3_duration(course_content.get("ossOriUrl"))
166168
total_num = int(mp3_duration)
167-
elif file_type == "zip":
169+
elif file_type == "ppt":
168170
total_num = random.randint(1, 10)
169171
elif file_type == "img":
170172
total_num = random.randint(1, 10)
173+
elif file_type == "图文":
174+
total_num = random.randint(1, 10)
171175
elif url_short:
172-
file_status = self.client.upload_file_status(url_short)
173-
file_status_args = file_status.get("args")
174176
# 视频类型
175-
file_status_args_duration = file_status_args.get("duration")
177+
file_status_args_duration = course_content.get("duration")
176178
# 文件类型
177-
file_status_args_has_txt_file = file_status_args.get("has_txt_file")
179+
file_status_args_has_txt_file = course_content.get("has_txt_file")
178180
if file_status_args_duration:
179181
total_num = parse_duration(file_status_args_duration)
180182
elif file_status_args_has_txt_file:
181-
total_num = file_status_args.get("page_count")
183+
total_num = course_content.get("page_count")
182184

183185
course_info_id = node.get("courseInfoId")
184186
study_time = total_num
185187

186-
wait_time = random.randint(1, 3)
188+
wait_time = random.randint(1, 2)
187189

188190
self.logging.info(
189191
f"{prefix} ⏳ 学习数: {total_num},等待 {wait_time} 秒..."

base/util.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,12 @@ def parse_duration(duration: str) -> int:
6161
:param duration: 时间字符串,例如 '00:00:20.1670000' 或 '00:00:31'
6262
:return: 对应的总秒数(int)
6363
"""
64-
h, m, s = duration.split(":") # 拆分时、分、秒
65-
s = float(s) # 处理可能的毫秒部分
66-
return int(float(h) * 3600 + float(m) * 60 + s) # 转换为整数秒
64+
if ':' in str(duration):
65+
h, m, s = duration.split(":") # 拆分时、分、秒
66+
s = float(s) # 处理可能的毫秒部分
67+
return int(float(h) * 3600 + float(m) * 60 + s) # 转换为整数秒
68+
else:
69+
return int(duration)
6770

6871

6972
def get_mp3_duration(mp3_url: str) -> float:

0 commit comments

Comments
 (0)