diff --git a/.vscode/settings.json b/.vscode/settings.json index edcdb94..5c47c4d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,6 +6,7 @@ "Matthiola", "ORIGINALYEAR", "STREAMINFO", + "TLMC", "TRACKNUMBER", "TSOA", "Violetium", diff --git a/README.md b/README.md index 6a39d88..5a442e3 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,9 @@ npm install -g touhou-tagger ```powershell thtag ``` -启动后会询问专辑名称, 如果留空直接回车就取文件夹的名字; 如果按照这个名称没有**精确匹配**的专辑(**精确匹配**在 THBWiki 中表现为输入到搜索框回车能直接跳转到词条), 则会列出以此名称在 THBWiki 中的搜索结果, 可以继续选择一项作为专辑信息. (有精确匹配的话会直接开始下载专辑信息) +启动后会询问专辑名称, 默认情况下自动取当前文件夹的名字, 如果检测到 TLMC 的命名格式则会提取其中的专辑名, 按回车表示接受自动提取的专辑名, 也可以自行输入专辑名称再按回车. + +如果最后输入的名称没有**精确匹配**的专辑(**精确匹配**在 THBWiki 中表现为输入到搜索框回车能直接跳转到词条), 则会列出以此名称在 THBWiki 中的搜索结果, 可以继续选择一项作为专辑信息. (有精确匹配的话会直接开始下载专辑信息)
图片示例
@@ -118,7 +120,9 @@ thtag -l -t mixed ### 禁止交互 不做任何询问, 按照理想行为运行到底, 例如: - 专辑名称不再询问, 直接取文件夹的名称 -- 根据文件夹名称搜索不到/搜索到多个专辑时: 直接判为失败并退出 +- 根据文件夹名称搜索: + - 搜索不到专辑时: 判为失败并退出 + - 搜索到多个专辑时: 只有一个结果就取这个结果, 否则判为失败并退出 ```powershell thtag -I ``` diff --git a/dist/cli/default-album-name.js b/dist/cli/default-album-name.js new file mode 100644 index 0000000..91ed5e1 --- /dev/null +++ b/dist/cli/default-album-name.js @@ -0,0 +1,27 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getDefaultAlbumName = void 0; +const path_1 = require("path"); +const specialFormats = [ + { + name: 'TLMC', + regex: /^([\d\.]+)\s*(\[.+\])?\s*(.+?)\s*(\[.+\])?$/, + resolve: match => match[3], + }, + { + name: 'Default', + regex: /.+/, + resolve: match => match[0] + }, +]; +exports.getDefaultAlbumName = () => { + const currentFolder = path_1.basename(process.cwd()); + const [formatMatch] = specialFormats.map(f => { + const match = currentFolder.match(f.regex); + if (match) { + return f.resolve(match); + } + return null; + }).filter((it) => it !== null); + return formatMatch || currentFolder; +}; diff --git a/dist/cli/index.js b/dist/cli/index.js index 6bd3933..64a1006 100644 --- a/dist/cli/index.js +++ b/dist/cli/index.js @@ -1,9 +1,9 @@ #!/usr/bin/env node "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -const path_1 = require("path"); const options_1 = require("./options"); const readline_1 = require("../core/readline"); +const default_album_name_1 = require("./default-album-name"); let spinner; const runTagger = async (album) => { const ora = await Promise.resolve().then(() => require('ora')); @@ -21,7 +21,7 @@ const runTagger = async (album) => { await tagger.run(album); process.exit(); }; -const defaultAlbumName = path_1.basename(process.cwd()); +const defaultAlbumName = default_album_name_1.getDefaultAlbumName(); if (options_1.cliOptions.batch) { Promise.resolve().then(() => require('./batch')).then(({ runBatchTagger }) => { runBatchTagger(options_1.cliOptions.batch); diff --git a/package.json b/package.json index c744f34..bf5511b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "touhou-tagger", - "version": "1.2.0", + "version": "1.2.1", "description": "从 THBWiki 自动填写东方Project CD曲目信息.", "main": "dist/core/index.js", "bin": { diff --git a/src/cli/default-album-name.ts b/src/cli/default-album-name.ts new file mode 100644 index 0000000..c9172e8 --- /dev/null +++ b/src/cli/default-album-name.ts @@ -0,0 +1,30 @@ +import { basename } from 'path' + +interface SpecialFormat { + name: string + regex: RegExp + resolve: (match: RegExpMatchArray) => string +} +const specialFormats: SpecialFormat[] = [ + { + name: 'TLMC', + regex: /^([\d\.]+)\s*(\[.+\])?\s*(.+?)\s*(\[.+\])?$/, + resolve: match => match[3], + }, + { + name: 'Default', + regex: /.+/, + resolve: match => match[0] + }, +] +export const getDefaultAlbumName = () => { + const currentFolder = basename(process.cwd()) + const [formatMatch] = specialFormats.map(f => { + const match = currentFolder.match(f.regex) + if (match) { + return f.resolve(match) + } + return null + }).filter((it): it is string => it !== null) + return formatMatch || currentFolder +} diff --git a/src/cli/index.ts b/src/cli/index.ts index 05acbbf..e460eb4 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -1,8 +1,8 @@ #!/usr/bin/env node -import { basename } from 'path' import { cliOptions, metadataConfig } from './options' import { Ora } from 'ora' import { readline } from '../core/readline' +import { getDefaultAlbumName } from './default-album-name' let spinner: Ora const runTagger = async (album: string) => { @@ -22,7 +22,7 @@ const runTagger = async (album: string) => { process.exit() } -const defaultAlbumName = basename(process.cwd()) +const defaultAlbumName = getDefaultAlbumName() if (cliOptions.batch) { import('./batch').then(({ runBatchTagger }) => { runBatchTagger(cliOptions.batch)