forked from przemyslawpluta/node-youtube-dl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresume.js
40 lines (30 loc) · 1.03 KB
/
resume.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
var youtubedl = require('..');
var fs = require('fs');
var output = 'myvideo.mp4';
var downloaded = 0;
if (fs.existsSync(output)) {
downloaded = fs.statSync(output).size;
}
var video = youtubedl('https://www.youtube.com/watch?v=179MiZSibco',
// Optional arguments passed to youtube-dl.
['--format=18'],
// start will be sent as a range header
{ start: downloaded, cwd: __dirname });
// Will be called when the download starts.
video.on('info', function(info) {
console.log('Download started');
console.log('filename: ' + info._filename);
// info.size will be the amount to download, add
var total = info.size + downloaded;
console.log('size: ' + total);
if (downloaded > 0) {
// size will be the amount already downloaded
console.log('resuming from: ' + downloaded);
// display the remaining bytes to download
console.log('remaining bytes: ' + info.size);
}
});
video.pipe(fs.createWriteStream('myvideo.mp4', { flags: 'a' }));
video.on('end', function() {
console.log('finished downloading!');
});