This repository has been archived by the owner on Dec 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding ability to continue partially downloaded files.
- Loading branch information
1 parent
2b8333f
commit e9e540a
Showing
3 changed files
with
155 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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!'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters