If you create a text file for your playlist data and also a text file of your song list both in JSON form, you can use the following script to do just this:
It takes a few seconds to run when there are lots of tracks and playlists.
HTML:
<p>Please note that this will take a few seconds to run if you have a large amount of songs and playlists.</p>
<label>Song text file (generated from <a href="https://webapps.stackexchange.com/q/108103/140514">this answer</a>): <input type="file" id="songInput"></label>
<br>
<label>Playlist text file (generated from <a href="https://webapps.stackexchange.com/a/106604/140514">this answer</a>): <input type="file" id="playlistInput"></label>
<br>
<textarea style="width: 500px; height: 200px;"></textarea>
JS:
var songInput = document.getElementById("songInput"),
playlistInput = document.getElementById("playlistInput"),
result = document.querySelector("textarea");
var songList,
playlistData;
function loadData(id, elem) {
if(elem.files
&& elem.files[0]) {
let myFile = elem.files[0];
let reader = new FileReader();
reader.addEventListener('load', function (e) {
if(id === "songInput")
songList = JSON.parse(e.target.result);
if(id === "playlistInput")
playlistData = e.target.result;
checkBothAdded();
});
reader.readAsBinaryString(myFile);
}
}
function checkBothAdded() {
if(songList
&& playlistData) {
getSongPlaylistData();
}
}
/* Needed to escape song names that have (), [], etc. */
function regexEscape(s) {
return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
};
var songData = {};
function getSongPlaylistData() {
for(let song of songList) {
let playlistsItsIn = [];
/* Use regex to search the playlist file for all instances,
add the playlist name that it's in (if any) to an array. */
let reg = new RegExp('"([^"]*?)":(?=[^\\]]+' + regexEscape(song) + ')', "g");
let result;
while((result = reg.exec(playlistData)) !== null) {
playlistsItsIn.push(result[1]);
}
// Update our song data object
songData[song] = playlistsItsIn;
}
result.value = JSON.stringify(songData, null, '\t');
}
songInput.addEventListener("change", function() {
loadData("songInput", this);
});
playlistInput.addEventListener("change", function() {
loadData("playlistInput", this);
});