Skip to content

Commit

Permalink
Fix missing composer, add data normalize
Browse files Browse the repository at this point in the history
  • Loading branch information
the1812 committed Dec 17, 2019
1 parent 6869d20 commit 8c97b55
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 16 deletions.
45 changes: 38 additions & 7 deletions dist/core/metadata/thb-wiki.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,19 @@ class THBWiki {
parseRelatedRowInfo(trackInfoRow) {
const defaultInfoParser = (name) => {
return (data) => {
let textContent = data.textContent;
/*
要是这个值就是一个_, THBWiki 会转成一个警告...
例如疯帽子茶会'千年战争'中出现的编曲者就有一个_
https://thwiki.cc/%E5%8D%83%E5%B9%B4%E6%88%98%E4%BA%89%EF%BD%9Eiek_loin_staim_haf_il_dis_o-del_al
*/
const warningMatch = textContent.match(/包含无效字符或不完整,并因此在查询或注释过程期间导致意外结果。\[\[(.+)\]\]/);
if (warningMatch) {
textContent = warningMatch[1];
}
return {
name,
result: data.textContent.trim().split(',')
result: textContent.trim().split(',')
};
};
};
Expand Down Expand Up @@ -114,6 +124,19 @@ class THBWiki {
}
return action(data);
}
rowDataNormalize(rowData) {
const normalizeAction = (str) => {
return str.replace('(人物)', '');
};
for (const [key, value] of Object.entries(rowData)) {
if (typeof value === 'string') {
rowData[key] = normalizeAction(value);
}
if (Array.isArray(value)) {
rowData[key] = value.map(v => normalizeAction(v));
}
}
}
parseRow(trackNumberElement) {
const trackNumber = parseInt(trackNumberElement.textContent, 10).toString();
const trackNumberRow = trackNumberElement.parentElement;
Expand All @@ -126,25 +149,33 @@ class THBWiki {
const [comments] = infos
.filter(it => it.name === 'comments')
.map(it => it.result);
const artists = ['vocals', 'coverVocals', 'harmonyVocals', 'accompanyVocals', 'chorusVocals', 'instruments', 'remix', 'arrangers']
const arrangers = ['remix', 'arrangers']
.flatMap(name => infos
.filter(it => it.name === name)
.map(it => it.result)
.flat());
const performers = ['vocals', 'coverVocals', 'harmonyVocals', 'accompanyVocals', 'chorusVocals', 'instruments']
.flatMap(name => infos
.filter(it => it.name === name)
.map(it => it.result)
.flat());
const artists = performers.concat(arrangers);
const [composers] = infos
.filter(it => it.name === 'composers')
.map(it => it.result);
if (artists.length === 0) {
if (arrangers.length === 0) {
artists.push(...composers);
}
return {
const rowData = {
title,
artists: [...new Set(artists)].map(it => it.replace('(人物)', '')),
artists: [...new Set(artists)],
trackNumber,
comments,
lyricists: lyricists ? lyricists.map(it => it.replace('(人物)', '')) : lyricists,
composers: composers ? composers.map(it => it.replace('(人物)', '')) : composers,
lyricists,
composers,
};
this.rowDataNormalize(rowData);
return rowData;
}
async getMetadata(albumName) {
const url = `https://thwiki.cc/index.php?search=${encodeURIComponent(albumName)}`;
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.0.4",
"version": "1.0.5",
"description": "从 THBWiki 自动填写东方Project CD曲目信息.",
"main": "dist/core/index.js",
"bin": {
Expand Down
46 changes: 39 additions & 7 deletions src/core/metadata/thb-wiki.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,19 @@ export class THBWiki implements MetadataSource {
private parseRelatedRowInfo(trackInfoRow: Element): TrackParseInfo {
const defaultInfoParser = (name: string): (data: Element) => TrackParseInfo => {
return (data: Element) => {
let textContent = data.textContent!
/*
要是这个值就是一个_, THBWiki 会转成一个警告...
例如疯帽子茶会'千年战争'中出现的编曲者就有一个_
https://thwiki.cc/%E5%8D%83%E5%B9%B4%E6%88%98%E4%BA%89%EF%BD%9Eiek_loin_staim_haf_il_dis_o-del_al
*/
const warningMatch = textContent.match(/包含无效字符或不完整,并因此在查询或注释过程期间导致意外结果。\[\[(.+)\]\]/)
if (warningMatch) {
textContent = warningMatch[1]
}
return {
name,
result: data.textContent!.trim().split(',')
result: textContent.trim().split(',')
}
}
}
Expand Down Expand Up @@ -116,6 +126,19 @@ export class THBWiki implements MetadataSource {
}
return action(data)
}
private rowDataNormalize(rowData: any) {
const normalizeAction = (str: string) => {
return str.replace('(人物)', '')
}
for (const [key, value] of Object.entries(rowData)) {
if (typeof value === 'string') {
rowData[key] = normalizeAction(value)
}
if (Array.isArray(value)) {
rowData[key] = value.map(v => normalizeAction(v))
}
}
}
private parseRow(trackNumberElement: Element) {
const trackNumber = parseInt(trackNumberElement.textContent!, 10).toString()
const trackNumberRow = trackNumberElement.parentElement as HTMLTableRowElement
Expand All @@ -128,26 +151,35 @@ export class THBWiki implements MetadataSource {
const [comments] = infos
.filter(it => it.name === 'comments')
.map(it => it.result as string)
const artists = ['vocals', 'coverVocals', 'harmonyVocals', 'accompanyVocals', 'chorusVocals', 'instruments', 'remix', 'arrangers']
const arrangers = ['remix', 'arrangers']
.flatMap(name => infos
.filter(it => it.name === name)
.map(it => it.result as string[])
.flat()
)
const performers = ['vocals', 'coverVocals', 'harmonyVocals', 'accompanyVocals', 'chorusVocals', 'instruments']
.flatMap(name => infos
.filter(it => it.name === name)
.map(it => it.result as string[])
.flat()
)
const artists = performers.concat(arrangers)
const [composers] = infos
.filter(it => it.name === 'composers')
.map(it => it.result as string[])
if (artists.length === 0) {
if (arrangers.length === 0) {
artists.push(...composers)
}
return {
const rowData = {
title,
artists: [...new Set(artists)].map(it => it.replace('(人物)', '')),
artists: [...new Set(artists)],
trackNumber,
comments,
lyricists: lyricists ? lyricists.map(it => it.replace('(人物)', '')) : lyricists,
composers: composers ? composers.map(it => it.replace('(人物)', '')) : composers,
lyricists,
composers,
}
this.rowDataNormalize(rowData)
return rowData
}
async getMetadata(albumName: string) {
const url = `https://thwiki.cc/index.php?search=${encodeURIComponent(albumName)}`
Expand Down

0 comments on commit 8c97b55

Please sign in to comment.