forked from dd-center/vdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse.js
47 lines (41 loc) · 1.78 KB
/
parse.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const { v5: uuidv5 } = require('uuid')
module.exports = ({ vtbs, linkSyntax, UUID_NAMESPACE }, keepFilename = false) => ({
meta: { UUID_NAMESPACE, linkSyntax },
vtbs: vtbs
.map(({ name, object }) => ({ uuid: uuidv5(name, UUID_NAMESPACE), object, name }))
.map(({ object, ...extra }) => ({ object: { ...object, name: Object.entries(object.name || {}) }, ...extra }))
.map(({ object, ...extra }) => ({ object: { ...object, accounts: Object.entries(object.accounts || {}) }, ...extra }))
.map(({ uuid, object, name }) => {
const parsed = { uuid }
parsed.type = object.type || 'vtuber'
parsed.bot = !!object.bot
parsed.accounts = object.accounts
.map(([platform, ids]) => [platform, [ids].flat()])
.flatMap(([platform, ids]) => ids.map(id => ({ platform, id })))
.map(({ platform, id }) => typeof id === 'string' ? { platform, id: { id } } : { platform, id })
.map(({ platform, id }) => ({ ...id, type: id.type || 'official', platform }))
parsed.name = { extra: [] }
object.name
.map(([lang, name]) => typeof name === 'object' ? [lang, name] : [lang, [name]])
.forEach(([lang, names]) => names.forEach(name => {
if (parsed.name[lang]) {
parsed.name.extra.push(name)
} else {
parsed.name[lang] = name
}
}))
if (!parsed.name.default && (object.name[0] || [undefined])[0]) {
parsed.name.default = (object.name[0] || [undefined])[0]
}
if (object.group) {
parsed.group = uuidv5(object.group, UUID_NAMESPACE)
parsed.group_name = object.group
} else if (parsed.type === 'group') {
parsed.group = uuid
}
if (keepFilename) {
parsed.filename = name
}
return parsed
}),
})