-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
174 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,5 @@ whisper_models/ | |
release_*/ | ||
*.json | ||
.idea | ||
.DS_Store | ||
.DS_Store | ||
auth.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,14 +16,23 @@ | |
} | ||
|
||
|
||
@utils.print_help | ||
def main(): | ||
if len(sys.argv) == 1: | ||
courseID = input("输 入 课 程 ID: ") | ||
else: | ||
courseID = sys.argv[1] | ||
|
||
if not utils.read_auth() or not utils.test_auth(courseID=courseID): | ||
auth = input("。".join(utils.auth_prompt())) | ||
utils.write_auth(auth) | ||
if not utils.test_auth(courseID=courseID): | ||
print("身份验证失败") | ||
sys.exit() | ||
videoList, courseName, professor = utils.get_course_info(courseID=courseID) | ||
|
||
print(f"课 程 名: {courseName}") | ||
|
||
for i, c in enumerate(videoList): | ||
print(f"[{i}]: ", c["title"]) | ||
|
||
|
@@ -59,16 +68,4 @@ def main(): | |
|
||
|
||
if __name__ == "__main__": | ||
try: | ||
main() | ||
# cProfile.run('main()', 'output/profile.txt') | ||
except Exception as e: | ||
print(e) | ||
print( | ||
"If the problem is still not solved, you can report an issue in https://github.com/AuYang261/BIT_yanhe_download/issues." | ||
) | ||
print("Or contact with the author [email protected]. Thanks for your report!") | ||
print( | ||
"如果问题仍未解决,您可以在https://github.com/AuYang261/BIT_yanhe_download/issues 中报告问题。" | ||
) | ||
print("或者联系作者[email protected]。感谢您的报告!") | ||
main() |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,17 +4,33 @@ | |
import m3u8dl | ||
import time | ||
from hashlib import md5 | ||
import os | ||
|
||
|
||
headers = { | ||
"Origin": "https://www.yanhekt.cn", | ||
"Referer": "https://www.yanhekt.cn/", | ||
"xdomain-client": "web_user", | ||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.26", | ||
"Xdomain-Client": "web_user", | ||
"Xclient-Signature": "e6e3bf5851b0e4af888cb4bc1938c568", | ||
"Xclient-Version": "v1", | ||
"Xclient-Timestamp": str(int(time.time())), | ||
"Authorization": "", | ||
} | ||
magic = "1tJrMwNq3h0yLgx86Rued2J1tFc" | ||
|
||
|
||
def auth_prompt(code=True): | ||
return [ | ||
"请先在浏览器登陆延河课堂", | ||
"并在延河课堂的地址栏输入 javascript:alert(JSON.parse(localStorage.auth).token)", | ||
'注意粘贴时浏览器会自动去掉"javascript:",需要手动补上', | ||
"或者按F12打开控制台粘贴这段代码", | ||
"然后将弹出的内容粘贴到" + ("这里:" if code else '"身份认证码"栏'), | ||
] | ||
|
||
|
||
def encryptURL(url): | ||
url_list = url.split("/") | ||
# "a97f12c055a10ee51d60e441e618bfef" | ||
|
@@ -33,6 +49,14 @@ def getToken(): | |
"https://cbiz.yanhekt.cn/v1/auth/video/token?id=0", headers=headers | ||
) | ||
data = req.json()["data"] | ||
if not data: | ||
read_auth() | ||
req = requests.get( | ||
"https://cbiz.yanhekt.cn/v1/auth/video/token?id=0", headers=headers | ||
) | ||
data = req.json()["data"] | ||
if not data: | ||
raise Exception("获取Token失败") | ||
return data["token"] | ||
|
||
|
||
|
@@ -50,6 +74,39 @@ def add_signature_for_url(url, token, timestamp, signature): | |
return url | ||
|
||
|
||
def read_auth(): | ||
if not os.path.exists("auth.txt"): | ||
return "" | ||
with open("auth.txt", "r") as f: | ||
auth = f.read().strip() | ||
headers["Authorization"] = "Bearer " + auth | ||
return auth | ||
|
||
|
||
def write_auth(auth): | ||
headers["Authorization"] = "Bearer " + auth | ||
with open("auth.txt", "w") as f: | ||
f.write(auth) | ||
|
||
|
||
def remove_auth(): | ||
headers["Authorization"] = "" | ||
if os.path.exists("auth.txt"): | ||
os.remove("auth.txt") | ||
|
||
|
||
def test_auth(courseID): | ||
""" | ||
Test if the auth in headers is valid. | ||
Return True if the auth is valid, otherwise False. | ||
""" | ||
res = requests.get( | ||
f"https://cbiz.yanhekt.cn/v2/course/session/list?course_id={courseID}", | ||
headers=headers, | ||
) | ||
return bool(res.json()["data"]) | ||
|
||
|
||
def get_course_info(courseID): | ||
courseID = courseID.strip() | ||
|
||
|
@@ -104,3 +161,23 @@ def download_audio(url, path, name): | |
res = requests.get(url, headers=_headers) | ||
with open(f"{path}/{name}.aac", "wb") as f: | ||
f.write(res.content) | ||
|
||
|
||
def print_help(f: callable): | ||
def wrap(): | ||
try: | ||
f() | ||
except Exception as e: | ||
print(e) | ||
print( | ||
"If the problem is still not solved, you can report an issue in https://github.com/AuYang261/BIT_yanhe_download/issues." | ||
) | ||
print( | ||
"Or contact with the author [email protected]. Thanks for your report!" | ||
) | ||
print( | ||
"如果问题仍未解决,您可以在https://github.com/AuYang261/BIT_yanhe_download/issues 中报告问题。" | ||
) | ||
print("或者联系作者[email protected]。感谢您的报告!") | ||
|
||
return wrap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters