All music lovers in Russia have been looking forward to the launch of Spotify on our market. When this finally happened, users were faced with the problem of transferring music from other services. Personally, over the years, I have accumulated a huge collection of music on different platforms: Yandex.Music, VKontakte, a personal collection on a hard drive and a cloud on Yandex.Disk.
At first I thought of using services like Soundiiz and TuneMyMusic. But inspired by an article on using Python for the same purpose , I became interested in solving this problem using Javascript. Next, I will describe a series of simple steps with source code to help you transfer your music from different sources to Spotify.
So, to get started, we need three things: Node.js, the Google Chrome browser, and script sources .
And install dependencies, of course.
Go to the root of the project and execute the command:
npm i
Is it done?
Ok, let's move on.
First of all, we need to get a list of tracks.
, , .
, .
.
In contact with
Over the years of using this social network, the list of tracks has been steadily replenished. I think that many have the same situation.
DOM-, . , , .
, . (F12) , src/grabTracksVk.js. Enter.
.
.
, , . , , .. .
API. DOM- .
: https://yandex.ru/dev/disk/poligon
" OAuth ".
src/grabTracksYandexDisk.js.
const token = ''
.
:
const token = 'AgAAAAACbokuAADL45FDSww2d3SDSffddwAAAAA';
, , , , , . onlyArtist, true.
:
node ./src/grabTracksYandexDisk.js
collection-yandex-disk.txt.
. API ( ):
https://cloud-api.yandex.net/v1/disk/resources/files
media type, .
. , . , , , Spotify ( ) .
β , , .
, src/grabTracksFileSystem.js.
const rootPath = ''
, .
:
const rootPath = 'D:/Music/Metal';
.
mask . .
:
const mask = ['.mp3', '.flac'];
onlyArtist , . , , true.
:
node ./src/grabTracksFileSystem.js
collection-fs.txt.
.
. . API, , , DOM-. , DOM- 150 , . , .
( ):
, , DOM- . , .
, send XMLHttpRequest.
. β . β !
, :
., " " β , " " β (, ). .
, src/grabTracksYandexMusic Enter.
.
.
P.S.: .
, .
Apple Music
, , . DOM, . , . , ..
, , . , src/grabTracksAppleMusic.js.
.
Spotify
, , Spotify.
Spotify API . . .
: https://developer.spotify.com/dashboard
"Create an app", . . Client ID Client Secret.
src/getSpotifyToken.js client_id client_secret. .
redirect_uri.
"Edit settings". "Redirect URIs", http://localhost:8888/callback
. "Save" .
!
tracks.txt, , . .
:
Slaughter To Prevail - Misery Sermon
Grim Christmas - Jingle Bells
Novembers Doom - Rain
: ./src/getSpotifyToken.js. Spotify .
:
node ./src/getSpotifyToken.js
Spotify. .
: access token: < > refresh token: < >.
. , .
src/addTracksToSpotify.js.
const accessToken = ''
. :
node ./src/addTracksToSpotify.js
.
( : - , , ).
spotify-tracks-no-found.txt, Spotify .
, , ( ).
artists.txt, .
.
:
Bob Dylan
Slaughter To Prevail
Novembers Doom
, , src/addArtistsToSpotify.js.
, :
node ./src/addTracksToSpotify.js
. - , spotify-artists-no-found.txt.
!
P.S.: , .
, Ctrl + A (Cmd + A). . .
! )