Last active
September 20, 2020 08:51
-
-
Save FelipeGrijo/7e76411f143087728268cf5478eb11c7 to your computer and use it in GitHub Desktop.
youtube-dl promisify nodejs
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
// https://gist.github.com/FelipeGrijo | |
// https://www.npmjs.com/package/youtube-dl | |
const util = require('util'); | |
const youtubedl = require('youtube-dl'); // 3.0.2 -- 2020.09.20 | |
const ytdl = util.promisify(youtubedl); | |
const videoUrl = 'http://www.youtube.com/watch?v=AQ4MQ_uhBSs'; // url ou id | |
const getMusic = async (url, formatId = 140) => { | |
try { | |
const music = await ytdl(url); | |
return { | |
id: music.id, | |
title: music.title, | |
url: music.formats.filter((e) => e.format_id === formatId.toString())[0].url, | |
thumbnail: music.thumbnail, | |
description: music.description, | |
}; | |
} catch (error) { | |
throw new Error(error); | |
} | |
}; | |
(async () => { | |
const music = await getMusic(videoUrl); | |
console.log(music); | |
})(); | |
/* info | |
{ | |
id: 'AQ4MQ_uhBSs', | |
title: 'Jonas Blue - By Your Side ft. RAYE (Official Video)', | |
url: 'https://...googlevideo.com/videoplayback?expire...', | |
thumbnail: 'https://i.ytimg.com/vi_webp/AQ4MQ_uhBSs/maxresdefault.webp', | |
description: 'Jonas Blue’s ‘The Blueprint’...' | |
} | |
*/ | |
/* audios | |
https://gist.github.com/AgentOak/34d47c65b1d28829bb17c24c04a0096f | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment