mirror of
https://github.com/happycola233/tchMaterial-parser.git
synced 2026-10-16 20:50:33 +08:00
feat: add headers, optimize download logic
Signed-off-by: 晨叶梦春 <wuziqian211@126.com>
This commit is contained in:
@@ -0,0 +1 @@
|
||||
3.14.6
|
||||
+1
-1
@@ -11,7 +11,7 @@ requires-python = ">=3.10"
|
||||
license = {text = "MIT"}
|
||||
authors = [{name = "肥宅水水呀"}, {name = "晨叶梦春", email = "wuziqian211@126.com"}]
|
||||
dependencies = [
|
||||
"Pillow>=10,<12",
|
||||
"pillow>=10,<12",
|
||||
"psutil>=5.9,<8",
|
||||
"pypdf>=5,<6",
|
||||
"pyperclip>=1.8,<2",
|
||||
|
||||
@@ -133,7 +133,7 @@ def parse(url: str, bookmarks: bool) -> list[tuple[str, str, str, list[dict]]] |
|
||||
result: list[dict] = []
|
||||
for node in nodes:
|
||||
# 从 page_map 中找页码,找不到为 None
|
||||
page_num: int = next((m["page_number"] for m in page_map if m["node_id"] == node["id"]), None)
|
||||
page_num: int | None = next((m["page_number"] for m in page_map if m["node_id"] == node["id"]), None)
|
||||
chapter_item = {
|
||||
"title": node["title"],
|
||||
"page_index": page_num
|
||||
|
||||
@@ -6,4 +6,10 @@ import requests
|
||||
session = requests.Session() # 初始化请求
|
||||
session.proxies = {} # 全局忽略代理
|
||||
|
||||
headers = { "Authorization": "Bearer 0", "X-ND-AUTH": 'MAC id="0",nonce="0",mac="0"' } # 设置请求头部,包含认证信息,其中 “MAC id” 即为 Access Token,“nonce” 和 “mac” 不可缺省但可为任意非空值
|
||||
headers = { # 设置请求头部,包含认证信息,其中 “MAC id” 即为 Access Token,“nonce” 和 “mac” 不可缺省但可为任意非空值
|
||||
"Authorization": "Bearer 0",
|
||||
"Origin": "https://basic.smartedu.cn",
|
||||
"Referer": "https://basic.smartedu.cn/",
|
||||
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36",
|
||||
"X-ND-AUTH": 'MAC id="0",nonce="0",mac="0"'
|
||||
}
|
||||
|
||||
@@ -120,14 +120,21 @@ def download_file(url: str, save_path: str, chapters: list[dict] | None = None)
|
||||
ui_call(download_progress_bar.config, value=download_progress) # 更新进度条
|
||||
ui_call(progress_label.config, text=f"{format_bytes(all_downloaded_size)}/{format_bytes(all_total_size)} ({download_progress:.2f}%) 已下载 {downloaded_number}/{total_number}") # 更新标签以显示当前下载进度
|
||||
|
||||
current_state["downloaded_size"] = current_state["total_size"]
|
||||
if current_state["total_size"] > 0 and current_state["downloaded_size"] != current_state["total_size"]: # 文件下载不完整
|
||||
current_state["failed_reason"] = f"文件下载不完整,需下载 {current_state["total_size"]} 字节,实际下载 {current_state["downloaded_size"]} 字节"
|
||||
current_state["downloaded_size"], current_state["total_size"] = 0, 0
|
||||
current_state["finished"] = True
|
||||
try:
|
||||
os.remove(temp_path)
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
if chapters: # 添加书签
|
||||
ui_call(progress_label.config, text="添加书签")
|
||||
add_bookmarks(temp_path, chapters)
|
||||
|
||||
if chapters: # 添加书签
|
||||
ui_call(progress_label.config, text="添加书签")
|
||||
add_bookmarks(temp_path, chapters)
|
||||
|
||||
os.replace(temp_path, save_path) # 重命名临时文件为目标文件
|
||||
current_state["finished"] = True
|
||||
os.replace(temp_path, save_path) # 重命名临时文件为目标文件
|
||||
current_state["finished"] = True
|
||||
|
||||
except Exception as e:
|
||||
print_error(e)
|
||||
|
||||
@@ -66,6 +66,7 @@ def show_access_token_window() -> None: # 打开输入 Access Token 的窗口
|
||||
help_win.focus() # 自动获得焦点
|
||||
help_win.grab_set() # 阻止主窗口操作
|
||||
help_win.bind("<Escape>", lambda event: help_win.destroy()) # 绑定 Esc 键关闭窗口
|
||||
help_win.bind("<Destroy>", lambda event: token_window.grab_set())
|
||||
|
||||
help_frame = ttk.Frame(help_win, padding=scaled(20))
|
||||
help_frame.pack(fill="both", expand=True)
|
||||
|
||||
Reference in New Issue
Block a user