UNPKG

mmmdl

Version:

Multi Media Music Downloader

54 lines (53 loc) 1.59 kB
exports.youtube = async function(url) { const ytdl = require("ytdl-core"); try { await ytdl.getURLVideoID(url); } catch(err) { throw new Error("Could not find the video."); return; } const stream = await ytdl(ytdl.getURLVideoID(url), { filter: format => format.audioCodec === 'opus' && format.container === 'webm', quality: 'highest', highWaterMark: 32 * 1024 * 1024, }); return stream; } exports.spotify = async function(url, clientId, clientSecret) { if(!clientId || !clientSecret) { throw new Error("Please provide a client id and secret."); return;} const ytdl = require("ytdl-core"); const SpotifyToYoutubeMusic = require('spotify-to-ytmusic'); const spotifyToYoutubeMusic = await SpotifyToYoutubeMusic({ clientID: clientId, clientSecret: clientSecret, ytMusicUrl: true }); let musicUrl = ""; musicUrl = await spotifyToYoutubeMusic(url); const stream = await ytdl(await ytdl.getURLVideoID(musicUrl), { filter: format => format.audioCodec === 'opus' && format.container === 'webm', quality: 'highest', highWaterMark: 32 * 1024 * 1024, }); return stream; } exports.dependencyReport = function() { let content = ""; try { const ytdl = require("ytdl-core"); content = content + "ytdl-core: Ok"; } catch(err) { content = content + "ytdl-core: Not found"; } try { const SpotifyToYoutubeMusic = require('spotify-to-ytmusic'); content = content + "\n\nspotify-to-ytmusic: Ok"; } catch(err) { content = content + "\n\nspotify-to-ytmusic: Not found"; } return content; }