-
Notifications
You must be signed in to change notification settings - Fork 0
/
fkg-scan-story-and-download.js
62 lines (60 loc) · 2.26 KB
/
fkg-scan-story-and-download.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const ThreadPool = require('./lib/threadpool.js')
const download = require('./lib/download.js')
const getFileList = require('./lib/getFileList')
const MD5 = require('./lib/md5.js')
const fs = require('fs')
const pool = new ThreadPool(20);
let errorUrls = []
pool.step = () => console.log(`Running: ${ pool.running }, downloaded: ${ pool.counter } / ${ pool.sum }, ${ pool.status() }`)
pool.finish(() => {
fs.writeFileSync('error.log', JSON.stringify(errorUrls))
console.log('finished')
})
!(async function main() {
const scenes = getFileList('hscene_r18', true)
Promise.all(scenes.map(scene => {
return new Promise(resolve => {
fs.readFile(scene, 'utf-8', (err, text) =>{
let messages = text.replace(/\r\n/g, '\n').split('\n')
for (let i = 0; i < messages.length; i) {
let words = messages[i].split(',')
let type = 'voice'
// remove blank messages
if (words.length < 2) {
continue
}
let fileToDownload = undefined
switch (words[0]) {
case 'mess':
fileToDownload = words[3]
break;
case 'image':
fileToDownload = words[1]
type = 'cg'
break;
default:
break;
}
if (fileToDownload) {
let charaId = fileToDownload.split('/')[0]
let file = fileToDownload.split('/')[1]
if (type === 'voice') {
pool.add(fn => {
let url = `http://dugrqaqinbtcq.cloudfront.net/product/ynnFQcGDLfaUcGhp/assets/voice/c`
`/${charaId}/${ MD5(file) }.mp3?2333`;
return download(url, `./voice/${charaId}/${file}.mp3`, () => fn(pool)).catch(url => errorUrls.push(url));
})
} else {
pool.add(fn => {
let url = `http://dugrqaqinbtcq.cloudfront.net/product/ynnFQcGDLfaUcGhp/assets/ultra/images/hscene_r18`
`/${ MD5(file) }.bin?2333`
return download(url, `./images/hscene_r18/${file}.png`, () => fn(pool)).catch(url => errorUrls.push(url));
})
}
}
resolve()
}
})
}).catch(err => console.log(err))
})).then(() => pool.run())
})()