spotify-to-ytmusic
Advanced tools
Comparing version 1.0.4 to 1.0.5
43
index.js
const YoutubeMusic = require('youtube-music-api') | ||
const SpotifyAPI = require('spotify-web-api-node') | ||
function SpotifyToYoutubeMusic(spotifyAPI) { | ||
async function SpotifyToYoutubeMusic({ clientID, clientSecret }) { | ||
//SPOTIFY API NOT PROVIDED | ||
//CHECK CLIENT ID & CLIENT SECRET | ||
if (!spotifyAPI) return console.error('\x1b[33m%s\x1b[0m','\nYou need to provide an instance of "spotify-web-api-node"\n') | ||
if (!clientID || !clientSecret) { | ||
console.error('\x1b[33m%s\x1b[0m','\nYou need to provide a Client ID & Client Secret\n') | ||
return null | ||
} | ||
//YOUTUBE MUSIC SETUP | ||
//SPOTIFY API SETUP | ||
const spotifyAPI = new SpotifyAPI({ | ||
clientId: clientID, | ||
clientSecret: clientSecret | ||
}) | ||
spotifyAPI.setAccessToken((await spotifyAPI.clientCredentialsGrant()).body.access_token) | ||
//YOUTUBE MUSIC API SETUP | ||
const ytMusic = new YoutubeMusic() | ||
@@ -16,3 +29,3 @@ let ytMusicStatus = false | ||
return async function get(spotifyTrack) { | ||
return async function get(spotifyID) { | ||
@@ -26,8 +39,15 @@ //CHECK YOUTUBE MUSIC STATUS | ||
//CHECK IF URL IS ARRAY | ||
//CHECK IF ID IS PROVIDED | ||
if (!spotifyID || spotifyID === '') { | ||
console.error('\x1b[33m%s\x1b[0m','\nYou need to provide a Spotify Track!\n') | ||
return null | ||
} | ||
//CHECK IF ID IS ARRAY | ||
let isArray = true | ||
if (!Array.isArray(spotifyTrack)) { | ||
spotifyTrack = [spotifyTrack] | ||
if (!Array.isArray(spotifyID)) { | ||
spotifyID = [spotifyID] | ||
isArray = false | ||
@@ -38,3 +58,3 @@ } | ||
const IDs = spotifyTrack.map(track => track | ||
const IDs = spotifyID.map(track => track | ||
.replace('spotify:track:','') | ||
@@ -47,2 +67,7 @@ .replace('https://open.spotify.com/track/','') | ||
if (tracks[0] === null) { | ||
console.error('\x1b[33m%s\x1b[0m','\nOnly Spotify Tracks are supported!\n') | ||
return null | ||
} | ||
//GET SONG(S) | ||
@@ -49,0 +74,0 @@ |
{ | ||
"name": "spotify-to-ytmusic", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Convert songs from Spotify to YouTube Music!", | ||
@@ -10,3 +10,4 @@ "main": "index.js", | ||
"dependencies": { | ||
"youtube-music-api": "^1.0.6" | ||
"youtube-music-api": "^1.0.6", | ||
"spotify-web-api-node": "^5.0.2" | ||
}, | ||
@@ -22,3 +23,6 @@ "repository": { | ||
"spotoyt", | ||
"youtube-music" | ||
"youtube-music", | ||
"youtube-music-api", | ||
"spotify-to-youtube", | ||
"spotify-to-yt" | ||
], | ||
@@ -25,0 +29,0 @@ "author": "gox", |
@@ -1,11 +0,9 @@ | ||
# Spotify to YouTube Music | ||
## v1.0.5 Changelog | ||
Convert songs from **Spotify** to **YouTube Music**! | ||
> The authentication is now handled by **spotify-to-ytmusic**, only using a **Client ID** & **Client Secret**, the previously required **Redirect URI** & **Access Token** are not needed anymore. | ||
## Installation | ||
To use this package, you also need to install **[spotify-web-api-node](https://www.npmjs.com/package/spotify-web-api-node)**. | ||
```bash | ||
npm install spotify-to-ytmusic spotify-web-api-node | ||
npm install spotify-to-ytmusic | ||
``` | ||
@@ -15,39 +13,29 @@ | ||
Before using **Spotify to YouTube Music**, you need to setup a **Spotify API client**. | ||
- To use **Spotify to YouTube Music**, first you need to provide your **Spotify Credentials** (**[Client ID & Client Secret](https://www.avermedia.com/us/creator_central_spotify)**), in order to have access to the **Spotify API**. | ||
- You can only provide **Spotify Tracks** *(Playlists / Albums / Podcasts are not supported)* | ||
## Example | ||
```javascript | ||
const SpotifyToYoutubeMusic = require('spotify-to-ytmusic') | ||
const SpotifyWebApi = require('spotify-web-api-node') | ||
// Use your Client ID, Client Secret & Redirect URI | ||
async function example() { | ||
const spotifyApi = new SpotifyWebApi({ | ||
clientId: 'CLIENT_ID', | ||
clientSecret: 'CLIENT_SECRET', | ||
redirectUri: 'REDIRECT_URI' | ||
}) | ||
// Set Spotify Credentials | ||
// Or use an Access Token | ||
const spotifyToYoutubeMusic = await SpotifyToYoutubeMusic({ | ||
clientID: "CLIENT_ID", | ||
clientSecret: "CLIENT_SECRET" | ||
}) | ||
const spotifyApi = new SpotifyWebApi() | ||
spotifyApi.setAccessToken('ACCESS_TOKEN') | ||
``` | ||
// Convert a Spotify Track | ||
Now using the **spotifyApi**, we can convert songs from **Spotify** to **YouTube Music**. | ||
```javascript | ||
// Setup spotify-to-ytmusic | ||
let spotifyToYoutubeMusic = SpotifyToYoutubeMusic(spotifyApi) | ||
// Convert Spotify song to YouTube Music | ||
async function convert() { | ||
let song = await spotifyToYoutubeMusic('4cOdK2wGLETKBW3PvgPWqT') | ||
console.log(song) // https://www.youtube.com/watch?v=lYBUbBu4W08 | ||
} | ||
convert() | ||
example() | ||
``` | ||
Other ways to provide a **Spotify Track ID**. | ||
*Other ways to provide a **Spotify Track**:* | ||
@@ -61,3 +49,3 @@ ```javascript | ||
await spotifyToYoutubeMusic(['4cOdK2wGLETKBW3PvgPWqT','1UKoB3dGXJlRHFx1EJuMds']) | ||
await spotifyToYoutubeMusic(['4cOdK2wGLETKBW3PvgPWqT','06JvOZ39sK8D8SqiqfaxDU']) | ||
``` | ||
@@ -67,2 +55,2 @@ | ||
This system is not 100% perfect, and sometimes will not get the right song from YouTube Music. | ||
This system is not 100% perfect, and sometimes will not get the right song(s) from YouTube Music. |
5282
65
2
53
+ Addedspotify-web-api-node@^5.0.2
+ Addedasynckit@0.4.0(transitive)
+ Addedcall-bind-apply-helpers@1.0.2(transitive)
+ Addedcall-bound@1.0.3(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcomponent-emitter@1.3.1(transitive)
+ Addedcookiejar@2.1.4(transitive)
+ Addeddebug@4.4.0(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addeddunder-proto@1.0.1(transitive)
+ Addedes-define-property@1.0.1(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.1.1(transitive)
+ Addedes-set-tostringtag@2.1.0(transitive)
+ Addedfast-safe-stringify@2.1.1(transitive)
+ Addedform-data@3.0.3(transitive)
+ Addedformidable@1.2.6(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.3.0(transitive)
+ Addedget-proto@1.0.1(transitive)
+ Addedgopd@1.2.0(transitive)
+ Addedhas-symbols@1.1.0(transitive)
+ Addedhas-tostringtag@1.0.2(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedmath-intrinsics@1.1.0(transitive)
+ Addedmethods@1.1.2(transitive)
+ Addedmime@2.6.0(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedms@2.1.3(transitive)
+ Addedobject-inspect@1.13.4(transitive)
+ Addedqs@6.14.0(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsemver@7.7.1(transitive)
+ Addedside-channel@1.1.0(transitive)
+ Addedside-channel-list@1.0.0(transitive)
+ Addedside-channel-map@1.0.1(transitive)
+ Addedside-channel-weakmap@1.0.2(transitive)
+ Addedspotify-web-api-node@5.0.2(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedsuperagent@6.1.0(transitive)
+ Addedutil-deprecate@1.0.2(transitive)