-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbaidu_image.js
More file actions
58 lines (51 loc) · 1.81 KB
/
baidu_image.js
File metadata and controls
58 lines (51 loc) · 1.81 KB
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
48
49
50
51
52
53
54
55
56
57
58
const imagesJson = require('./baidu_images.json')
const fs = require('fs')
const result = {} // categoryName, idList
const map = {} // id: name
const originList = imagesJson.bsResult.data
const CATEGORY_FIELDS = ['skinData', 'starData']
const convert = () => {
for (const row of originList) {
if (Array.isArray(row.bgitem)) {
handleRows(row, row.bgitem)
} else {
for (const field of CATEGORY_FIELDS) {
if (!Array.isArray(row[field])) continue
for (category of row[field]) {
for (const rows of row[field]) {
handleRows(rows, rows.list)
}
break
}
break
}
}
}
}
const handleRows = (parent, rows) => {
let index = 0
for (const r of rows) {
const categoryName = (parent.type || '') + (parent.name || '') + (parent.filewriter || '')
const img = {
id: Number(r.filename || r.dataindex),
name: (r.name || r.filewriter)
? ((r.name || '') + ' ' + (r.filewriter || ''))
: categoryName + index
}
if (img.id > 10000) continue // 过滤自定义背景图 ??
if (categoryName === '最近使用') continue
console.log(categoryName, img.name)
// console.log(img)
// if (!img.name.trim()) console.log(rows)
// if (map[img.id]) console.log(map[img.id])
map[img.id] = img.name
if (!Array.isArray(result[categoryName])) result[categoryName] = []
result[categoryName].push(img.id)
index++
}
}
convert()
// console.log(result)
// console.log(map)
fs.writeFileSync('./baidu_image_categorys.json', JSON.stringify(result))
fs.writeFileSync('./baidu_image_map.json', JSON.stringify(map))