diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..3f0a10f --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.14.6 diff --git a/pyproject.toml b/pyproject.toml index 2f19d47..908b5c7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", diff --git a/src/tchmaterial_parser/api.py b/src/tchmaterial_parser/api.py index ad1bc89..d9eeb69 100644 --- a/src/tchmaterial_parser/api.py +++ b/src/tchmaterial_parser/api.py @@ -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 diff --git a/src/tchmaterial_parser/network.py b/src/tchmaterial_parser/network.py index 1388f9c..a7ebb9d 100644 --- a/src/tchmaterial_parser/network.py +++ b/src/tchmaterial_parser/network.py @@ -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"' +} diff --git a/src/tchmaterial_parser/ui/download_panel.py b/src/tchmaterial_parser/ui/download_panel.py index eb1c49f..e463c31 100644 --- a/src/tchmaterial_parser/ui/download_panel.py +++ b/src/tchmaterial_parser/ui/download_panel.py @@ -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) diff --git a/src/tchmaterial_parser/ui/token_window.py b/src/tchmaterial_parser/ui/token_window.py index 731116e..299992f 100644 --- a/src/tchmaterial_parser/ui/token_window.py +++ b/src/tchmaterial_parser/ui/token_window.py @@ -66,6 +66,7 @@ def show_access_token_window() -> None: # 打开输入 Access Token 的窗口 help_win.focus() # 自动获得焦点 help_win.grab_set() # 阻止主窗口操作 help_win.bind("", lambda event: help_win.destroy()) # 绑定 Esc 键关闭窗口 + help_win.bind("", lambda event: token_window.grab_set()) help_frame = ttk.Frame(help_win, padding=scaled(20)) help_frame.pack(fill="both", expand=True)