Full Code of Moorad/youtubeDownloader for AI

master d66318bd6eec cached
8 files
5.3 KB
1.8k tokens
3 symbols
1 requests
Download .txt
Repository: Moorad/youtubeDownloader
Branch: master
Commit: d66318bd6eec
Files: 8
Total size: 5.3 KB

Directory structure:
gitextract_zxsqpt5b/

├── .gitignore
├── Contributors.md
├── README.md
├── Server/
│   ├── index.js
│   └── package.json
├── index.html
├── script.js
└── style.css

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================
node_modules


================================================
FILE: Contributors.md
================================================
Balaji S github URL: https://github.com/balajinikhil


================================================
FILE: README.md
================================================
# Youtube Downloader

This is a repository that has sample code for my [Medium Article](https://blog.usejournal.com/how-i-made-my-own-youtube-downloader-using-javascript-and-node-js-160b172f6e10)

## Getting Started

If there is any issues please open a new issue.

1. You need to clone this repository
```
git clone https://github.com/mooradal/youtubeDownloader
```

2. After you clone the repo you will have to navigate to the Server folder
```
cd Server
```

3. Then you will have to install all the packages and dependencies
```
npm install 
```

4. Finally you need to run it
```
node index.js
```

5. If you want to use nodemon (nodemon is a package that will auto restart the server when files are changed) you can run **(Optional)**

```
npm run dev
```
or
```
nodemon index.js
```

## Info

If there is any issues please open a new issue. You are welcome to add pull requests at anytime

Thank you so much for supporting me and thank you for almost 2,000 claps. I really appreciate that. I will try to post more articles and I'm thinking of turning this project from a sample code to an actual functional public website for everyone to use!


================================================
FILE: Server/index.js
================================================
const express = require('express');
const cors = require('cors');
const ytdl = require('ytdl-core');
const app = express();
const PORT = 4000;

app.use(cors());

app.listen(PORT, () => {
	console.log(`Server Works !!! At port ${PORT}`);
});

app.get('/downloadmp3', async (req, res, next) => {
	try {
		var url = req.query.url;
		if(!ytdl.validateURL(url)) {
			return res.sendStatus(400);
		}
		let title = 'audio';

		await ytdl.getBasicInfo(url, {
			format: 'mp4'
		}, (err, info) => {
			if (err) throw err;
			title = info.player_response.videoDetails.title.replace(/[^\x00-\x7F]/g, "");
		});

		res.header('Content-Disposition', `attachment; filename="${title}.mp3"`);
		ytdl(url, {
			format: 'mp3',
			filter: 'audioonly',
		}).pipe(res);

	} catch (err) {
		console.error(err);
	}
});

app.get('/downloadmp4', async (req, res, next) => {
	try {
		let url = req.query.url;
		if(!ytdl.validateURL(url)) {
			return res.sendStatus(400);
		}
		let title = 'video';

		await ytdl.getBasicInfo(url, {
			format: 'mp4'
		}, (err, info) => {
			title = info.player_response.videoDetails.title.replace(/[^\x00-\x7F]/g, "");
		});

		res.header('Content-Disposition', `attachment; filename="${title}.mp4"`);
		ytdl(url, {
			format: 'mp4',
		}).pipe(res);

	} catch (err) {
		console.error(err);
	}
});

================================================
FILE: Server/package.json
================================================
{
  "name": "server",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "nodemon index.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "cors": "^2.8.5",
    "express": "^4.16.4",
    "ytdl-core": "^3.1.2"
  },
  "devDependencies": {
    "nodemon": "^1.18.10"
  }
}


================================================
FILE: index.html
================================================
<!DOCTYPE html>
<html lang='en'>

<head>
	<link rel='stylesheet' href='./style.css' />
	<title>Youtube Downloader</title>
</head>

<body>
	<h1 class='heading'>Paste YouTube URL</h1>
	<input class='URL-input' placeholder='https://www.youtube.com/watch?v=MtN1YnoL46Q' />
	<select class='opt'>
		<option value='mp3'>mp3</option>
		<option value='mp4'>mp4</option>
	</select>

	<button class='convert-button' id='btn'>Convert</button>
	<script src='./script.js'></script>
</body>

</html>

================================================
FILE: script.js
================================================
let Btn = document.getElementById('btn');
let URLinput = document.querySelector('.URL-input');
let select = document.querySelector('.opt');
let serverURL = 'http://localhost:4000';

Btn.addEventListener('click', () => {
	if (!URLinput.value) {
		alert('Enter YouTube URL');
	} else {
		if (select.value == 'mp3') {
			downloadMp3(URLinput.value);
		} else if (select.value == 'mp4') {
			downloadMp4(URLinput.value);
		}
	}
});

