The only downloader you need. 下载器的集大成者。
TypeScript asyncasynciobittorentbtcross-platformdownload-managerdownloaderfluent-designftphttp3magnetpyqtpyside6pythonqtquicreactsoftwarestreaming
feat(ed2k/bt): peer counter, daemon restart, duplicate rejection, error i18n
Zhenfu Shidc0431d74722
diff --git a/app/assets/i18n/gd3.en_US.ts b/app/assets/i18n/gd3.en_US.tsindex 7190e78e..cfdadb0b 100644--- a/app/assets/i18n/gd3.en_US.ts+++ b/app/assets/i18n/gd3.en_US.ts@@ -250,8 +250,8 @@<translation type="vanished">Seed Ratio: {0:.2f}%</translation></message><message>- <location filename="../../../features/bittorrent_pack/cards.py" line="88"/>- <location filename="../../../features/bittorrent_pack/cards.py" line="106"/>+ <location filename="../../../features/bittorrent_pack/cards.py" line="102"/>+ <location filename="../../../features/bittorrent_pack/cards.py" line="118"/><source>做种 {0}</source><translation>Seeded for {0}</translation></message>@@ -260,64 +260,63 @@<translation type="vanished">Peers {0}/Seeds {1}</translation></message><message>- <location filename="../../../features/bittorrent_pack/cards.py" line="86"/>- <location filename="../../../features/bittorrent_pack/cards.py" line="104"/>+ <location filename="../../../features/bittorrent_pack/cards.py" line="100"/>+ <location filename="../../../features/bittorrent_pack/cards.py" line="116"/><source>分享率 {0}</source><translation>Seed Ratio: {0}</translation></message><message>- <location filename="../../../features/bittorrent_pack/cards.py" line="90"/><source>{0} peers</source>- <translation>{0} Peers</translation>+ <translation type="vanished">{0} Peers</translation></message><message>- <location filename="../../../features/bittorrent_pack/cards.py" line="48"/>- <location filename="../../../features/bittorrent_pack/cards.py" line="91"/>+ <location filename="../../../features/bittorrent_pack/cards.py" line="59"/>+ <location filename="../../../features/bittorrent_pack/cards.py" line="103"/><source>做种中</source><translation>Seeding</translation></message><message>- <location filename="../../../features/bittorrent_pack/cards.py" line="43"/>+ <location filename="../../../features/bittorrent_pack/cards.py" line="54"/><source>校验已有文件</source><translation>Checking Existing Files</translation></message><message>- <location filename="../../../features/bittorrent_pack/cards.py" line="44"/>+ <location filename="../../../features/bittorrent_pack/cards.py" line="55"/><source>检查续传状态</source><translation>Checking Resume Data</translation></message><message>- <location filename="../../../features/bittorrent_pack/cards.py" line="45"/>+ <location filename="../../../features/bittorrent_pack/cards.py" line="56"/><source>获取元数据</source><translation>Downloading Metadata</translation></message><message>- <location filename="../../../features/bittorrent_pack/cards.py" line="46"/>+ <location filename="../../../features/bittorrent_pack/cards.py" line="57"/><source>下载中</source><translation>Downloading</translation></message><message>- <location filename="../../../features/bittorrent_pack/cards.py" line="47"/>+ <location filename="../../../features/bittorrent_pack/cards.py" line="58"/><source>下载完成</source><translation>Download Complete</translation></message><message>- <location filename="../../../features/bittorrent_pack/cards.py" line="49"/>+ <location filename="../../../features/bittorrent_pack/cards.py" line="60"/><source>分配文件中</source><translation>Allocating Files</translation></message><message>- <location filename="../../../features/bittorrent_pack/cards.py" line="50"/>+ <location filename="../../../features/bittorrent_pack/cards.py" line="61"/><source>等待校验</source><translation>Queued for Checks</translation></message><message>- <location filename="../../../features/bittorrent_pack/cards.py" line="51"/>+ <location filename="../../../features/bittorrent_pack/cards.py" line="62"/><source>已暂停做种</source><translation>Seeding Paused</translation></message><message>- <location filename="../../../features/bittorrent_pack/cards.py" line="52"/>+ <location filename="../../../features/bittorrent_pack/cards.py" line="63"/><source>已暂停下载</source><translation>Download Paused</translation></message>@@ -539,17 +538,17 @@ http://example.com/{mp4,mkv}/video</translation><translation>Best Quality</translation></message><message>- <location filename="../../../features/bili_pack/cards.py" line="487"/>+ <location filename="../../../features/bili_pack/cards.py" line="491"/><source>截取片段</source><translation>Trim Media</translation></message><message>- <location filename="../../../features/bili_pack/cards.py" line="503"/>+ <location filename="../../../features/bili_pack/cards.py" line="507"/><source>选择分P</source><translation>Select Parts</translation></message><message>- <location filename="../../../features/bili_pack/cards.py" line="503"/>+ <location filename="../../../features/bili_pack/cards.py" line="507"/><source>选择合集</source><translation>Select Episodes</translation></message>@@ -618,7 +617,7 @@ http://example.com/{mp4,mkv}/video</translation><context><name>BilibiliTask</name><message>- <location filename="../../../features/bili_pack/task.py" line="139"/>+ <location filename="../../../features/bili_pack/task.py" line="143"/><source>{0}/{1} 集</source><translation>{0}/{1} Eps</translation></message>@@ -626,14 +625,14 @@ http://example.com/{mp4,mkv}/video</translation><context><name>BilibiliTaskCard</name><message>- <location filename="../../../features/bili_pack/cards.py" line="773"/>+ <location filename="../../../features/bili_pack/cards.py" line="777"/><source>选择分P</source><translation>Select Parts</translation></message><message>- <location filename="../../../features/bili_pack/cards.py" line="773"/>+ <location filename="../../../features/bili_pack/cards.py" line="777"/><source>选择合集</source>- <translation type="unfinished"></translation>+ <translation>Select Episodes</translation></message></context><context>@@ -1621,17 +1620,17 @@ You can adjust options in Settings at any time.</translation><context><name>EditTaskDialog</name><message>- <location filename="../../view/dialogs/edit_task.py" line="24"/>+ <location filename="../../view/dialogs/edit_task.py" line="25"/><source>编辑任务参数</source><translation>Edit Task Options</translation></message><message>- <location filename="../../view/dialogs/edit_task.py" line="30"/>+ <location filename="../../view/dialogs/edit_task.py" line="31"/><source>应用</source><translation>Apply</translation></message><message>- <location filename="../../view/dialogs/edit_task.py" line="31"/>+ <location filename="../../view/dialogs/edit_task.py" line="32"/><source>取消</source><translation>Cancel</translation></message>@@ -2368,17 +2367,17 @@ select "No Emulation" to send as-is</translation><context><name>LiveEditDialog</name><message>- <location filename="../../view/dialogs/edit_task.py" line="103"/>+ <location filename="../../view/dialogs/edit_task.py" line="104"/><source>确认更换链接</source><translation>Confirm URL Update</translation></message><message>- <location filename="../../view/dialogs/edit_task.py" line="104"/>+ <location filename="../../view/dialogs/edit_task.py" line="105"/><source>新链接与原链接的内容不一致,将清除已下载的 {0} 数据,是否继续?</source><translation>The new URL differs from the original; {0} of existing data will be cleared. Continue?</translation></message><message>- <location filename="../../view/dialogs/edit_task.py" line="120"/>+ <location filename="../../view/dialogs/edit_task.py" line="121"/><source>链接解析失败</source><translation>Link Parsing Failed</translation></message>@@ -4084,7 +4083,7 @@ Path: {1}</translation></message><message><location filename="../../view/pages/setting_page.py" line="55"/>- <location filename="../../view/pages/setting_page.py" line="371"/>+ <location filename="../../view/pages/setting_page.py" line="367"/><source>关于</source><translation>About</translation></message>@@ -4502,103 +4501,103 @@ Path: {1}</translation><translation>Use System Settings</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="319"/>+ <location filename="../../view/pages/setting_page.py" line="316"/><source>切换到用户模式</source><translation>Switch to User Mode</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="320"/>- <location filename="../../view/pages/setting_page.py" line="326"/>+ <location filename="../../view/pages/setting_page.py" line="317"/>+ <location filename="../../view/pages/setting_page.py" line="323"/><source>数据存储模式</source><translation>Configuration Data Storage Mode</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="321"/>+ <location filename="../../view/pages/setting_page.py" line="318"/><source>当前为 Portable 模式,数据保存在程序旁: {0}</source><translation>Currently in Portable mode, configuration stored next to the app: {0}</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="325"/>+ <location filename="../../view/pages/setting_page.py" line="322"/><source>切换到 Portable 模式</source><translation>Switch to Portable Mode</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="327"/>+ <location filename="../../view/pages/setting_page.py" line="324"/><source>当前为用户模式,数据保存在: {0}</source><translation>Currently in User mode, configuration stored at: {0}</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="331"/>+ <location filename="../../view/pages/setting_page.py" line="328"/><source>在应用程序启动时检查更新</source><translation>Check For Updates on Startup</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="332"/>+ <location filename="../../view/pages/setting_page.py" line="329"/><source>新版本将更稳定,并具有更多功能</source><translation>Get more features and improved stability with new versions</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="341"/>+ <location filename="../../view/pages/setting_page.py" line="337"/><source>关闭主窗口时</source><translation>Main Window Closing Behavior</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="342"/>+ <location filename="../../view/pages/setting_page.py" line="338"/><source>设置关闭主窗口后程序继续在后台运行还是退出</source><translation>Choose whether to continue running in background or exit when closing the main window</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="343"/>+ <location filename="../../view/pages/setting_page.py" line="339"/><source>关闭时询问</source><translation>Ask when closing</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="343"/>+ <location filename="../../view/pages/setting_page.py" line="339"/><source>继续在后台运行</source><translation>Continue running in background</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="343"/>+ <location filename="../../view/pages/setting_page.py" line="339"/><source>退出程序</source><translation>Exit</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="358"/>+ <location filename="../../view/pages/setting_page.py" line="354"/><source>通过提供反馈来帮助我们改进 Ghost Downloader,也可查看日志排查问题</source><translation>Help improve Ghost Downloader by providing feedback, or view logs to troubleshoot issues</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="367"/>+ <location filename="../../view/pages/setting_page.py" line="363"/><source>查看详情</source><translation>Details</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="367"/>+ <location filename="../../view/pages/setting_page.py" line="363"/><source>功能包</source><translation>Feature Packs</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="368"/>+ <location filename="../../view/pages/setting_page.py" line="364"/><source>管理已安装的功能包</source><translation>Manage currently installed feature packs</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="502"/>+ <location filename="../../view/pages/setting_page.py" line="497"/><source>用户模式</source><translation>User Mode</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="502"/>+ <location filename="../../view/pages/setting_page.py" line="497"/><source>Portable 模式</source><translation>Portable Mode</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="504"/>+ <location filename="../../view/pages/setting_page.py" line="499"/><source>切换数据存储模式</source><translation>Switch Data Storage Mode</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="505"/>+ <location filename="../../view/pages/setting_page.py" line="500"/><source>确定要切换到{0}吗?数据将被复制到新位置,程序随后退出。请手动重新打开。</source>@@ -4607,12 +4606,12 @@ Path: {1}</translation>Data will be copied to new location and the program will then exit. Please manually restart.</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="522"/>+ <location filename="../../view/pages/setting_page.py" line="517"/><source>正在检查更新...</source><translation>Checking for updates...</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="534"/>+ <location filename="../../view/pages/setting_page.py" line="529"/><source>当前已是最新版本</source><translation>You're running the latest version</translation></message>@@ -4621,17 +4620,17 @@ Data will be copied to new location and the program will then exit. Please manua<translation type="vanished">Current version {0}, latest version {1}</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="531"/>+ <location filename="../../view/pages/setting_page.py" line="526"/><source>检查更新失败</source><translation>Failed to check update</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="531"/>+ <location filename="../../view/pages/setting_page.py" line="526"/><source>无法获取最新版本信息</source><translation>Unable to get the latest version information</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="547"/>+ <location filename="../../view/pages/setting_page.py" line="542"/><source>搜索设置</source><translation>Search Settings</translation></message>@@ -4656,33 +4655,33 @@ Data will be copied to new location and the program will then exit. Please manua<translation>Start Ghost Downloader minimized on system startup</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="347"/>+ <location filename="../../view/pages/setting_page.py" line="343"/><source>剪贴板监听</source><translation>Monitor Clipboard</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="348"/>+ <location filename="../../view/pages/setting_page.py" line="344"/><source>剪贴板监听器将自动检测剪贴板中的链接并添加下载任务</source><translation>Automatically detect links in clipboard and add download tasks</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="377"/>+ <location filename="../../view/pages/setting_page.py" line="372"/><source>打开作者的个人空间</source><translation>Open Author's Profile</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="378"/>+ <location filename="../../view/pages/setting_page.py" line="373"/><source>了解作者</source><translation>About the Author</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="378"/>+ <location filename="../../view/pages/setting_page.py" line="373"/><source>发现更多 {} 的作品</source><translation>Discover more works by {}</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="356"/>- <location filename="../../view/pages/setting_page.py" line="357"/>+ <location filename="../../view/pages/setting_page.py" line="352"/>+ <location filename="../../view/pages/setting_page.py" line="353"/><source>提供反馈</source><translation>Provide Feedback</translation></message>@@ -4704,63 +4703,63 @@ Data will be copied to new location and the program will then exit. Please manua<translation type="vanished">Help improve Ghost Downloader by providing feedback</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="360"/>+ <location filename="../../view/pages/setting_page.py" line="356"/><source>查看日志</source><translation>View Logs</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="371"/>- <location filename="../../view/pages/setting_page.py" line="522"/>+ <location filename="../../view/pages/setting_page.py" line="367"/>+ <location filename="../../view/pages/setting_page.py" line="517"/><source>检查更新</source><translation>Check For Updates</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="429"/>+ <location filename="../../view/pages/setting_page.py" line="424"/><source>已配置</source><translation>Configuration Saved</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="429"/>+ <location filename="../../view/pages/setting_page.py" line="424"/><source>重启软件后生效</source><translation>Restart required to take effect</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="439"/>+ <location filename="../../view/pages/setting_page.py" line="434"/><source>已复制配对令牌</source><translation>Token Copied</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="445"/>+ <location filename="../../view/pages/setting_page.py" line="440"/><source>已重新生成配对令牌</source><translation>Token Regenerated</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="445"/>+ <location filename="../../view/pages/setting_page.py" line="440"/><source>新令牌已复制到剪贴板</source><translation>Copied new token to clipboard</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="462"/>+ <location filename="../../view/pages/setting_page.py" line="457"/><source>解包失败</source><translation>Unpack failed</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="469"/>+ <location filename="../../view/pages/setting_page.py" line="464"/><source>未连接</source><translation>Not Connected</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="471"/>+ <location filename="../../view/pages/setting_page.py" line="466"/><source>已连接 v{} (桌面端自管理)</source><translation>Connected v{} (Desktop-managed)</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="473"/>+ <location filename="../../view/pages/setting_page.py" line="468"/><source>已连接 v{} (商店安装)</source><translation>Connected v{} (Store-installed)</translation></message><message>- <location filename="../../view/pages/setting_page.py" line="479"/>+ <location filename="../../view/pages/setting_page.py" line="474"/><source>选择导出路径</source><translation>Select Export Path</translation></message>@@ -4856,47 +4855,47 @@ Data will be copied to new location and the program will then exit. Please manua<context><name>TaskCard</name><message>- <location filename="../../view/cards/task_cards.py" line="78"/>+ <location filename="../../view/cards/task_cards.py" line="79"/><source>暂停/继续</source><translation>Pause/Resume</translation></message><message>- <location filename="../../view/cards/task_cards.py" line="83"/>+ <location filename="../../view/cards/task_cards.py" line="84"/><source>选择文件</source><translation>Select Files</translation></message><message>- <location filename="../../view/cards/task_cards.py" line="86"/>+ <location filename="../../view/cards/task_cards.py" line="87"/><source>校验文件哈希</source><translation>Verify File Hash</translation></message><message>- <location filename="../../view/cards/task_cards.py" line="93"/>+ <location filename="../../view/cards/task_cards.py" line="94"/><source>打开文件</source><translation>Open File</translation></message><message>- <location filename="../../view/cards/task_cards.py" line="98"/>+ <location filename="../../view/cards/task_cards.py" line="99"/><source>打开文件夹</source><translation>Open Folder</translation></message><message>- <location filename="../../view/cards/task_cards.py" line="99"/>+ <location filename="../../view/cards/task_cards.py" line="100"/><source>删除</source><translation>Delete</translation></message><message>- <location filename="../../view/cards/task_cards.py" line="257"/>+ <location filename="../../view/cards/task_cards.py" line="258"/><source>文件不存在</source><translation>File does not exist</translation></message><message>- <location filename="../../view/cards/task_cards.py" line="260"/>+ <location filename="../../view/cards/task_cards.py" line="261"/><source>完成于 {}</source><translation>Completed at {}</translation></message><message>- <location filename="../../view/cards/task_cards.py" line="263"/>+ <location filename="../../view/cards/task_cards.py" line="264"/><source>任务已经完成</source><translation>Task Completed</translation></message>@@ -4970,6 +4969,12 @@ Data will be copied to new location and the program will then exit. Please manua<source>未分类</source><translation>Uncategorized</translation></message>+ <message>+ <location filename="../../../features/bittorrent_pack/cards.py" line="44"/>+ <location filename="../../../features/ed2k_pack/cards.py" line="13"/>+ <source>{0}/{1} Peers</source>+ <translation>{0}/{1} Peers</translation>+ </message></context><context><name>TaskCommandBarView</name>@@ -5022,48 +5027,48 @@ Data will be copied to new location and the program will then exit. Please manua<context><name>TaskDraftDialog</name><message>- <location filename="../../view/dialogs/task_draft.py" line="76"/>+ <location filename="../../view/dialogs/task_draft.py" line="77"/><source>添加任务</source><translation>Add Task</translation></message><message>- <location filename="../../view/dialogs/task_draft.py" line="81"/>+ <location filename="../../view/dialogs/task_draft.py" line="82"/><source>批量添加</source><translation>Batch Add</translation></message><message>- <location filename="../../view/dialogs/task_draft.py" line="82"/>- <location filename="../../view/dialogs/task_draft.py" line="324"/>+ <location filename="../../view/dialogs/task_draft.py" line="83"/>+ <location filename="../../view/dialogs/task_draft.py" line="325"/><source>导入文件</source><translation>Import File(s)</translation></message><message>- <location filename="../../view/dialogs/task_draft.py" line="96"/>+ <location filename="../../view/dialogs/task_draft.py" line="97"/><source>添加多个下载链接时,请确保每行只有一个下载链接</source><translation>When adding multiple download links, make sure each line contains only one link</translation></message><message>- <location filename="../../view/dialogs/task_draft.py" line="106"/>+ <location filename="../../view/dialogs/task_draft.py" line="107"/><source>下载</source><translation>Download</translation></message><message>- <location filename="../../view/dialogs/task_draft.py" line="108"/>+ <location filename="../../view/dialogs/task_draft.py" line="109"/><source>稍后下载</source><translation>Download Later</translation></message><message>- <location filename="../../view/dialogs/task_draft.py" line="114"/>+ <location filename="../../view/dialogs/task_draft.py" line="115"/><source>取消</source><translation>Cancel</translation></message><message>- <location filename="../../view/dialogs/task_draft.py" line="282"/>+ <location filename="../../view/dialogs/task_draft.py" line="283"/><source>链接解析失败</source><translation>Link Parsing Failed</translation></message><message>- <location filename="../../view/dialogs/task_draft.py" line="319"/>+ <location filename="../../view/dialogs/task_draft.py" line="320"/><source>所有可导入文件 ({0})</source><translation>All Supported Formats ({0})</translation></message>@@ -5071,29 +5076,29 @@ Data will be copied to new location and the program will then exit. Please manua<context><name>TaskErrors</name><message>- <location filename="../../view/error_catalog.py" line="3"/>- <location filename="../../../features/ed2k_pack/error_catalog.py" line="4"/>+ <location filename="../../view/error_catalog.py" line="9"/>+ <location filename="../../../features/ed2k_pack/error_catalog.py" line="6"/><location filename="../../../features/yt_dlp_pack/error_catalog.py" line="13"/><source>{name} 未安装,请在设置中安装</source><translation>{name} is not installed, please install it in Settings</translation></message><message>- <location filename="../../view/error_catalog.py" line="4"/>+ <location filename="../../view/error_catalog.py" line="10"/><source>服务器返回了错误({status})</source><translation>Server returned an error ({status})</translation></message><message>- <location filename="../../view/error_catalog.py" line="5"/>+ <location filename="../../view/error_catalog.py" line="11"/><source>无法建立 FTP 连接</source><translation>FTP connection failed</translation></message><message>- <location filename="../../view/error_catalog.py" line="6"/>+ <location filename="../../view/error_catalog.py" line="12"/><source>进程异常退出({code}):{detail}</source><translation>Process terminated abnormally ({code}): {detail}</translation></message><message>- <location filename="../../view/error_catalog.py" line="7"/>+ <location filename="../../view/error_catalog.py" line="13"/><source>发生了意外错误:{detail}</source><translation>Unexpected error: {detail}</translation></message>@@ -5150,8 +5155,18 @@ Data will be copied to new location and the program will then exit. Please manua<source>ED2k 错误:{detail}</source><translation>ED2k error: {detail}</translation></message>+ <message>+ <location filename="../../../features/ed2k_pack/error_catalog.py" line="4"/>+ <source>该 eD2k 链接已在下载中</source>+ <translation>This eD2k link is already being downloaded</translation>+ </message><message><location filename="../../../features/ed2k_pack/error_catalog.py" line="5"/>+ <source>该 eD2k 传输已存在于 daemon 中</source>+ <translation type="unfinished">This eD2k transfer already exists in daemon</translation>+ </message>+ <message>+ <location filename="../../../features/ed2k_pack/error_catalog.py" line="7"/><source>ED2kSession 未启动</source><translation>ED2k session not started</translation></message>@@ -5215,6 +5230,41 @@ Data will be copied to new location and the program will then exit. Please manua<source>未找到可用的视频格式</source><translation>No available video format found</translation></message>+ <message>+ <location filename="../../../features/m3u8_pack/error_catalog.py" line="3"/>+ <source>服务器拒绝了请求(403),链接可能已失效({detail})</source>+ <translation>Request refused (403), link might have expired: {detail}</translation>+ </message>+ <message>+ <location filename="../../../features/m3u8_pack/error_catalog.py" line="4"/>+ <source>资源不存在(404),链接可能已失效({detail})</source>+ <translation>Resource does not exist (404), link might no longer be available: {detail}</translation>+ </message>+ <message>+ <location filename="../../../features/m3u8_pack/error_catalog.py" line="5"/>+ <source>服务器返回了错误({detail})</source>+ <translation>Server returned an error ({detail})</translation>+ </message>+ <message>+ <location filename="../../../features/m3u8_pack/error_catalog.py" line="6"/>+ <source>无法解析域名,请检查网络连接({detail})</source>+ <translation>Domain resolution failed, please check your connection ({detail})</translation>+ </message>+ <message>+ <location filename="../../../features/m3u8_pack/error_catalog.py" line="7"/>+ <source>连接被拒绝,请检查网络连接({detail})</source>+ <translation>Connection refused, please check your connection ({detail})</translation>+ </message>+ <message>+ <location filename="../../../features/m3u8_pack/error_catalog.py" line="8"/>+ <source>连接超时,请检查网络连接({detail})</source>+ <translation>Connection timed out, please check your connection ({detail})</translation>+ </message>+ <message>+ <location filename="../../../features/m3u8_pack/error_catalog.py" line="9"/>+ <source>SSL 连接失败,请检查网络连接({detail})</source>+ <translation>SSL handshake failed, please check your connection ({detail})</translation>+ </message></context><context><name>TaskPage</name>@@ -5489,22 +5539,22 @@ Data will be copied to new location and the program will then exit. Please manua<context><name>UpdateErrors</name><message>- <location filename="../../view/error_catalog.py" line="9"/>+ <location filename="../../view/error_catalog.py" line="15"/><source>无法获取版本信息</source><translation>Unable to retrieve version information</translation></message><message>- <location filename="../../view/error_catalog.py" line="10"/>+ <location filename="../../view/error_catalog.py" line="16"/><source>校验失败</source><translation>Checksum verification failed</translation></message><message>- <location filename="../../view/error_catalog.py" line="11"/>+ <location filename="../../view/error_catalog.py" line="17"/><source>当前平台无可用更新</source><translation>No update is available for the current platform</translation></message><message>- <location filename="../../view/error_catalog.py" line="12"/>+ <location filename="../../view/error_catalog.py" line="18"/><source>DMG 中未找到 .app</source><translation>No .app bundle was found in the DMG</translation></message>@@ -6059,7 +6109,7 @@ For manual import: Open YouTube and log in, press F12 to open Developer Tools, g<context><name>self._dialog</name><message>- <location filename="../../view/dialogs/task_draft.py" line="45"/>+ <location filename="../../view/dialogs/task_draft.py" line="46"/><source>添加任务</source><translation>Add Task</translation></message>diff --git a/app/view/cards/task_cards.py b/app/view/cards/task_cards.pyindex b2642f52..c3be7bca 100644--- a/app/view/cards/task_cards.py+++ b/app/view/cards/task_cards.py@@ -5,7 +5,7 @@ from datetime import datetimefrom pathlib import Pathfrom typing import TYPE_CHECKING, Callable-from PySide6.QtCore import QCoreApplication, QFileInfo, QPoint, Signal, Qt, QT_TRANSLATE_NOOP as N+from PySide6.QtCore import QFileInfo, QPoint, Signal, Qt, QT_TRANSLATE_NOOP as Nfrom PySide6.QtGui import QColor, QPainter, QPenfrom PySide6.QtWidgets import QFileIconProvider, QHBoxLayout, QVBoxLayout, QApplication, QWidget, QSizePolicyfrom qfluentwidgets import (@@ -20,6 +20,7 @@ from app.format import toReadableSize, toReadableTimefrom app.models.task import TaskStatus, SpecialFileSizefrom app.platform.desktop import openFile, revealInFolderfrom app.view.components.labels import IconBodyLabel, IconStrongBodyLabel+from app.view.error_catalog import toLocalizedErrorif TYPE_CHECKING:from app.models.task import Task@@ -268,8 +269,7 @@ class TaskCard(CardWidget):self.progressBar.setError(True)error = task.lastErrorif error:- text = QCoreApplication.translate("TaskErrors", error.message)- self._setStatus(text.format_map(error.params) if error.params else text)+ self._setStatus(toLocalizedError(error.message, error.params))else:self._setStatus(self.tr("下载过程中发生错误,请稍后重试"))diff --git a/app/view/components/progress_toast.py b/app/view/components/progress_toast.pyindex 32d194ce..e3c5c093 100644--- a/app/view/components/progress_toast.py+++ b/app/view/components/progress_toast.py@@ -108,7 +108,7 @@ class ProgressToast(InfoBar):self.iconWidget.icon = InfoBarIcon.ERRORself.title = self.tr("下载更新失败")self.content = (- QCoreApplication.translate("UpdateErrors", info.error)+ QCoreApplication.translate("UpdateErrors", info.error) or info.errorif info.error else self.tr("未知错误"))self._retryButton.show()diff --git a/app/view/dialogs/edit_task.py b/app/view/dialogs/edit_task.pyindex 8abd538a..32962c51 100644--- a/app/view/dialogs/edit_task.py+++ b/app/view/dialogs/edit_task.py@@ -10,6 +10,7 @@ from qfluentwidgets import (from app.format import toReadableSizefrom app.view.components.card_groups import OptionCardGroup+from app.view.error_catalog import toLocalizedErrorif TYPE_CHECKING:from app.models.task import Task@@ -118,7 +119,7 @@ class LiveEditDialog(EditTaskDialog):self._setInteractive(True)InfoBar.error(title=self.tr("链接解析失败"),- content=error,+ content=toLocalizedError(error),duration=4000,position=InfoBarPosition.TOP,parent=self,diff --git a/app/view/dialogs/task_draft.py b/app/view/dialogs/task_draft.pyindex 5b442ea3..00145c74 100644--- a/app/view/dialogs/task_draft.py+++ b/app/view/dialogs/task_draft.py@@ -18,6 +18,7 @@ from app.platform.android import IS_ANDROIDfrom app.view.components.card_groups import DraftCardGroup, OptionCardGroupfrom app.view.components.editors import AutoSizingEditfrom app.view.components.option_cards import OutputFolderCard, SubworkerCountCard+from app.view.error_catalog import toLocalizedErrorif TYPE_CHECKING:from app.models.task import Task@@ -280,7 +281,7 @@ class TaskDraftDialog(MessageBoxBase):displayUrl = url if len(url) <= 48 else f"{url[:45]}..."InfoBar.error(self.tr("链接解析失败"),- f"{displayUrl}\n{error}",+ f"{displayUrl}\n{toLocalizedError(error)}",duration=5000,position=InfoBarPosition.BOTTOM_RIGHT,parent=self,diff --git a/app/view/error_catalog.py b/app/view/error_catalog.pyindex 104b9bdb..6938ab7c 100644--- a/app/view/error_catalog.py+++ b/app/view/error_catalog.py@@ -1,4 +1,10 @@-from PySide6.QtCore import QT_TRANSLATE_NOOP as N+from PySide6.QtCore import QCoreApplication, QT_TRANSLATE_NOOP as N+++def toLocalizedError(message: str, params: dict | None = None) -> str:+ text = QCoreApplication.translate("TaskErrors", message) or message+ return text.format_map(params) if params else text+N("TaskErrors", "{name} 未安装,请在设置中安装")N("TaskErrors", "服务器返回了错误({status})")diff --git a/features/bittorrent_pack/cards.py b/features/bittorrent_pack/cards.pyindex fd686bab..fd1fdd09 100644--- a/features/bittorrent_pack/cards.py+++ b/features/bittorrent_pack/cards.py@@ -1,4 +1,4 @@-from PySide6.QtCore import QT_TRANSLATE_NOOP as N+from PySide6.QtCore import QCoreApplication, QT_TRANSLATE_NOOP as Nfrom PySide6.QtWidgets import QFileIconProviderfrom qfluentwidgets import FluentIcon@@ -39,6 +39,17 @@ BT_UPLOAD_FIELD = FieldSpec("upload", FluentIcon.SHARE, {BT_ETA_FIELD = FieldSpec("eta", FluentIcon.STOP_WATCH, {TaskStatus.RUNNING: toBtEtaText})BT_SIZE_FIELD = FieldSpec("size", FluentIcon.LIBRARY, {None: toBtSizeText})++def toPeerText(task: BTTask, _speed: int, _received: int) -> str:+ return QCoreApplication.translate("TaskCard", "{0}/{1} Peers").format(+ task.peerCount, task.totalPeerCount+ )+++BT_PEERS_FIELD = FieldSpec(+ "peers", FluentIcon.INFO, {TaskStatus.RUNNING: toPeerText}+)+BT_STATE_LABELS = {"checking_files": N("BTTaskCard", "校验已有文件"),"checking_resume_data": N("BTTaskCard", "检查续传状态"),@@ -75,7 +86,10 @@ class BTDraftCard(MultiFileDraftCard):class BTTaskCard(MultiFileTaskCard):uploadLabel: IconBodyLabelfileSelectDialog = TorrentFileSelectDialog- infoFields = [BT_SPEED_FIELD, BT_UPLOAD_FIELD, BT_ETA_FIELD, BT_SIZE_FIELD]+ infoFields = [+ BT_SPEED_FIELD, BT_UPLOAD_FIELD, BT_ETA_FIELD, BT_SIZE_FIELD,+ BT_PEERS_FIELD,+ ]def _refreshForStatus(self, task):super()._refreshForStatus(task)@@ -86,8 +100,6 @@ class BTTaskCard(MultiFileTaskCard):parts.append(self.tr("分享率 {0}").format(f"{task.shareRatioPercent:.1f}%"))if task.seedingTimeSeconds > 0:parts.append(self.tr("做种 {0}").format(toReadableTime(task.seedingTimeSeconds)))- if task.peerCount > 0:- parts.append(self.tr("{0} peers").format(task.peerCount))self._setStatus(self.tr("做种中") + " " + " · ".join(parts))elif task.status == TaskStatus.RUNNING and task.stateText and task.stateText != "downloading":self.progressBar.hide()diff --git a/features/bittorrent_pack/session.py b/features/bittorrent_pack/session.pyindex be929927..eb96f7cf 100644--- a/features/bittorrent_pack/session.py+++ b/features/bittorrent_pack/session.py@@ -73,6 +73,7 @@ class TorrentParams:class TorrentProgress:stateText: strpeerCount: int+ totalPeerCount: intseedCount: intisSeeding: booldownloadRate: int@@ -465,6 +466,7 @@ class BTSession(QObject):entry.onProgress(TorrentProgress(stateText=stateText,peerCount=status.num_peers,+ totalPeerCount=max(status.num_peers, status.list_peers),seedCount=status.num_seeds,isSeeding=isSeeding,downloadRate=downloadRate,diff --git a/features/bittorrent_pack/task.py b/features/bittorrent_pack/task.pyindex 582db04a..83f28352 100644--- a/features/bittorrent_pack/task.py+++ b/features/bittorrent_pack/task.py@@ -32,6 +32,7 @@ class BTTask(Task):isSeeding: bool = FalsestateText: str = ""peerCount: int = 0+ totalPeerCount: int = 0seedCount: int = 0downloadRate: int = 0uploadRate: int = 0@@ -121,6 +122,7 @@ class BTTask(Task):self.isSeeding = Falseself.stateText = ""self.peerCount = 0+ self.totalPeerCount = 0self.seedCount = 0self.downloadRate = 0self.uploadRate = 0@@ -174,6 +176,7 @@ class BTTaskStep(TaskStep):def onProgress(p: TorrentProgress):task.stateText = p.stateTexttask.peerCount = p.peerCount+ task.totalPeerCount = p.totalPeerCounttask.seedCount = p.seedCounttask.isSeeding = p.isSeedingtask.downloadRate = p.downloadRatediff --git a/features/ed2k_pack/cards.py b/features/ed2k_pack/cards.pynew file mode 100644index 00000000..a3dc584b--- /dev/null+++ b/features/ed2k_pack/cards.py@@ -0,0 +1,24 @@+from PySide6.QtCore import QCoreApplication+from qfluentwidgets import FluentIcon++from app.models.task import TaskStatus+from app.view.cards.task_cards import FieldSpec, TaskCard+from .task import ED2kTask+++def toPeerText(task: ED2kTask, _speed: int, _received: int) -> str | None:+ if task.activePeerCount is None:+ return None+ total = max(task.activePeerCount, task.totalPeerCount)+ return QCoreApplication.translate("TaskCard", "{0}/{1} Peers").format(+ task.activePeerCount, total+ )+++ED2K_PEERS_FIELD = FieldSpec(+ "peers", FluentIcon.INFO, {TaskStatus.RUNNING: toPeerText}+)+++class ED2kTaskCard(TaskCard):+ infoFields = [*TaskCard.infoFields, ED2K_PEERS_FIELD]diff --git a/features/ed2k_pack/error_catalog.py b/features/ed2k_pack/error_catalog.pyindex 3cd86cc0..e0780b56 100644--- a/features/ed2k_pack/error_catalog.py+++ b/features/ed2k_pack/error_catalog.py@@ -1,5 +1,7 @@from PySide6.QtCore import QT_TRANSLATE_NOOP as NN("TaskErrors", "ED2k 错误:{detail}")+N("TaskErrors", "该 eD2k 链接已在下载中")+N("TaskErrors", "该 eD2k 传输已存在于 daemon 中")N("TaskErrors", "{name} 未安装,请在设置中安装")N("TaskErrors", "ED2kSession 未启动")diff --git a/features/ed2k_pack/pack.py b/features/ed2k_pack/pack.pyindex 6dea7c9a..7ede0540 100644--- a/features/ed2k_pack/pack.py+++ b/features/ed2k_pack/pack.py@@ -1,9 +1,10 @@from __future__ import annotationsfrom app.models.pack import FeaturePack, TaskParser, UriScheme-from app.models.task import Task, TaskOptions+from app.models.task import Task, TaskError, TaskOptionsfrom app.platform.filesystem import toSafeFilenamefrom .config import ed2kConfig, ed2kRuntime+from .cards import ED2kTaskCardfrom .task import ED2kTask, ED2kTaskStep, parseEd2kLink@@ -15,7 +16,11 @@ class ED2kParser(TaskParser):async def parse(self, options: TaskOptions) -> Task:link = options.url.strip()- name, fileSize, _ = parseEd2kLink(link)+ name, fileSize, fileHash = parseEd2kLink(link)+ from .session import ed2kSession++ if ed2kSession.hasActiveTransfer(fileHash, fileSize):+ raise TaskError("该 eD2k 链接已在下载中")name = toSafeFilename(name, fallback="ed2k_download")task = ED2kTask(@@ -32,6 +37,7 @@ class ED2kPack(FeaturePack):packId = "ed2k"config = ed2kConfigparsers = [ED2kParser]+ taskCards = {ED2kTask: ED2kTaskCard}def uriSchemes(self) -> list[UriScheme]:return [UriScheme("ed2k", "eD2k")]diff --git a/features/ed2k_pack/python_ed2k/client.py b/features/ed2k_pack/python_ed2k/client.pyindex 6e04a475..a9b6ec81 100644--- a/features/ed2k_pack/python_ed2k/client.py+++ b/features/ed2k_pack/python_ed2k/client.py@@ -31,6 +31,11 @@ class Client:self._snapshotCondition = asyncio.Condition()self._exitError: Error | None = None+ @property+ def isRunning(self) -> bool:+ process = self._process+ return process is not None and process.returncode is None and not self._stopped+async def start(self, settings: Settings = Settings()) -> Snapshot:loop = asyncio.get_running_loop()if self._loop is None:@@ -76,6 +81,9 @@ class Client:},))+ except asyncio.CancelledError:+ await self.terminate()+ raiseexcept Exception:await self.terminate()raise@@ -304,6 +312,7 @@ def _toTransfer(value: Any) -> Transfer:received=value["received"],downloadRate=value["downloadRate"],uploadRate=value["uploadRate"],+ activePeers=value.get("activePeers"),peers=value["peers"],)except (KeyError, TypeError, ValueError) as error:diff --git a/features/ed2k_pack/python_ed2k/models.py b/features/ed2k_pack/python_ed2k/models.pyindex b329293f..f57b27ad 100644--- a/features/ed2k_pack/python_ed2k/models.py+++ b/features/ed2k_pack/python_ed2k/models.py@@ -35,6 +35,7 @@ class Transfer:received: intdownloadRate: intuploadRate: int+ activePeers: int | Nonepeers: intdiff --git a/features/ed2k_pack/session.py b/features/ed2k_pack/session.pyindex 26a0a4fd..134de5ab 100644--- a/features/ed2k_pack/session.py+++ b/features/ed2k_pack/session.py@@ -1,5 +1,6 @@from __future__ import annotations+import asynciofrom pathlib import Pathfrom loguru import logger@@ -14,8 +15,27 @@ class ED2kSession:def __init__(self):self._client: Client | None = None+ self._openLock = asyncio.Lock()+ self._activeTransfers: set[tuple[str, int]] = set()self.submit = None+ @staticmethod+ def toTransferKey(fileHash: str, fileSize: int) -> tuple[str, int]:+ return fileHash.upper(), fileSize++ def hasActiveTransfer(self, fileHash: str, fileSize: int) -> bool:+ return self.toTransferKey(fileHash, fileSize) in self._activeTransfers++ def acquireTransfer(self, fileHash: str, fileSize: int) -> tuple[str, int]:+ identity = self.toTransferKey(fileHash, fileSize)+ if identity in self._activeTransfers:+ raise TaskError("该 eD2k 链接已在下载中")+ self._activeTransfers.add(identity)+ return identity++ def releaseTransfer(self, identity: tuple[str, int]) -> None:+ self._activeTransfers.discard(identity)+def removeHash(self, fileHash: str) -> None:if self._client is None or self.submit is None:return@@ -30,32 +50,36 @@ class ED2kSession:return self._clientasync def open(self) -> None:- if self._client is not None:- return- path = ed2kRuntime.path()- if not path:- raise TaskError(- "{name} 未安装,请在设置中安装", name=ed2kRuntime.name- )- client = Client(Path(path), Path(APP_DATA_DIR) / "ed2k_data")- try:+ async with self._openLock:+ if self._client is not None and self._client.isRunning:+ return++ # An unexpected daemon exit is remembered by Client so active tasks+ # can report it. A later task attempt must replace that dead client+ # instead of replaying the same cached EngineExited forever.+ self._client = None++ path = ed2kRuntime.path()+ if not path:+ raise TaskError(+ "{name} 未安装,请在设置中安装", name=ed2kRuntime.name+ )+ client = Client(Path(path), Path(APP_DATA_DIR) / "ed2k_data")await client.start(Settings(- enableDht=ed2kConfig.enableDht.value,- enableUpnp=ed2kConfig.enableUpnp.value,- listenPort=ed2kConfig.listenPort.value,- serverMetSource=ed2kConfig.serverMetSource.value or None,- nodesDatSource=ed2kConfig.nodesDatSource.value or None,- ))- except Exception:- await client.terminate()- raise- self._client = client+ enableDht=ed2kConfig.enableDht.value,+ enableUpnp=ed2kConfig.enableUpnp.value,+ listenPort=ed2kConfig.listenPort.value,+ serverMetSource=ed2kConfig.serverMetSource.value or None,+ nodesDatSource=ed2kConfig.nodesDatSource.value or None,+ ))+ self._client = clientasync def close(self) -> None:- if self._client is None:- return- await self._client.close()- self._client = None+ async with self._openLock:+ client = self._client+ self._client = None+ if client is not None:+ await client.close()ed2kSession = ED2kSession()diff --git a/features/ed2k_pack/task.py b/features/ed2k_pack/task.pyindex 57ec52fb..56bf0c8d 100644--- a/features/ed2k_pack/task.py+++ b/features/ed2k_pack/task.py@@ -4,7 +4,7 @@ import asyncioimport sysfrom dataclasses import dataclassfrom pathlib import Path-from urllib.parse import unquote+from urllib.parse import quote, unquotefrom loguru import logger@@ -14,9 +14,13 @@ from app.models.task import Task, TaskError, TaskStep, TaskStatusclass ED2kTask(Task):packId: str = "ed2k"fileHash: str = ""+ activePeerCount: int | None = None+ totalPeerCount: int = 0def reset(self) -> TaskStatus:self.fileHash = ""+ self.activePeerCount = None+ self.totalPeerCount = 0return super().reset()def deleteFiles(self):@@ -34,47 +38,55 @@ class ED2kTaskStep(TaskStep):from .session import ed2kSessiontask: ED2kTask = self.task-- await ed2kSession.open()- client = ed2kSession.client()-- if task.fileHash:- await client.resume(task.fileHash)- else:- try:- transfer = await client.addLink(task.url, task.outputFolder)- except Error as e:- if e.code != ErrorCode.TRANSFER_EXISTS:- raise TaskError("ED2k 错误:{detail}", detail=str(e)) from e- _, _, linkHash = parseEd2kLink(task.url)- await client.remove(linkHash, deleteFile=False)- transfer = await client.addLink(task.url, task.outputFolder)- task.fileHash = transfer.hash- task.name = transfer.name or task.name+ _, linkSize, linkHash = parseEd2kLink(task.url)+ identity = ed2kSession.acquireTransfer(linkHash, linkSize)try:- async for snapshot in client.snapshots():- for t in snapshot.transfers:- if t.hash != task.fileHash:- continue- self.receivedBytes = t.received- self.speed = t.downloadRate- reportSpeed(t.downloadRate)- if t.size > 0:- task.fileSize = t.size- self.progress = min(99.9, t.received / t.size * 100)- if t.state == TransferState.FINISHED:- self.setStatus(TaskStatus.COMPLETED)- await client.pause(task.fileHash)- return- break- except asyncio.CancelledError:+ await ed2kSession.open()+ client = ed2kSession.client()+if task.fileHash:+ await client.resume(task.fileHash)+ else:try:- await ed2kSession.client().pause(task.fileHash)- except Exception as e:- logger.opt(exception=e).warning("暂停 eD2k 传输失败")- raise+ transfer = await client.addLink(+ buildEd2kLink(task.url, task.name),+ task.outputFolder,+ )+ except Error as e:+ if e.code == ErrorCode.TRANSFER_EXISTS:+ raise TaskError("该 eD2k 传输已存在于 daemon 中") from e+ raise TaskError("ED2k 错误:{detail}", detail=str(e)) from e+ task.fileHash = transfer.hash+ task.name = transfer.name or task.name++ try:+ async for snapshot in client.snapshots():+ for t in snapshot.transfers:+ if t.hash != task.fileHash:+ continue+ self.receivedBytes = t.received+ self.speed = t.downloadRate+ task.activePeerCount = t.activePeers+ task.totalPeerCount = t.peers+ reportSpeed(t.downloadRate)+ if t.size > 0:+ task.fileSize = t.size+ self.progress = min(99.9, t.received / t.size * 100)+ if t.state == TransferState.FINISHED:+ self.setStatus(TaskStatus.COMPLETED)+ await client.pause(task.fileHash)+ return+ break+ except asyncio.CancelledError:+ if task.fileHash:+ try:+ await ed2kSession.client().pause(task.fileHash)+ except Exception as e:+ logger.opt(exception=e).warning("暂停 eD2k 传输失败")+ raise+ finally:+ ed2kSession.releaseTransfer(identity)@dataclass(kw_only=True)@@ -105,3 +117,9 @@ def parseEd2kLink(link: str) -> tuple[str, int, str]:size = 0fileHash = parts[4] if len(parts) > 4 else ""return name, size, fileHash+++def buildEd2kLink(link: str, name: str) -> str:+ parts = link.strip().split("|")+ parts[2] = quote(name, safe="")+ return "|".join(parts)diff --git a/tests/test_ed2k_client.py b/tests/test_ed2k_client.pynew file mode 100644index 00000000..88d13adf--- /dev/null+++ b/tests/test_ed2k_client.py@@ -0,0 +1,30 @@+import asyncio++import pytest++from ed2k_pack.python_ed2k import Client+++async def test_cancelled_start_terminates_daemon(tmp_path):+ daemon = tmp_path / "slow-daemon"+ daemon.write_text(+ "#!/usr/bin/env python3\n"+ "import time\n"+ "time.sleep(60)\n"+ )+ daemon.chmod(0o755)++ client = Client(daemon, tmp_path / "data")+ start = asyncio.create_task(client.start())+ await asyncio.sleep(0.05)+ process = client._process+ assert process is not None+ start.cancel()++ with pytest.raises(asyncio.CancelledError):+ await start++ assert not client.isRunning+ assert client._process is None+ assert process.returncode is not Nonediff --git a/tests/test_ed2k_session.py b/tests/test_ed2k_session.pynew file mode 100644index 00000000..4b3dd6f3--- /dev/null+++ b/tests/test_ed2k_session.py@@ -0,0 +1,57 @@+import asyncio++import pytest++from ed2k_pack import session as session_module+++class _FakeClient:+ instances = []++ def __init__(self, executable, dataDir):+ self.executable = executable+ self.dataDir = dataDir+ self.isRunning = False+ self.startCalls = 0+ self.closeCalls = 0+ self.__class__.instances.append(self)++ async def start(self, settings):+ self.startCalls += 1+ await asyncio.sleep(0)+ self.isRunning = True++ async def close(self):+ self.closeCalls += 1+ self.isRunning = False+++def fake_client(monkeypatch):+ _FakeClient.instances.clear()+ monkeypatch.setattr(session_module, "Client", _FakeClient)+ monkeypatch.setattr(session_module.ed2kRuntime, "path", lambda: "/tmp/goed2kd")+ return _FakeClient+++async def test_open_replaces_stopped_client(fake_client):+ session = session_module.ED2kSession()+ stopped = fake_client("/tmp/old", "/tmp/data")+ session._client = stopped++ await session.open()++ assert session.client() is not stopped+ assert session.client().isRunning+ assert session.client().startCalls == 1+++async def test_concurrent_open_starts_one_client(fake_client):+ session = session_module.ED2kSession()++ await asyncio.gather(session.open(), session.open())++ assert len(fake_client.instances) == 1+ assert fake_client.instances[0].startCalls == 1diff --git a/tests/test_ed2k_task.py b/tests/test_ed2k_task.pynew file mode 100644index 00000000..2637370e--- /dev/null+++ b/tests/test_ed2k_task.py@@ -0,0 +1,162 @@+from pathlib import Path++import pytest++from app.models.task import TaskError, TaskOptions, TaskStatus+from ed2k_pack import session as session_module+from ed2k_pack.pack import ED2kParser+from ed2k_pack.python_ed2k import Snapshot, Transfer, TransferState+from ed2k_pack.python_ed2k.errors import Error, ErrorCode+from ed2k_pack.task import (+ ED2kTask,+ ED2kTaskStep,+ parseEd2kLink,+ buildEd2kLink,+)+++FILE_HASH = "D6E4FE0BA5FD8A2F22FC9C0326481791"+LINK = f"ed2k://|file|payload.bin|1234|{FILE_HASH}|h=TESTAICH|/"+++class FakeClient:+ isRunning = True++ def __init__(self):+ self.added: list[tuple[str, Path]] = []+ self.paused: list[str] = []+ self.removed: list[str] = []++ async def addLink(self, link: str, outputDir: Path) -> Transfer:+ self.added.append((link, outputDir))+ name, size, fileHash = parseEd2kLink(link)+ return Transfer(+ hash=fileHash,+ name=name,+ path=outputDir / name,+ size=size,+ state=TransferState.DOWNLOADING,+ done=0,+ received=0,+ downloadRate=0,+ uploadRate=0,+ activePeers=0,+ peers=0,+ )++ async def snapshots(self):+ link, outputDir = self.added[-1]+ name, size, fileHash = parseEd2kLink(link)+ yield Snapshot(transfers=(Transfer(+ hash=fileHash,+ name=name,+ path=outputDir / name,+ size=size,+ state=TransferState.FINISHED,+ done=size,+ received=size,+ downloadRate=0,+ uploadRate=0,+ activePeers=0,+ peers=1,+ ),))++ async def pause(self, fileHash: str) -> None:+ self.paused.append(fileHash)++ async def remove(self, fileHash: str, deleteFile: bool = False) -> None:+ self.removed.append(fileHash)+++def makeTask(tmp_path: Path, name: str = "payload(1).bin") -> ED2kTask:+ task = ED2kTask(+ name=name,+ url=LINK,+ fileSize=1234,+ outputFolder=tmp_path,+ )+ task.addStep(ED2kTaskStep(stepIndex=1))+ task.setStatus(TaskStatus.RUNNING)+ return task+++def test_build_ed2k_link_preserves_content_identity():+ renamed = buildEd2kLink(LINK, "payload(1).bin")++ assert parseEd2kLink(renamed) == ("payload(1).bin", 1234, FILE_HASH)+ assert renamed.endswith("|h=TESTAICH|/")+++def test_session_rejects_duplicate_hash_and_size():+ session = session_module.ED2kSession()+ identity = session.acquireTransfer(FILE_HASH.lower(), 1234)++ with pytest.raises(TaskError, match="该 eD2k 链接已在下载中"):+ session.acquireTransfer(FILE_HASH, 1234)++ differentSize = session.acquireTransfer(FILE_HASH, 4321)+ session.releaseTransfer(differentSize)+ session.releaseTransfer(identity)++ identity = session.acquireTransfer(FILE_HASH, 1234)+ session.releaseTransfer(identity)+++async def test_step_submits_deduplicated_task_filename(monkeypatch, tmp_path):+ fakeClient = FakeClient()+ session = session_module.ED2kSession()+ session._client = fakeClient+ monkeypatch.setattr(session_module, "ed2kSession", session)+ task = makeTask(tmp_path)++ await task.steps[0].run(lambda _: None, None)++ submittedLink, submittedFolder = fakeClient.added[0]+ assert parseEd2kLink(submittedLink)[0] == "payload(1).bin"+ assert submittedFolder == tmp_path+ assert fakeClient.paused == [FILE_HASH]+ assert not session._activeTransfers+++async def test_parser_rejects_active_duplicate_on_add_task_page(monkeypatch, tmp_path):+ session = session_module.ED2kSession()+ identity = session.acquireTransfer(FILE_HASH, 1234)+ monkeypatch.setattr(session_module, "ed2kSession", session)++ with pytest.raises(TaskError, match="该 eD2k 链接已在下载中"):+ await ED2kParser().parse(TaskOptions(url=LINK, outputFolder=tmp_path))++ session.releaseTransfer(identity)+++async def test_active_duplicate_never_reaches_daemon(monkeypatch, tmp_path):+ fakeClient = FakeClient()+ session = session_module.ED2kSession()+ session._client = fakeClient+ identity = session.acquireTransfer(FILE_HASH, 1234)+ monkeypatch.setattr(session_module, "ed2kSession", session)+ task = makeTask(tmp_path)++ with pytest.raises(TaskError, match="该 eD2k 链接已在下载中"):+ await task.steps[0].run(lambda _: None, None)++ assert fakeClient.added == []+ session.releaseTransfer(identity)+++async def test_transfer_exists_does_not_remove_first_download(monkeypatch, tmp_path):+ class DuplicateClient(FakeClient):+ async def addLink(self, link: str, outputDir: Path) -> Transfer:+ raise Error(ErrorCode.TRANSFER_EXISTS, "transfer already exists")++ fakeClient = DuplicateClient()+ session = session_module.ED2kSession()+ session._client = fakeClient+ monkeypatch.setattr(session_module, "ed2kSession", session)+ task = makeTask(tmp_path)++ with pytest.raises(TaskError, match="该 eD2k 传输已存在于 daemon 中"):+ await task.steps[0].run(lambda _: None, None)++ assert fakeClient.removed == []+ assert not session._activeTransfersdiff --git a/tests/test_peer_fields.py b/tests/test_peer_fields.pynew file mode 100644index 00000000..184e2756--- /dev/null+++ b/tests/test_peer_fields.py@@ -0,0 +1,27 @@+from types import SimpleNamespace++from app.models.task import TaskStatus+from features.bittorrent_pack.cards import BT_PEERS_FIELD, BTTaskCard+from features.ed2k_pack.cards import ED2K_PEERS_FIELD, ED2kTaskCard+++def test_ed2k_task_card_displays_active_and_total_peers():+ task = SimpleNamespace(activePeerCount=2, totalPeerCount=10)++ assert ED2K_PEERS_FIELD in ED2kTaskCard.infoFields+ assert ED2K_PEERS_FIELD.icon.value == "Info"+ assert ED2K_PEERS_FIELD.formats[TaskStatus.RUNNING](task, 0, 0) == "2/10 Peers"+++def test_ed2k_peer_field_hides_for_an_older_daemon():+ task = SimpleNamespace(activePeerCount=None, totalPeerCount=10)++ assert ED2K_PEERS_FIELD.formats[TaskStatus.RUNNING](task, 0, 0) is None+++def test_bt_task_card_displays_connected_and_known_peers():+ task = SimpleNamespace(peerCount=3, totalPeerCount=17)++ assert BT_PEERS_FIELD in BTTaskCard.infoFields+ assert BT_PEERS_FIELD.icon.value == "Info"+ assert BT_PEERS_FIELD.formats[TaskStatus.RUNNING](task, 0, 0) == "3/17 Peers"diff --git a/tests/test_task_error_translation.py b/tests/test_task_error_translation.pynew file mode 100644index 00000000..bfc2c250--- /dev/null+++ b/tests/test_task_error_translation.py@@ -0,0 +1,83 @@+from PySide6.QtCore import QTranslator++from app.view.error_catalog import toLocalizedError+++class TaskErrorTranslator(QTranslator):+ translations = {+ "该种子已在下载中": "This torrent is already being downloaded",+ "该 eD2k 链接已在下载中": "This eD2k link is already being downloaded",+ }++ def translate(self, context, sourceText, disambiguation=None, n=-1):+ if context == "TaskErrors":+ return self.translations.get(sourceText, "")+ return ""+++def test_task_error_translation_uses_shared_catalog(qapp):+ translator = TaskErrorTranslator()+ qapp.installTranslator(translator)+ try:+ assert toLocalizedError("该种子已在下载中") == (+ "This torrent is already being downloaded"+ )+ assert toLocalizedError("该 eD2k 链接已在下载中") == (+ "This eD2k link is already being downloaded"+ )+ assert toLocalizedError("uncatalogued external error") == (+ "uncatalogued external error"+ )+ finally:+ qapp.removeTranslator(translator)+++def test_add_task_popup_translates_parse_error(monkeypatch):+ from app.view.dialogs import task_draft as draft_module++ captured = {}++ class Dialog:+ def _refreshStats(self):+ pass++ def tr(self, text):+ return text++ def capture(*args, **kwargs):+ captured["content"] = args[1]++ monkeypatch.setattr(draft_module, "toLocalizedError", lambda _: "translated error")+ monkeypatch.setattr(draft_module.InfoBar, "error", capture)++ draft_module.TaskDraftDialog._onParseFailed(Dialog(), "ed2k://example", "source error")++ assert captured["content"] == "ed2k://example\ntranslated error"+++def test_edit_task_popup_translates_parse_error(monkeypatch):+ from app.view.dialogs import edit_task as edit_module++ captured = {}++ class Dialog:+ _pendingParseId = "pending"++ def _setInteractive(self, enabled):+ self.enabled = enabled++ def tr(self, text):+ return text++ def capture(*args, **kwargs):+ captured["content"] = kwargs["content"]++ dialog = Dialog()+ monkeypatch.setattr(edit_module, "toLocalizedError", lambda _: "translated error")+ monkeypatch.setattr(edit_module.InfoBar, "error", capture)++ edit_module.LiveEditDialog._onReparseFailed(dialog, "source error")++ assert captured["content"] == "translated error"+ assert dialog._pendingParseId == ""+ assert dialog.enabled is True