Skip to content

Commit

Permalink
Add TLMC folder name format (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
the1812 committed Sep 1, 2021
1 parent 350e302 commit 594ea68
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 7 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"Matthiola",
"ORIGINALYEAR",
"STREAMINFO",
"TLMC",
"TRACKNUMBER",
"TSOA",
"Violetium",
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ npm install -g touhou-tagger
```powershell
thtag
```
启动后会询问专辑名称, 如果留空直接回车就取文件夹的名字; 如果按照这个名称没有**精确匹配**的专辑(**精确匹配**在 THBWiki 中表现为输入到搜索框回车能直接跳转到词条), 则会列出以此名称在 THBWiki 中的搜索结果, 可以继续选择一项作为专辑信息. (有精确匹配的话会直接开始下载专辑信息)
启动后会询问专辑名称, 默认情况下自动取当前文件夹的名字, 如果检测到 TLMC 的命名格式则会提取其中的专辑名, 按回车表示接受自动提取的专辑名, 也可以自行输入专辑名称再按回车.

如果最后输入的名称没有**精确匹配**的专辑(**精确匹配**在 THBWiki 中表现为输入到搜索框回车能直接跳转到词条), 则会列出以此名称在 THBWiki 中的搜索结果, 可以继续选择一项作为专辑信息. (有精确匹配的话会直接开始下载专辑信息)

<details><summary><strong>图片示例</strong></summary>
<div>
Expand Down Expand Up @@ -118,7 +120,9 @@ thtag -l -t mixed
### 禁止交互
不做任何询问, 按照理想行为运行到底, 例如:
- 专辑名称不再询问, 直接取文件夹的名称
- 根据文件夹名称搜索不到/搜索到多个专辑时: 直接判为失败并退出
- 根据文件夹名称搜索:
- 搜索不到专辑时: 判为失败并退出
- 搜索到多个专辑时: 只有一个结果就取这个结果, 否则判为失败并退出
```powershell
thtag -I
```
Expand Down
27 changes: 27 additions & 0 deletions dist/cli/default-album-name.js
Original file line number Diff line number Diff line change
@@ -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;
};
4 changes: 2 additions & 2 deletions dist/cli/index.js
Original file line number Diff line number Diff line change
@@ -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'));
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
30 changes: 30 additions & 0 deletions src/cli/default-album-name.ts
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 2 additions & 2 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Expand All @@ -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)
Expand Down

0 comments on commit 594ea68

Please sign in to comment.