Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复代码样式和任务完成时回显 #349

Merged
merged 4 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
<img src="https://img.shields.io/github/v/release/Samueli924/chaoxing?display_name=tag&sort=semver" alt="version" />
</a>
</p>
:muscle: 本项目的最终目的是通过开源消灭所谓的付费刷课平台,希望有能力的朋友都可以为这个项目提交代码,支持本项目的良性发展
:muscle: 本项目的最终目的是通过开源消灭所谓的付费刷课平台,希望有能力的朋友都可以为这个项目提交代码,支持本项目的良性发展

:star: 觉得有帮助的朋友可以给个Star

## :point_up: 更新通知
## :point_up: 更新通知
20231114更新通知: 3.0大版本更新,修复403报错,优化代码结构

## :books: 使用方法
Expand All @@ -28,21 +28,21 @@
2. `cd chaoxing`
3. `pip install -r requirements.txt`
4. (可选直接运行) `python main.py`
5. (可选配置文件运行)复制config_template.ini文件为config.ini文件,修改文件内的账号密码内容, 执行 `python main.py -c config.ini`
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. (可选直接运行) 双击运行即可
3. (可选配置文件运行)下载config_template.ini文件保存为config.ini文件,修改文件内的账号密码内容, 执行 `./chaoxing.exe -c config.ini`
3. (可选配置文件运行) 下载config_template.ini文件保存为config.ini文件,修改文件内的账号密码内容, 执行 `./chaoxing.exe -c config.ini`
4. (可选命令行运行)`./chaoxing.exe -u "手机号" -p "密码" -l 课程ID1,课程ID2,课程ID3...(可选)`

## :heart: CONTRIBUTORS
## :heart: CONTRIBUTORS
<a href="https://github.com/Samueli924/chaoxing/graphs/contributors">
<img src="https://contrib.rocks/image?repo=Samueli924/chaoxing" />
</a>

