Skip to content

Commit

Permalink
修复[BUG](#298)
Browse files Browse the repository at this point in the history
修复[BUG](#290)
跳过网页端显示转码失败的课程
  • Loading branch information
Samueli924 committed Nov 16, 2023
1 parent b959150 commit 32bc7d8
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 55 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@
1. `git clone --depth=1 https://github.com/Samueli924/chaoxing` 项目至本地
2. `cd chaoxing`
3. `pip install -r requirements.txt`
4. (可选配置文件运行)复制config_template.ini文件为config.ini文件,修改文件内的账号密码内容, 执行 `python main.py -c config.ini`
5. (可选命令行运行)`python main.py -u 手机号 -p 密码 -l 课程ID1,课程ID2,课程ID3...(可选)`
4. (可选直接运行) `python main.py`
5. (可选配置文件运行)复制config_template.ini文件为config.ini文件,修改文件内的账号密码内容, 执行 `python main.py -c config.ini`
6. (可选命令行运行)`python main.py -u 手机号 -p 密码 -l 课程ID1,课程ID2,课程ID3...(可选)`

### 打包文件运行
1. 从最新[Releases](https://github.com/Samueli924/chaoxing/releases)中下载exe文件
2. (可选配置文件运行)下载config_template.ini文件保存为config.ini文件,修改文件内的账号密码内容, 执行 `./chaoxing.exe -c config.ini`
3. (可选命令行运行)`./chaoxing.exe -u "手机号" -p "密码" -l 课程ID1,课程ID2,课程ID3...(可选)`
2. (可选直接运行) 双击运行即可
3. (可选配置文件运行)下载config_template.ini文件保存为config.ini文件,修改文件内的账号密码内容, 执行 `./chaoxing.exe -c config.ini`
4. (可选命令行运行)`./chaoxing.exe -u "手机号" -p "密码" -l 课程ID1,课程ID2,课程ID3...(可选)`

## :heart: CONTRIBUTORS
### :one:感谢[huajijam](https://github.com/huajijam)对chaoxing项目的贡献! [PR #73](https://github.com/Samueli924/chaoxing/pull/73)
Expand Down
104 changes: 53 additions & 51 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,55 +30,57 @@ def init_config():
username, password, course_list, speed = init_config()
# 强行限制倍速最大为2倍速
speed = 2 if speed > 2 else speed
if username and password:
account = Account(username, password)
# 实例化超星API
chaoxing = Chaoxing(account=account)
# 检查当前登录状态,并检查账号密码
_login_state = chaoxing.login()
if not _login_state["status"]:
raise LoginError(_login_state["msg"])
# 获取所有的课程列表
all_course = chaoxing.get_course_list()
course_task = []
# 手动输入要学习的课程ID列表
if not course_list:
print("*"*10 + "课程列表" + "*"*10)
for course in all_course:
print(f"ID: {course['courseId']} 课程名: {course['title']}")
print("*" * 28)
try:
course_list = str(input("请输入想要学习的课程列表,以逗号分隔,例: 2151141,189191,198198\n")).split(",")
except:
raise FormatError("输入格式错误")
# 筛选需要学习的课程
if (not username) or (not password):
username = input("请输入你的手机号,按回车确认\n手机号:")
password = input("请输入你的密码,按回车确认\n密码:")
account = Account(username, password)
# 实例化超星API
chaoxing = Chaoxing(account=account)
# 检查当前登录状态,并检查账号密码
_login_state = chaoxing.login()
if not _login_state["status"]:
raise LoginError(_login_state["msg"])
# 获取所有的课程列表
all_course = chaoxing.get_course_list()
course_task = []
# 手动输入要学习的课程ID列表
if not course_list:
print("*"*10 + "课程列表" + "*"*10)
for course in all_course:
if course["courseId"] in course_list:
course_task.append(course)
if not course_task:
course_task = all_course
# 开始遍历要学习的课程列表
logger.info(f"课程列表过滤完毕,当前课程任务数量: {len(course_task)}")
for course in course_task:
# 获取当前课程的所有章节
point_list = chaoxing.get_course_point(course["courseId"], course["clazzId"], course["cpi"])
for point in point_list["points"]:
# 获取当前章节的所有任务点
jobs, job_info = chaoxing.get_job_list(course["clazzId"], course["courseId"], course["cpi"], point["id"])
# 可能存在章节无任何内容的情况
if not jobs:
continue
# 遍历所有任务点
for job in jobs:
# 视频任务
if job["type"] == "video":
logger.trace(f"识别到视频任务, 任务章节: {course['title']} 任务ID: {job['jobid']}")
chaoxing.study_video(course, job, job_info, _speed=speed)
# 文档任务
elif job["type"] == "document":
logger.trace(f"识别到文档任务, 任务章节: {course['title']} 任务ID: {job['jobid']}")
chaoxing.study_document(course, job)
# 测验任务
elif job["type"] == "workid":
logger.trace(f"识别到测验任务, 任务章节: {course['title']}")
pass
print(f"ID: {course['courseId']} 课程名: {course['title']}")
print("*" * 28)
try:
course_list = str(input("请输入想要学习的课程列表,以逗号分隔,例: 2151141,189191,198198\n")).split(",")
except:
raise FormatError("输入格式错误")
# 筛选需要学习的课程
for course in all_course:
if course["courseId"] in course_list:
course_task.append(course)
if not course_task:
course_task = all_course
# 开始遍历要学习的课程列表
logger.info(f"课程列表过滤完毕,当前课程任务数量: {len(course_task)}")
for course in course_task:
# 获取当前课程的所有章节
point_list = chaoxing.get_course_point(course["courseId"], course["clazzId"], course["cpi"])
for point in point_list["points"]:
# 获取当前章节的所有任务点
jobs, job_info = chaoxing.get_job_list(course["clazzId"], course["courseId"], course["cpi"], point["id"])
# 可能存在章节无任何内容的情况
if not jobs:
continue
# 遍历所有任务点
for job in jobs:
# 视频任务
if job["type"] == "video":
logger.trace(f"识别到视频任务, 任务章节: {course['title']} 任务ID: {job['jobid']}")
chaoxing.study_video(course, job, job_info, _speed=speed)
# 文档任务
elif job["type"] == "document":
logger.trace(f"识别到文档任务, 任务章节: {course['title']} 任务ID: {job['jobid']}")
chaoxing.study_document(course, job)
# 测验任务
elif job["type"] == "workid":
logger.trace(f"识别到测验任务, 任务章节: {course['title']}")
pass

0 comments on commit 32bc7d8

Please sign in to comment.