spotify-to-yt
v1.1.1
Published
Simple package to get information from Spotify and convert it to YouTube, you can use it in your music module so that your bot can easily play Spotify tracks and playlists, as well as URL's validation systems.
Downloads
27
Maintainers
Readme
spotify-to-yt
Simple package to get information from Spotify and convert it to YouTube, you can use it in your music module so that your bot can easily play Spotify tracks and playlists, as well as URL's validation systems.
Features
- Very easy to use system
- Multiple functions to use
- Works with ALL current music modules
Why spotify-to-yt?
spotify-to-yt is the only package with such useful and very easy to use methods. I made this package because I saw people trying to create music robots with Spotify, but they couldn't do it because they had no experience in it, so here I bring you a very good solution. Simple and easy to use. Works from NodeJS v12 onwards!
Changelogs
v1.0.8 - v1.0.9 - v1.1.0
- We go back to JavaScript, some errors do not allow it to work correctly.
v1.0.7
- Package export errors have been fixed.
v1.0.6
- The package has been changed to TypeScript, it still works with JavaScript correctly.
v1.0.5
- Fixed a bug in the trackSearch method that returned undefined.
- Fixed errors in README.md
v1.0.4
- Added info result by requiring most results.
v1.0.3
- Added method trackSearch, to search for tracks on Spotify
v1.0.2
- Errors in README.md
v1.0.1
- Errors in README.md
📂 | Install
npm install spotify-to-yt@latest
📜 | Setup:
const spotifyToYT = require("spotify-to-yt")
📥 | Methods
trackGet
spotifyToYT.trackGet("<URL of Spotify track or Spotify Name Song>")
Returns a YouTube URL to play music with the "play" property of your preferred music npm.
📌 | How to use:
- URL of Spotify track or Spotify Name Song: URL of the Spotify track or the song name of the same
✍ | Example with Distube Module:
const Discord = require("discord.js") //Define Discord
const client = new Discord.Client() //Define client
const Distube = require("distube") //Define Distube
client.distube = new Distube(client, { searchSongs: 10 }) //Define Distube Client
const spotifyToYT = require("spotify-to-yt") //Define package
const settings = {
prefix: "!", //Define bot prefix
token: "Discord Bot Token" //Define bot token
}
client.on('message', async message => { //Create message event
const args = message.content.slice(settings.prefix.length).trim().split(/ +/g) //Define args
const command = args.shift().toLowerCase() //Define command
if (command === "play") { //Create new command
const track = args.join(" ") //Define URL
const result = await spotifyToYT.trackGet(track) //Obtain Spotify Track Info and YouTube link URL
client.distube.play(message, result.url).catch(e => console.error(e)) //Play music with message parameter and result constant
}
})
client.login(settings.token) //Login bot
playListGet
spotifyToYT.playListGet("<URL of Spotify Playlist>")
Returns an Array of YouTube music URL's to play a playlist with your preferred music npm.
📌 | How to use:
- URL of Spotify Playlist: Spotify playlist URL
✍ | Example with Distube Module:
const Discord = require("discord.js") //Define Discord
const client = new Discord.Client() //Define client
const Distube = require("distube") //Define Distube
client.distube = new Distube(client, { searchSongs: 10 }) //Define Distube Client
const spotifyToYT = require("spotify-to-yt") //Define package
const settings = {
prefix: "!", //Define bot prefix
token: "Discord Bot Token" //Define bot token
}
client.on('message', async message => { //Create message event
const args = message.content.slice(settings.prefix.length).trim().split(/ +/g) //Define args
const command = args.shift().toLowerCase() //Define command
if (command === "playlist") { //Create new command
const playlist = args.join(" ") //Define URL
const result = await spotifyToYT.playListGet(playlist) //Obtain YouTube link of Spotify
client.distube.playCustomPlaylist(message, result.songs, { name: result.info.name, thumbnail: result.info.images[0].url, url: result.info.externals_url.spotify }).catch(e => console.error(e)) //Play playlist with message parameter, and get YouTube links of Spotify in Array
}
})
client.login(settings.token) //Login bot
isTrackOrPlaylist
spotifyToYT.isTrackOrPlaylist("<URL of Spotify Playlist or URL of Spotify Track>")
Returns a String, if it is a playlist or a track
📌 | How to use:
- URL of Spotify Playlist or URL of Spotify Track: URL of Spotify playlist or Spotify track
✍ | Example:
const Discord = require("discord.js") //Define Discord
const client = new Discord.Client() //Define client
const spotifyToYT = require("spotify-to-yt") //Define package
const settings = {
prefix: "!", //Define bot prefix
token: "Discord Bot Token" //Define bot token
}
client.on('message', async message => { //Create message event
const args = message.content.slice(settings.prefix.length).trim().split(/ +/g) //Define args
const command = args.shift().toLowerCase() //Define command
if (command === "track-or-playlist") { //Create new command
const url = args.join(" ") //Define URL
const result = await spotifyToYT.isTrackOrPlaylist(url) //Obtain YouTube link of Spotify
message.channel.send("The link is: **" + result + "**") //Send message
}
})
client.login(settings.token) //Login bot
validateURL
spotifyToYT.validateURL("<URL>")
Validate a URL from Spotify and return a Boolean as the result
📌 | How to use:
- URL: URL to validate
✍ | Example:
const Discord = require("discord.js") //Define Discord
const client = new Discord.Client() //Define client
const spotifyToYT = require("spotify-to-yt") //Define package
const settings = {
prefix: "!", //Define bot prefix
token: "Discord Bot Token" //Define bot token
}
client.on('message', async message => { //Create message event
const args = message.content.slice(settings.prefix.length).trim().split(/ +/g) //Define args
const command = args.shift().toLowerCase() //Define command
if (command === "validate-url") { //Create new command
const validate = await spotifyToYT.validateURL(args.join(" ")) //Validate Spotify URL
const result = validate ? "Valid link" : "Invalid Link" //Make a conditional, where if it returns true, the first parameter is executed, otherwise the second is executed
message.channel.send("This link is: **" + result + "**") //Send message
}
})
client.login(settings.token) //Login bot
trackSearch
spotifyToYT.trackSearch("<Term to Search>")
Search track on Spotify and return URL
📌 | How to use:
- Term to Search: Term to search on Spotify
✍ | Example:
const Discord = require("discord.js") //Define Discord
const client = new Discord.Client() //Define client
const spotifyToYT = require("spotify-to-yt") //Define package
const settings = {
prefix: "!", //Define bot prefix
token: "Discord Bot Token", //Define bot token
clientID: "Client Spotify App ID", //Define Spotify Client ID, obtain of 'https://developer.spotify.com/dashboard/'
secretKey: "Secret Key Spotify App" //Define Secret Key, obtain of 'https://developer.spotify.com/dashboard/'
}
spotifyToYT.setCredentials(settings.clientID, settings.secretKey) //Set credentials for method 'trackSearch'
client.on('message', async message => { //Create message event
const args = message.content.slice(settings.prefix.length).trim().split(/ +/g) //Define args
const command = args.shift().toLowerCase() //Define command
if (command === "spotify-search") { //Create new command
const result = await spotifyToYT.trackSearch(args.join(" ")).catch(e => message.channel.send("No results")) //Declare result, with trackSearch property, and catch for errors
message.channel.send(result.url) //Send message with URL of Spotify
}
})
client.login(settings.token) //Login bot
❓ | Do you need more help?
If you have problems with the package, but I don't think you have them, this package is very easy to use, but just in case, here is my Discord server, for support.
https://discord.gg/R8NKJHxuyh
🔧 | Creator
Yeral_Andre | Yeral_Andre#0001