-
Notifications
You must be signed in to change notification settings - Fork 0
/
bulk.js
39 lines (30 loc) · 1.06 KB
/
bulk.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
const fs = require('fs');
const util = require('util');
const path = require('path');
const downloadAndSaveVideo = require('./lib/download-cli');
const vimeoMetaExtractor = require('./lib/vimeo-meta');
const readFile = util.promisify(fs.readFile);
async function loadBulkConfig() {
const configFile = path.join(__dirname, '.bulkdownload');
if (!fs.existsSync(configFile)) {
console.log('No .bulkdownload file exists in the current directory');
return null;
}
const bulkConfig = JSON.parse(await readFile(configFile, 'utf8'));
return bulkConfig;
}
(async () => {
const config = await loadBulkConfig();
if (!config) return;
const { saveDirectory, videos } = config;
/* eslint-disable no-restricted-syntax, no-await-in-loop */
for (const video of videos) {
const rawVideoUrl = await vimeoMetaExtractor(video.url);
await downloadAndSaveVideo(
rawVideoUrl,
path.join(saveDirectory, video.filename),
);
}
/* eslint-enable no-restricted-syntax, no-await-in-loop */
console.log('All the files has been downloaded.');
})();