@@ -67,9 +67,19 @@ export class THBWiki implements MetadataSource {
67
67
private parseRelatedRowInfo ( trackInfoRow : Element ) : TrackParseInfo {
68
68
const defaultInfoParser = ( name : string ) : ( data : Element ) => TrackParseInfo => {
69
69
return ( data : Element ) => {
70
+ let textContent = data . textContent !
71
+ /*
72
+ 要是这个值就是一个_, THBWiki 会转成一个警告...
73
+ 例如疯帽子茶会'千年战争'中出现的编曲者就有一个_
74
+ 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
75
+ */
76
+ const warningMatch = textContent . match ( / 包 含 无 效 字 符 或 不 完 整 , 并 因 此 在 查 询 或 注 释 过 程 期 间 导 致 意 外 结 果 。 \[ \[ ( .+ ) \] \] / )
77
+ if ( warningMatch ) {
78
+ textContent = warningMatch [ 1 ]
79
+ }
70
80
return {
71
81
name,
72
- result : data . textContent ! . trim ( ) . split ( ',' )
82
+ result : textContent . trim ( ) . split ( ',' )
73
83
}
74
84
}
75
85
}
@@ -116,6 +126,19 @@ export class THBWiki implements MetadataSource {
116
126
}
117
127
return action ( data )
118
128
}
129
+ private rowDataNormalize ( rowData : any ) {
130
+ const normalizeAction = ( str : string ) => {
131
+ return str . replace ( '(人物)' , '' )
132
+ }
133
+ for ( const [ key , value ] of Object . entries ( rowData ) ) {
134
+ if ( typeof value === 'string' ) {
135
+ rowData [ key ] = normalizeAction ( value )
136
+ }
137
+ if ( Array . isArray ( value ) ) {
138
+ rowData [ key ] = value . map ( v => normalizeAction ( v ) )
139
+ }
140
+ }
141
+ }
119
142
private parseRow ( trackNumberElement : Element ) {
120
143
const trackNumber = parseInt ( trackNumberElement . textContent ! , 10 ) . toString ( )
121
144
const trackNumberRow = trackNumberElement . parentElement as HTMLTableRowElement
@@ -128,26 +151,35 @@ export class THBWiki implements MetadataSource {
128
151
const [ comments ] = infos
129
152
. filter ( it => it . name === 'comments' )
130
153
. map ( it => it . result as string )
131
- const artists = [ 'vocals' , 'coverVocals' , 'harmonyVocals' , 'accompanyVocals' , 'chorusVocals' , 'instruments' , 'remix' , 'arrangers' ]
154
+ const arrangers = [ 'remix' , 'arrangers' ]
132
155
. flatMap ( name => infos
133
156
. filter ( it => it . name === name )
134
157
. map ( it => it . result as string [ ] )
135
158
. flat ( )
136
159
)
160
+ const performers = [ 'vocals' , 'coverVocals' , 'harmonyVocals' , 'accompanyVocals' , 'chorusVocals' , 'instruments' ]
161
+ . flatMap ( name => infos
162
+ . filter ( it => it . name === name )
163
+ . map ( it => it . result as string [ ] )
164
+ . flat ( )
165
+ )
166
+ const artists = performers . concat ( arrangers )
137
167
const [ composers ] = infos
138
168
. filter ( it => it . name === 'composers' )
139
169
. map ( it => it . result as string [ ] )
140
- if ( artists . length === 0 ) {
170
+ if ( arrangers . length === 0 ) {
141
171
artists . push ( ...composers )
142
172
}
143
- return {
173
+ const rowData = {
144
174
title,
145
- artists : [ ...new Set ( artists ) ] . map ( it => it . replace ( '(人物)' , '' ) ) ,
175
+ artists : [ ...new Set ( artists ) ] ,
146
176
trackNumber,
147
177
comments,
148
- lyricists : lyricists ? lyricists . map ( it => it . replace ( '(人物)' , '' ) ) : lyricists ,
149
- composers : composers ? composers . map ( it => it . replace ( '(人物)' , '' ) ) : composers ,
178
+ lyricists,
179
+ composers,
150
180
}
181
+ this . rowDataNormalize ( rowData )
182
+ return rowData
151
183
}
152
184
async getMetadata ( albumName : string ) {
153
185
const url = `https://thwiki.cc/index.php?search=${ encodeURIComponent ( albumName ) } `
0 commit comments