-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfetch-sub.js
46 lines (42 loc) · 1.2 KB
/
fetch-sub.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
const { pathExist, insert, getArg, defaultLang } = require("./global");
const lang = getArg("lang") || defaultLang;
const husn = require(`./data/husn_muslim_book_${lang}.json`);
const wget = require("node-wget");
const uniqWith = require("uniq-with");
const subAudioDest = "./audio/sub/";
const delay = 3000;
pathExist(subAudioDest);
let limit;
if (getArg("mode") === "prod") {
limit = husn.length - 1;
} else {
limit = 1;
}
let i = 0;
let husnMuslimfullLocalBook = [];
let reqTimer = setInterval(() => {
if (i <= limit) {
updatedhusn = husn[i];
husn[i].children.forEach((subhusn, index) => {
wget({
url: subhusn.AUDIO,
timeout: 1000,
dest: subAudioDest,
});
updatedhusn.children[index].AUDIO_URL = subhusn.AUDIO;
updatedhusn.children[index].AUDIO =
"./audio/sub/" +
subhusn.AUDIO.slice(subhusn.AUDIO.lastIndexOf("/") + 1);
husnMuslimfullLocalBook.push(updatedhusn);
});
i++;
} else {
clearInterval(reqTimer);
uniqData = uniqWith((a, b) => a.ID === b.ID, husnMuslimfullLocalBook);
insert({
object: uniqData,
fileName: `data/after_sub_${lang}.json`,
});
console.log("fetching complete");
}
}, delay);