This API provides functionality to retrieve information about YouTube videos, download videos, and manage downloaded files on the server.
Important
Use this repo as a Backend/Server for your Front-end Application.
-
Can download YouTube videos in the highest possible quality to the lowest possible quality.
-
YouTube allows us to download 2160p video without audio. Still, in case the downloaded 2160p video has audio, the API combines the video (without audio) and audio separately using ffmpeg.
-
Similarly, YouTube allows us to download 1080p video without audio. If the downloaded 1080p video has audio, the API combines the video (without audio) and audio separately using ffmpeg.
-
Before hitting any endpoints in the API, always use
encodeURIComponent()
for the URL. The:yt_link
parameter must be encoded usingencodeURIComponent()
. -
When hitting the endpoint
/video-download/:yt_link
, send{"quality":"2160p"}
from the front-end to specify the desired video quality. -
When hitting the endpoint
/:filePath
, send{"fileName":"output.mp4"}
from the front-end to specify the desired video file name.
Endpoint | Method | Description |
---|---|---|
/video-info/:yt_link |
GET | Retrieve information about a YouTube video. |
/video-download/:yt_link |
POST | Download a YouTube video to the server. |
/:filePath |
POST | Serve the downloaded video to the client. |
GET /api/items/${id}
Retrieve information about a YouTube video, including title, duration, and thumbnails.
yt_link
: YouTube video link (URL-encoded using encodeURIComponent())
Returns a JSON object containing video information and available download options.
POST /video-download/:yt_link
Download a YouTube video to the server. Include an object in the request body with the desired video quality.
yt_link
: YouTube video link (must be URL-encoded using encodeURIComponent())- Request Body:
{ "quality": "your_quality_choice" }
Returns a JSON object with information about the downloaded video, including quality, file path, and file name.
GET /:filePath
Serve the downloaded video to the client. The server deletes the downloaded files after the download is complete or encounters an error. Include an object in the request body with the desired video file name.
filePath
: Path to the downloaded video file (already URL-encoded using encodeURIComponent())
// Example request using axios
const axios = require('axios');
// Get Video Information
axios.get('/video-info/:yt_link')
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error(error);
});
// Download YouTube Video
axios.post('/video-download/:yt_link', { "quality": "your_quality_choice" })
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error(error);
});
// Serve Downloaded Video
axios.get('/:filePath')
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error(error);
});
The provided code in routes.js implements the functionality of the API using Express, ytdl-core, and other libraries. The code includes error handling and cleanup procedures to manage downloaded files on the server.
Feel free to adapt the code and integrate it into your project.
Feel free to use and modify this content as needed. If you have any further changes or additions, let me know!