From 2e90f9fbac212014bbbd51e87ae721322903595b Mon Sep 17 00:00:00 2001 From: x1ao4 Date: Tue, 1 Jul 2025 16:59:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8B=BC=E9=9F=B3=E6=8E=92?= =?UTF-8?q?=E5=BA=8F=E4=BD=9C=E4=B8=BA=E5=85=A8=E5=B1=80=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=8E=92=E5=BA=8F=E5=87=BD=E6=95=B0=E7=9A=84=E7=AC=AC=E4=BA=94?= =?UTF-8?q?=E7=BA=A7=E6=8E=92=E5=BA=8F=E9=94=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/static/js/sort_file_by_name.js | 15 ++++++++++++++- plugins/aria2.py | 8 ++++++-- quark_auto_save.py | 20 ++++++++++++++------ 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/app/static/js/sort_file_by_name.js b/app/static/js/sort_file_by_name.js index 4be5773..c2e2708 100644 --- a/app/static/js/sort_file_by_name.js +++ b/app/static/js/sort_file_by_name.js @@ -30,6 +30,19 @@ function sortFileByName(file) { let file_name_without_ext = filename.replace(/\.[^/.]+$/, ''); let date_value = Infinity, episode_value = Infinity, segment_value = 0; + // 生成拼音排序键(第五级排序) + let pinyin_sort_key; + try { + // 尝试使用 pinyinPro 库进行拼音转换 + if (typeof pinyinPro !== 'undefined') { + pinyin_sort_key = pinyinPro.pinyin(filename, { toneType: 'none', type: 'string' }).toLowerCase(); + } else { + pinyin_sort_key = filename.toLowerCase(); + } + } catch (e) { + pinyin_sort_key = filename.toLowerCase(); + } + // 1. 日期提取 let match; // YYYY-MM-DD @@ -142,7 +155,7 @@ function sortFileByName(file) { else if (/[中][集期话部篇]?|[集期话部篇]中/.test(filename)) segment_value = 2; else if (/[下][集期话部篇]?|[集期话部篇]下/.test(filename)) segment_value = 3; - return [date_value, episode_value, segment_value, update_time]; + return [date_value, episode_value, segment_value, update_time, pinyin_sort_key]; } // 用法: diff --git a/plugins/aria2.py b/plugins/aria2.py index bf2e3f6..a1b3b7e 100644 --- a/plugins/aria2.py +++ b/plugins/aria2.py @@ -14,15 +14,19 @@ except ImportError: def sort_file_by_name(file): if isinstance(file, dict): filename = file.get("file_name", "") + update_time = file.get("updated_at", 0) else: filename = file + update_time = 0 # 简单排序,主要通过文件名进行(使用拼音排序) try: from pypinyin import lazy_pinyin, Style pinyin_list = lazy_pinyin(filename, style=Style.NORMAL, errors='ignore') - return ''.join(pinyin_list).lower() + pinyin_sort_key = ''.join(pinyin_list).lower() except ImportError: - return filename.lower() + pinyin_sort_key = filename.lower() + # 返回五级排序元组:(日期, 期数, 上中下, 修改时间, 拼音排序) + return (float('inf'), float('inf'), 0, update_time, pinyin_sort_key) def get_filename_pinyin_sort_key(filename): try: diff --git a/quark_auto_save.py b/quark_auto_save.py index da69cb6..11065f2 100644 --- a/quark_auto_save.py +++ b/quark_auto_save.py @@ -42,19 +42,27 @@ def sort_file_by_name(file): 通用的文件排序函数,用于根据文件名智能排序 支持多种格式的日期、期数、集数等提取和排序 使用多级排序键,按日期、期数、上中下顺序排序 - 如果以上均无法提取,则使用文件更新时间作为最后排序依据 + 如果以上均无法提取,则使用文件更新时间和拼音排序作为最后排序依据 """ if isinstance(file, dict) and file.get("dir", False): # 跳过文件夹 - return (float('inf'), float('inf'), float('inf'), 0) - + return (float('inf'), float('inf'), float('inf'), 0, "") + # 获取文件名,支持字符串或文件对象 if isinstance(file, dict): filename = file.get("file_name", "") - # 获取更新时间作为最后排序依据 + # 获取更新时间作为第四级排序依据 update_time = file.get("updated_at", 0) else: filename = file update_time = 0 + + # 导入拼音排序工具用于第五级排序 + try: + from app.utils.pinyin_sort import get_filename_pinyin_sort_key + pinyin_sort_key = get_filename_pinyin_sort_key(filename) + except ImportError: + # 如果导入失败,使用简单的小写排序作为备用 + pinyin_sort_key = filename.lower() # 提取文件名,不含扩展名 file_name_without_ext = os.path.splitext(filename)[0] @@ -212,8 +220,8 @@ def sort_file_by_name(file): elif re.search(r'下[集期话部篇]?|[集期话部篇]下', filename): segment_value = 3 - # 返回多级排序元组,加入更新时间作为第四级排序键 - return (date_value, episode_value, segment_value, update_time) + # 返回多级排序元组,加入更新时间作为第四级排序键,拼音排序作为第五级排序键 + return (date_value, episode_value, segment_value, update_time, pinyin_sort_key) # 全局的剧集编号提取函数