Created
December 3, 2020 14:47
-
-
Save CSFelix/c6063d0ce7f07b898126f7f354537aa1 to your computer and use it in GitHub Desktop.
Fourth Gist in the Page: https://csfelix.github.io/includes/how-to-do-web/tube-me.html
This file contains hidden or 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
| const express = require('express'); | |
| const cors = require('cors'); | |
| const ytdl = require('ytdl-core'); | |
| const app = express(); | |
| app.use(cors()); | |
| app.listen(4000, () => { | |
| console.log('Every thing okay on the port 4000!'); | |
| }); | |
| app.get('/downloadmp3', async (req, res, next) => { | |
| try { | |
| var url = req.query.url; | |
| let title = 'audio'; | |
| await ytdl.getBasicInfo(url, { | |
| format: 'mp4' | |
| }, (err, info) => { | |
| title = info.player_response.videoDetails.title; | |
| }); | |
| 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; | |
| let title = 'video'; | |
| await ytdl.getBasicInfo(URL, { | |
| format: 'mp4' | |
| }, (err, info) => { | |
| title = info.player_response.videoDetails.title; | |
| }); | |
| res.header('Content-Disposition', `attachment; filename="${title}.mp4"`); | |
| ytdl(URL, { | |
| format: 'mp4', | |
| }).pipe(res); | |
| } | |
| catch (err) { console.error(err); } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment