🎈 pref: 优化删除特殊符号逻辑

This commit is contained in:
zhiyu1998 2024-09-16 21:06:55 +08:00
parent 64135eae0f
commit 56333de309
2 changed files with 6 additions and 9 deletions

View File

@ -1248,7 +1248,7 @@ export class tools extends plugin {
// 获取歌曲信息 // 获取歌曲信息
let title = await axios.get(AUTO_NETEASE_SONG_DETAIL.replace("{}", id)).then(res => { let title = await axios.get(AUTO_NETEASE_SONG_DETAIL.replace("{}", id)).then(res => {
const song = res.data.songs[0]; const song = res.data.songs[0];
return `${ song?.name }-${ song?.ar?.[0].name }`.replace(/[\/\?<>\\:\*\|".… ]/g, ""); return cleanFilename(`${ song?.name }-${ song?.ar?.[0].name }`);
}); });
// 一般这个情况是VIP歌曲 (如果没有url或者是国内, 国内全走临时接口,后续如果不要删除逻辑'!isOversea ||') // 一般这个情况是VIP歌曲 (如果没有url或者是国内, 国内全走临时接口,后续如果不要删除逻辑'!isOversea ||')
if (!isOversea || url == null) { if (!isOversea || url == null) {

View File

@ -427,14 +427,11 @@ export function saveJsonToFile(jsonData, filename = "data.json") {
* @returns {string} * @returns {string}
*/ */
export function cleanFilename(filename) { export function cleanFilename(filename) {
// 去除省略号(…) // 1. 去除特殊字符
filename = filename.replace(/…/g, ''); // 2. 去除特定词汇
// 删除括号及其内容 filename = filename.replace(/[\/\?<>\\:\*\|".…《》()]/g, '')
filename = filename.replace(/\(|\)/g, ''); .replace(/电影|主题曲/g, '')
// 删除反斜杠 .trim();
filename = filename.replace(/\//g, '');
filename = filename.trim();
return filename; return filename;
} }