New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

spotify-to-ytmusic

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

spotify-to-ytmusic - npm Package Compare versions

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.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc