Skip to content

Latest commit

 

History

History
84 lines (73 loc) · 2.3 KB

CONTRIBUTING.md

File metadata and controls

84 lines (73 loc) · 2.3 KB

代码贡献指南

需要已安装 Node.js, pnpmTypeScript

安装依赖项

pnpm install

添加其他数据源

src/core/metadata/ 中添加文件 xxx.ts, 继承 MetadataSource 类:

import { MetadataSource } from './metadata-source'
import { Metadata } from './metadata'

export class XXX extends MetadataSource {
  // 搜索专辑, 返回 string 表示精确匹配, 返回 string[] 表示未找到精确匹配, 内容是根据 albumName 搜索得到的结果
  async resolveAlbumName(albumName: string): Promise<string[] | string> { /* ... */ }
  // 下载专辑信息, 返回 Metadata[], cover 如果传入现成的封面图片 Buffer, 将跳过封面下载节省时间
  async getMetadata(albumName: string, cover?: Buffer): Promise<Metadata[]> { /* ... */ }
}
export const xxx = new XXX()

然后在 src/core/metadata/source-mappings.ts 中添加对应项:

import { thbWiki } from './thb-wiki';
import { xxx } from './xxx';
import { MetadataSource } from './metadata-source';

export const sourceMappings = {
  'thb-wiki': thbWiki,
  'xxx': xxx,
} as { [type: string]: MetadataSource }

最后在 src/cli/options.ts 中添加选项:

.option('source', {
  alias: 's',
  type: 'string',
  default: 'thb-wiki',
  choices: ['thb-wiki', 'doujin-meta', 'local-mp3', 'local-json', 'xxx'],
  description: '设置数据源',
})

添加其他文件类型支持

src/core/writer/ 中添加文件 xxx-writer.ts, 继承 MetadataWriter 类:

import { MetadataWriter } from './metadata-writer'
import { Metadata } from './metadata'

export class XxxWriter extends MetadataWriter {
  // 将专辑信息写入文件
  async write(metadata: Metadata, filePath: string): Promise<void> { /* ... */ }
}
export const xxxWriter = new XxxWriter()

然后在 src/core/writer/writer-mappings.ts 中添加对应项:

import { MetadataWriter } from './metadata-writer'
import { mp3Writer } from './mp3-writer'
import { xxxWriter } from './xxx-writer'

export const writerMappings = {
  '.mp3': mp3Writer,
  '.xxx': xxxWriter,
} as { [type: string]: MetadataWriter }

编译

pnpm watch

本地版本

安装:

pnpm link --global

卸载:

pnpm remove --global touhou-tagger