From d48afa485ec825067ccba93d3dac18569ecd264b Mon Sep 17 00:00:00 2001 From: chettoy Date: Sat, 28 May 2022 22:32:39 +0800 Subject: [PATCH] Update fix: Update login fix: Fix ETA progress docs: Update readme chore: Add requirements.txt --- README.md | 38 ++++++++++++++++++++++++-------------- fxxkstar.py | 26 ++++++++++++++++++++------ requirements.txt | 9 +++++++++ 3 files changed, 53 insertions(+), 20 deletions(-) create mode 100644 requirements.txt diff --git a/README.md b/README.md index 61e73d9..feb7f5b 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ API基于网页端新版页面协议和安卓端超星SDK协议,目前实现 -*注:FxxkStar只含有测试版客户端功能,另有基于专有API的学习版客户端* +*注:FxxkStar含有测试版客户端功能* | | 测试版 | 学习版 | | -------- | ---------------------------------------------- | ------------------------------------------------------------ | @@ -66,7 +66,7 @@ API基于网页端新版页面协议和安卓端超星SDK协议,目前实现 ## Installation -You can download FxxkStar by cloning the [Git](https://github.com/chettoy/FxxkStar) repository: +You can download FxxkStar by cloning [the Git repository](https://github.com/chettoy/FxxkStar): ```shell git clone --depth 1 https://github.com/chettoy/FxxkStar.git FxxkStar-dev @@ -74,28 +74,38 @@ git clone --depth 1 https://github.com/chettoy/FxxkStar.git FxxkStar-dev FxxkStar works with [Python](https://www.python.org/download/) version 3.10 or above on any platform. -**requirements** -- `requests`, `brotli`, `lxml`, `beautifulsoup4`, `zstandard`, `fonttools` -- `pytesseract` (Only required when using OCR) + +You can install the requirements (using the TUNA mirror) with the following command via `pip`. + +```shell +pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt +``` + +Optional: Additional steps are required to install `pytesseract` data, check the [pytesseract package page](https://pypi.python.org/pypi/pytesseract) for more information. (Required only when OCR is enabled) + + + +**ArchLinux** + +install the requirements with: + +```shell +sudo pacman -S python-beautifulsoup4 python-brotli python-cryptography python-fonttools \ + python-lxml python-pycryptodome python-requests python-zstandard +``` -You can install requirements with the following command (using TUNA mirror): +## Usage ```shell -pip install -i https://pypi.tuna.tsinghua.edu.cn/simple requests -pip install -i https://pypi.tuna.tsinghua.edu.cn/simple brotli -pip install -i https://pypi.tuna.tsinghua.edu.cn/simple lxml -pip install -i https://pypi.tuna.tsinghua.edu.cn/simple beautifulsoup4 -pip install -i https://pypi.tuna.tsinghua.edu.cn/simple zstandard -pip install -i https://pypi.tuna.tsinghua.edu.cn/simple fonttools -pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pytesseract +python fxxkstar.py ``` +For **Windows** users, run with *Windows Terminal* to get better experience. -Note: Additional steps are required to install `pytesseract`, check the [pytesseract package page](https://pypi.python.org/pypi/pytesseract) for more information. ## Contributing diff --git a/fxxkstar.py b/fxxkstar.py index f0e0c97..31784c6 100644 --- a/fxxkstar.py +++ b/fxxkstar.py @@ -24,6 +24,8 @@ from typing import List from collections import Counter from fontTools.ttLib import TTFont +from Crypto.Cipher import DES +from cryptography.hazmat.primitives import padding VERSION_NAME = "FxxkStar 0.9" @@ -290,20 +292,32 @@ def check_login(self) -> bool: return False return True + @staticmethod + def encrypt_by_DES(message: str, key: str) -> str: + key_bytes = key.encode('utf-8') + des = DES.new(key_bytes, DES.MODE_ECB) + + data = message.encode('utf-8') + padder = padding.PKCS7(64).padder() + padded_data = padder.update(data) + padder.finalize() + + ciphertext = des.encrypt(padded_data) + return ciphertext.hex() + def sign_in(self, uname: str, password: str): url = "https://passport2.chaoxing.com/fanyalogin" - data = "fid=314&uname={0}&password={1}&refer=http%3A%2F%2Fi.chaoxing.com&t=true&forbidotherlogin=0".format( - uname, base64.b64encode(password.encode("utf-8")).decode("utf-8")) + data = "fid=-1&uname={0}&password={1}&refer=https%3A%2F%2Fi.chaoxing.com&t=true&forbidotherlogin=0&validate=".format( + uname, self.encrypt_by_DES(password, "u2oh6Vu^")) headers = self.agent.build_headers_based_on({ 'Accept': 'application/json, text/javascript, */*; q=0.01', 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', - 'Cookie': 'fanyamoocs=11401F839C536D9E; fid=314; isfyportal=1; ptrmooc=t', - 'Host': 'passport2.chaoxing.com', + 'Cookie': 'source=""', 'Origin': 'https://passport2.chaoxing.com', - 'Referer': 'https://passport2.chaoxing.com/login?loginType=4&fid=314&newversion=true&refer=http://i.mooc.chaoxing.com', + 'Referer': 'https://passport2.chaoxing.com/login?fid=&newversion=true&refer=https%3A%2F%2Fi.chaoxing.com', }, self.agent.headers_additional_xhr) sign_in_rsp = requests.post(url=url, data=data, headers=headers) sign_in_json = sign_in_rsp.json() + if sign_in_json['status']: self.uid = sign_in_rsp.cookies['_uid'] for item in sign_in_rsp.cookies: @@ -2752,7 +2766,7 @@ def sync_video_progress(self, thread_count=3) -> None: def print_eta(i: int, total: int) -> None: if i > total: - i = total + total = i print() print(f"{G_STRINGS['tag_total_progress']}: {i}/{total}") # [####------] 100.0% diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..c341be0 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,9 @@ +beautifulsoup4==4.10.0 +Brotli==1.0.9 +cryptography==37.0.0 +fonttools==4.33.3 +lxml==4.8.0 +pycryptodome==3.14.1 +requests==2.27.1 +urllib3==1.26.9 +zstandard==0.17.0