-
Notifications
You must be signed in to change notification settings - Fork 4
/
youtube-dl.js
58 lines (49 loc) · 1.54 KB
/
youtube-dl.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
const downloadYoutubeDl = require('youtube-dl/lib/downloader');
const fs = require('fs');
const path = require('path');
const Promise = require('yaku/lib/yaku.core');
const Store = require('electron-store');
const store = new Store();
/**
* Download or update the youtube-dl binary
*
* @param {String} appDataDirectory The path to the app's data directory
* @return {Promise}
*/
function initialize(appDataDirectory) {
return new Promise((resolve, reject) => {
const binPath = path.join(appDataDirectory, 'bin');
downloadYoutubeDl(binPath, (err, result) => {
if (err) {
return reject(err);
}
const details = {
lastOperationResult: result,
updated: !result.includes('Already up to date '),
version: result.replace('Downloaded youtube-dl ', '').replace('Already up to date ', ''),
date: new Date()
};
store.set('youtubeDl', details);
resolve(details);
});
});
}
/**
* Get the current version of the youtube-dl binary
*
* @param {String} appDataDirectory The path to the app's data directory
* @return {Promise}
*/
function getVersion(appDataDirectory) {
return new Promise((resolve, reject) => {
if (store.has('youtubeDl')) {
return resolve(store.get('youtubeDl.version'));
}
reject('youtube-dl not downloaded yet.');
});
}
module.exports = {
initialize: initialize,
update: initialize,
getVersion: getVersion
};