Skip to content

Commit 4ddc5b7

Browse files
authored
Merge pull request #231 from Ninjavin/nodejs-ytdload-ninjavin
Added-YT-Downloader-NodeJS
2 parents 9157c69 + 526c4c2 commit 4ddc5b7

File tree

6 files changed

+174
-0
lines changed

6 files changed

+174
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/node_modules
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# A Simple YouTube Video Downloader in NodeJS
2+
3+
This NodeJs Script downloads the youtube video from the url mentioned.
4+
5+
## How to Run?
6+
7+
+ Run `npm install i` in the project folder.
8+
+ Run `ytdload "<youtube-video-link>"` to download any YouTube video.
9+
> You can also run `npm install -g .` in the project folder, this will allow you to run the script from any location.
10+
11+
## Sample Input & Output
12+
13+
![image](images/ytdload.png)
Loading
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env node
2+
const fs = require('fs');
3+
const readline = require('readline');
4+
const ytdl = require('ytdl-core');
5+
const chalk = require('chalk');
6+
const figlet = require('figlet');
7+
const args = process.argv;
8+
// Download Function
9+
download = (link) => {
10+
getTime = () => {
11+
let today = new Date();
12+
let y = today.getFullYear();
13+
let m = today.getMonth() + 1;
14+
let d = today.getDate();
15+
let h = today.getHours();
16+
let mi = today.getMinutes();
17+
let s = today.getSeconds();
18+
return y + "-" + m + "-" + d + "-" + h + "-" + mi + "-" + s;
19+
}
20+
console.log(chalk.cyan("Starting download..."));
21+
ytdl(link).once('response', () => {
22+
starttime = Date.now()
23+
}).on('progress', (chunkLength, downloaded, total) => {
24+
const percent = downloaded / total;
25+
readline.cursorTo(process.stdout, 0);
26+
process.stdout.write(`${(percent * 100).toFixed(2)}% downloaded `);
27+
process.stdout.write(`(Total Download Size : ${(total / 1024 / 1024).toFixed(2)}MB)\n`);
28+
readline.moveCursor(process.stdout, 0, -1);
29+
}).on('finish', () => {
30+
console.log(chalk.greenBright("\nSuccessfully Downloaded!"))
31+
}).pipe(fs.createWriteStream(`video-${getTime()}.mp4`))
32+
}
33+
// Help Command for User
34+
help = () => {
35+
console.log(chalk.yellowBright(figlet.textSync("YouTube Downloader", function(err, data){
36+
if(err){
37+
console.log(err);
38+
}
39+
console.log(data);
40+
})))
41+
console.log(chalk.green(`Run ${chalk.yellow(`ytdload "<link-here>"`)} to download the youtube video`));
42+
}
43+
// If the user only enters ytdload
44+
if(args.length == 2){
45+
help();
46+
}else{
47+
// Getting the link entered by user
48+
const link = args[2];
49+
download(link);
50+
}

JavaScript/Youtube-Video-Downloader/package-lock.json

Lines changed: 91 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "nodejs-yt-downloader",
3+
"version": "1.0.0",
4+
"description": "`npm init`",
5+
"main": "index.js",
6+
"bin": {
7+
"ytdload": "./index.js"
8+
},
9+
"scripts": {
10+
"test": "echo \"Error: no test specified\" && exit 1"
11+
},
12+
"author": "Ninjavin",
13+
"license": "ISC",
14+
"dependencies": {
15+
"chalk": "^4.1.0",
16+
"figlet": "^1.5.0",
17+
"ytdl-core": "^4.0.2"
18+
}
19+
}

0 commit comments

Comments
 (0)