async function downloadMp3(query) {
	const res = await fetch(`${serverURL}/downloadmp3?url=${query}`);
	if(res.status == 200) {
		var a = document.createElement('a');
  		a.href = `${serverURL}/downloadmp3?url=${query}`;
  		a.setAttribute('download', '');
		a.click();
	} else if(res.status == 400) {
		alert("Invalid url");
	}
}

async function downloadMp4(query) {
	const res = await fetch(`${serverURL}/downloadmp4?url=${query}`);
	if(res.status == 200) {
		var a = document.createElement('a');
  		a.href = `${serverURL}/downloadmp4?url=${query}`;
  		a.setAttribute('download', '');
		a.click();
	} else if(res.status == 400) {
		alert('Invalid url');
	}
}

================================================
FILE: style.css
================================================
* {
	text-align: center;
}

body {
	display: grid;
	grid-template-columns: auto;
}

.heading {
	font-family: Arial;
	margin-top: 40vh;
}

.URL-input,
.convert-button {
	font-size: 1.3em;
	padding: 5px 10px;
}

.URL-input {
	margin: auto;
	border-radius: 4px 0px 0px 4px;
	width: 30em;
	text-align: left;
	border: 2px solid #eeeeee;
	background: #eeeeee;
	outline: none;
}

.URL-input:focus {
	border: 2px solid #0485ff;
}

.convert-button {
	margin: 2% auto;
	border: 2px solid #0485ff;
	background: #0485ff;
	color: white;
	transition: 0.15s;
}

.convert-button:hover {
	background: #016acc;
	border-color: #016acc;
}

@media only screen and (max-width: 600px) {
	body {
		display: grid;
		grid-template-columns: auto;
		justify-content: center;
	}

	.URL-input {
		margin: auto;
		width: 100%;
	}

	.convert-button {
		margin: 7% auto;
		width: 100%;
	}
}

.opt {
	width: 30vw;
	margin: 2% auto;
	padding: 4px;
	border-radius: 7%;
}
Download .txt
gitextract_zxsqpt5b/

├── .gitignore
├── Contributors.md
├── README.md
├── Server/
│   ├── index.js
│   └── package.json
├── index.html
├── script.js
└── style.css
Download .txt
SYMBOL INDEX (3 symbols across 2 files)

FILE: Server/index.js
  constant PORT (line 5) | const PORT = 4000;

FILE: script.js
  function downloadMp3 (line 18) | async function downloadMp3(query) {
  function downloadMp4 (line 30) | async function downloadMp4(query) {
Condensed preview — 8 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (6K chars).
[
  {
    "path": ".gitignore",
    "chars": 13,
    "preview": "node_modules\n"
  },
  {
    "path": "Contributors.md",
    "chars": 53,
    "preview": "Balaji S github URL: https://github.com/balajinikhil\n"
  },
  {
    "path": "README.md",
    "chars": 1150,
    "preview": "# Youtube Downloader\n\nThis is a repository that has sample code for my [Medium Article](https://blog.usejournal.com/how-"
  },
  {
    "path": "Server/index.js",
    "chars": 1303,
    "preview": "const express = require('express');\nconst cors = require('cors');\nconst ytdl = require('ytdl-core');\nconst app = express"
  },
  {
    "path": "Server/package.json",
    "chars": 386,
    "preview": "{\n  \"name\": \"server\",\n  \"version\": \"1.0.0\",\n  \"description\": \"\",\n  \"main\": \"index.js\",\n  \"scripts\": {\n    \"dev\": \"nodemo"
  },
  {
    "path": "index.html",
    "chars": 484,
    "preview": "<!DOCTYPE html>\n<html lang='en'>\n\n<head>\n\t<link rel='stylesheet' href='./style.css' />\n\t<title>Youtube Downloader</title"
  },
  {
    "path": "script.js",
    "chars": 1091,
    "preview": "let Btn = document.getElementById('btn');\nlet URLinput = document.querySelector('.URL-input');\nlet select = document.que"
  },
  {
    "path": "style.css",
    "chars": 934,
    "preview": "* {\n\ttext-align: center;\n}\n\nbody {\n\tdisplay: grid;\n\tgrid-template-columns: auto;\n}\n\n.heading {\n\tfont-family: Arial;\n\tmar"
  }
]

About this extraction

This page contains the full source code of the Moorad/youtubeDownloader GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 8 files (5.3 KB), approximately 1.8k tokens, and a symbol index with 3 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!