UNPKG

discordjs-ytdl

Version:

Great module for youtube video downloader for Discord Bots

67 lines (58 loc) 3.14 kB
const YOUTUBE = require('simple-youtube-api'); const domain = require('./utils/domain'); const log = require('./utils/log'); const ytdl = require('ytdl-core'); async function rhino(connection, keyword, key){ if (!key) return log("You Didn't Write Your Youtube API Key."); let youtube = new YOUTUBE(key); var videos = await youtube.searchVideos(keyword, 1).catch(err => { throw new TypeError("Invalid API Key For Youtube Search. Don't you have? Please go https://console.developers.google.com/ and get one.\nYoutube Araması İçin Geçersiz Api Key. Api Keyiniz yok mu? https://console.developers.google.com/ adresine gidip bir tane alınız.") }) const songInfo = await ytdl.getInfo(videos[0].url.replace(/<(.+)>/g, '$1')); const song = { id: songInfo.videoDetails.video_id, url: songInfo.videoDetails.video_url }; const dispatcher = await connection.play(ytdl(song.url, { filter: 'audioonly', volume: 0.5})) dispatcher.setVolume(0.4) return dispatcher; } async function title(keyword, key){ if (!key) return log("You Didn't Write Your Youtube API Key."); let youtube = new YOUTUBE(key); var videos = await youtube.searchVideos(keyword, 1).catch(err => { throw new TypeError("Invalid API Key For Youtube Search. Don't you have? Please go https://console.developers.google.com/ and get one.\nYoutube Araması İçin Geçersiz Api Key. Api Keyiniz yok mu? https://console.developers.google.com/ adresine gidip bir tane alınız.") }) return videos[0].title; } async function channel(keyword, key) { if (!key) return log("You Didn't Write Your Youtube API Key."); let youtube = new YOUTUBE(key); var videos = await youtube.searchVideos(keyword, 1).catch(err => { throw new TypeError("Invalid API Key For Youtube Search. Don't you have? Please go https://console.developers.google.com/ and get one.\nYoutube Araması İçin Geçersiz Api Key. Api Keyiniz yok mu? https://console.developers.google.com/ adresine gidip bir tane alınız.") }) return videos[0].channel.title; } async function id(keyword, key) { if (!key) return log("You Didn't Write Your Youtube API Key."); let youtube = new YOUTUBE(key); var videos = await youtube.searchVideos(keyword, 1).catch(err => { throw new TypeError("Invalid API Key For Youtube Search. Don't you have? Please go https://console.developers.google.com/ and get one.\nYoutube Araması İçin Geçersiz Api Key. Api Keyiniz yok mu? https://console.developers.google.com/ adresine gidip bir tane alınız.") }) return videos[0].id; } var searchURL = require('./thumb/url'); function thumbnail(id) { var searchUrl = searchURL + '/vi/' + id + '/maxresdefault.jpg'; return searchUrl; } function embed(id) { var searchUrl = 'https://youtube.com/embed/' + id; return searchUrl; } module.exports.play = rhino; module.exports.id = id; module.exports.channel = channel; module.exports.title = title; module.exports.thumbnail = thumbnail; module.exports.embed = embed;