spotify-to-ytmusic
Advanced tools
Comparing version 1.0.7 to 1.0.8
26
index.js
const YoutubeMusic = require('node-youtube-music') | ||
const SpotifyAPI = require('spotify-web-api-node') | ||
async function SpotifyToYoutubeMusic({ clientID, clientSecret }) { | ||
async function SpotifyToYoutubeMusic({ clientID, clientSecret, accessToken }) { | ||
// Check Client ID & Client Secret | ||
if (!clientID || !clientSecret) { | ||
console.error('\x1b[33m%s\x1b[0m','\nYou need to provide a Client ID & Client Secret\n') | ||
return null | ||
} | ||
if (!clientID) throw new Error('You need to provide a Client ID') | ||
if (!clientSecret) throw new Error('You need to provide a Client Secret') | ||
@@ -20,3 +18,4 @@ // Spotify API Setup | ||
spotifyAPI.setAccessToken((await spotifyAPI.clientCredentialsGrant()).body.access_token) | ||
if (!accessToken || accessToken === '') spotifyAPI.setAccessToken((await spotifyAPI.clientCredentialsGrant()).body.access_token) | ||
else spotifyAPI.setAccessToken(accessToken) | ||
@@ -29,6 +28,3 @@ // Get Function | ||
if (!spotifyID || spotifyID === '') { | ||
console.error('\x1b[33m%s\x1b[0m','\nYou need to provide a Spotify Track!\n') | ||
return null | ||
} | ||
if (!spotifyID || spotifyID === '') throw new Error('You need to provide a Spotify Track!') | ||
@@ -54,6 +50,3 @@ // Check if ID is array | ||
if (tracks[0] === null) { | ||
console.error('\x1b[33m%s\x1b[0m','\nOnly Spotify Tracks are supported!\n') | ||
return null | ||
} | ||
if (tracks[0] === null) throw new Error('Only Spotify Tracks are supported!') | ||
@@ -69,6 +62,3 @@ // Get Song(s) | ||
let track = tracks[i] | ||
let content = await YoutubeMusic.searchMusics(`${track.artists.map(artist => artist.name).join(' ')} ${track.name}`) | ||
if (content.length < 1) content = await YoutubeMusic.searchMusics(`${track.artists[0].name} ${track.name}`) | ||
if (content.length < 1) content = await YoutubeMusic.searchMusics(`${track.name} ${track.artists.map(artist => artist.name).join(' ')}`) | ||
if (content.length < 1) content = await YoutubeMusic.searchMusics(`${track.name} ${track.artists[0].name}`) | ||
let content = await YoutubeMusic.searchMusics(`name: ${track.name}, artists: ${track.artists.map(artist => artist.name).join(', ')}`) | ||
@@ -75,0 +65,0 @@ // Select Song |
{ | ||
"name": "spotify-to-ytmusic", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "Convert songs from Spotify to YouTube Music!", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -32,3 +32,4 @@ # Spotify to YouTube Music | ||
clientID: "CLIENT_ID", | ||
clientSecret: "CLIENT_SECRET" | ||
clientSecret: "CLIENT_SECRET", | ||
accessToken: "ACCESS_TOKEN" // Optional | ||
}) | ||
@@ -35,0 +36,0 @@ |
59
4718
45