## :warning: 免责声明
- 本代码遵循 [GPL-3.0 License](https://github.com/Samueli924/chaoxing/blob/main/LICENSE)协议,允许**开源/免费使用和引用/修改/衍生代码的开源/免费使用**,不允许**修改和衍生的代码作为闭源的商业软件发布和销售**,禁止**使用本代码盈利**,以此代码为基础的程序**必须**同样遵守[GPL-3.0 License](https://github.com/Samueli924/chaoxing/blob/main/LICENSE)协议
- 本代码仅用于**学习讨论**,禁止**用于盈利**
- 他人或组织使用本代码进行的任何**违法行为**与本人无关
## :warning: 免责声明
- 本代码遵循 [GPL-3.0 License](https://github.com/Samueli924/chaoxing/blob/main/LICENSE) 协议,允许**开源/免费使用和引用/修改/衍生代码的开源/免费使用**,不允许**修改和衍生的代码作为闭源的商业软件发布和销售**,禁止**使用本代码盈利**,以此代码为基础的程序**必须**同样遵守 [GPL-3.0 License](https://github.com/Samueli924/chaoxing/blob/main/LICENSE) 协议
- 本代码仅用于**学习讨论**,禁止**用于盈利**
- 他人或组织使用本代码进行的任何**违法行为**与本人无关
22 changes: 9 additions & 13 deletions api/base.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# -*- coding: utf-8 -*-
import re
import requests
import time
import random
import requests
from hashlib import md5
from requests.adapters import HTTPAdapter

from api import formatted_output
from api.cipher import AESCipher
from api.logger import logger
from api.cookies import save_cookies, use_cookies
Expand Down Expand Up @@ -132,8 +131,6 @@ def get_job_list(self, _clazzid, _courseid, _cpi, _knowledgeid):
_job_list, _job_info = decode_course_card(_resp.text)
if _job_list and len(_job_list) != 0:
break
else:
continue
# logger.trace(f"原始任务点列表内容:\n{_resp.text}")
logger.info("章节任务点读取成功...")
return _job_list, _job_info
Expand Down Expand Up @@ -170,9 +167,9 @@ def video_progress_log(self, _session, _course, _job, _job_info, _dtoken, _durat
resp = _session.get(_url)
if resp.status_code == 200:
_success = True
break # 如果返回为200正常,则跳出循环
break # 如果返回为200正常,则跳出循环
elif resp.status_code == 403:
continue # 如果出现403无权限报错,则继续尝试不同的rt参数
continue # 如果出现403无权限报错,则继续尝试不同的rt参数
if _success:
return resp.json()
else:
Expand All @@ -196,14 +193,12 @@ def study_video(self, _course, _job, _job_info, _speed: float = 1, _type: str =
_isPassed = False
_isFinished = False
_playingTime = 0
logger.info(f"开始任务:{_job['name']}, 总时长: {_duration}秒")
logger.info(f"开始任务: {_job['name']}, 总时长: {_duration}秒")
while not _isFinished:
if _isFinished:
_playingTime = _duration
_isPassed = self.video_progress_log(_session, _course, _job, _job_info, _dtoken, _duration, _playingTime, _type)
if _isPassed and _isPassed["isPassed"]:
break
elif not _isPassed:
if not _isPassed or (_isPassed and _isPassed["isPassed"]):
break
_wait_time = get_random_seconds()
if _playingTime + _wait_time >= int(_duration):
Expand All @@ -212,9 +207,10 @@ def study_video(self, _course, _job, _job_info, _speed: float = 1, _type: str =
# 播放进度条
show_progress(_job['name'], _playingTime, _wait_time, _duration, _speed)
_playingTime += _wait_time
logger.info(f"\n任务完成:{_job['name']}")
print("\r", end="", flush=True)
logger.info(f"任务完成: {_job['name']}")

def study_document(self, _course, _job):
_session = init_session()
_url = f"https://mooc1.chaoxing.com/ananas/job/document?jobid={_job['jobid']}&knowledgeid={re.findall('nodeId_(.*?)-', _job['otherinfo'])[0]}&courseid={_course['courseId']}&clazzid={_course['clazzId']}&jtoken={_job['jtoken']}&_dc={get_timestamp()}"
_resp = _session.get(_url)
_url = f"https://mooc1.chaoxing.com/ananas/job/document?jobid={_job['jobid']}&knowledgeid={re.findall(r'nodeId_(.*?)-', _job['otherinfo'])[0]}&courseid={_course['courseId']}&clazzid={_course['clazzId']}&jtoken={_job['jtoken']}&_dc={get_timestamp()}"
_resp = _session.get(_url)
2 changes: 0 additions & 2 deletions api/cipher.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# -*- coding:utf-8 -*-
# -*- coding: utf-8 -*-
import base64

import pyaes

from api.config import GlobalConst as gc


Expand Down
1 change: 0 additions & 1 deletion api/cookies.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
import os.path
import pickle

from api.config import GlobalConst as gc


Expand Down
16 changes: 8 additions & 8 deletions api/decode.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
import re
import json
from bs4 import BeautifulSoup
import re
from api.logger import logger


Expand All @@ -19,7 +19,7 @@ def decode_course_list(_text):

_course_detail["clazzId"] = course.select_one("input.clazzId").attrs["value"]
_course_detail["courseId"] = course.select_one("input.courseId").attrs["value"]
_course_detail["cpi"] = re.findall("cpi=(.*?)&", course.select_one("a").attrs["href"])[0]
_course_detail["cpi"] = re.findall(r"cpi=(.*?)&", course.select_one("a").attrs["href"])[0]
_course_detail["title"] = course.select_one("span.course-name").attrs["title"]
if course.select_one("p.margint10") is None:
_course_detail["desc"] = ''
Expand Down Expand Up @@ -52,7 +52,7 @@ def decode_course_point(_text):
if (not "id" in _point.attrs) or (not "title" in _point.attrs):
continue
_point_detail = {}
_point_detail["id"] = re.findall("^cur(\d{1,20})$", _point.attrs["id"])[0]
_point_detail["id"] = re.findall(r"^cur(\d{1,20})$", _point.attrs["id"])[0]
_point_detail["title"] = str(_point.select_one("span.catalog_sbar").text) + " " + str(_point.attrs["title"])
_point_detail["jobCount"] = 0
if _point.select_one("input.knowledgeJobCount"):
Expand All @@ -64,7 +64,7 @@ def decode_course_point(_text):

def decode_course_card(_text: str):
logger.trace("开始解码任务点列表...")
_temp = re.findall("mArg=\{(.*?)};", _text.replace(" ", ""))
_temp = re.findall(r"mArg=\{(.*?)\};", _text.replace(" ", ""))
if _temp:
_temp = _temp[0]
else:
Expand All @@ -85,10 +85,10 @@ def decode_course_card(_text: str):
_job_list = []
for _card in _cards:
# 已经通过的任务
if "isPassed" in _card and _card["isPassed"] == True:
if "isPassed" in _card and _card["isPassed"] is True:
continue
# 不属于任务点的任务
if "job" not in _card or _card["job"] == False:
if "job" not in _card or _card["job"] is False:
continue
# 视频任务
if _card["type"] == "video":
Expand All @@ -99,7 +99,7 @@ def decode_course_card(_text: str):
_job["otherinfo"] = _card["otherInfo"]
try:
_job["mid"] = _card["mid"]
except KeyError as e:
except KeyError:
logger.warning("出现转码失败视频,已跳过...")
continue
_job["objectid"] = _card["objectId"]
Expand All @@ -121,4 +121,4 @@ def decode_course_card(_text: str):
continue
if _card["type"] == "workid":
continue
return _job_list, _job_info
return _job_list, _job_info
1 change: 1 addition & 0 deletions api/logger.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from loguru import logger

logger.add("chaoxing.log", rotation="10 MB", level="TRACE")
4 changes: 2 additions & 2 deletions api/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ def sec2time(sec):
return ret


def show_progress(name, start: int, span: int, total: int, _speed):
def show_progress(name, 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)
percent = int(current / total * 100)
length = int(percent * 40 // 100)
progress = ("#" * length).ljust(40, " ")
# remain = (total - current)
print("\r" + f"当前任务: {name} |{progress}| {percent}% {sec2time(current)}/{sec2time(total)} ", end="", flush=True)
print(f"\r当前任务: {name} |{progress}| {percent}% {sec2time(current)}/{sec2time(total)}", end="", flush=True)
time.sleep(gc.THRESHOLD)
11 changes: 5 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ def init_config():
course_task = []
# 手动输入要学习的课程ID列表
if not course_list:
print("*"*10 + "课程列表" + "*"*10)
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("输入格式错误")
course_list = input("请输入想要学习的课程列表,以逗号分隔,例: 2151141,189191,198198\n").split(",")
except Exception as e:
raise FormatError("输入格式错误") from e
# 筛选需要学习的课程
for course in all_course:
if course["courseId"] in course_list:
Expand Down Expand Up @@ -94,5 +94,4 @@ def init_config():
chaoxing.study_document(course, job)
# 测验任务
elif job["type"] == "workid":
logger.trace(f"识别到测验任务, 任务章节: {course['title']}")
pass
logger.trace(f"识别到测验任务, 任务章节: {course['title']}")
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ pyaes
beautifulsoup4
lxml
argparse
loguru
loguru
celery
flask