Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
    <title>Show playlists a Google Play song is in</title>
</head>
<body>
<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>
<script type="text/javascript">
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();
    }
}
function regexEscape(s) {
    return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
};
var songData = {};
function getSongPlaylistData() {
    for(let song of songList) {
        let playlistsItsIn = [];
        let reg = new RegExp('"([^"]*?)":(?=[^\\]]+' + regexEscape(song) + ')', "g");
        let result;
        while((result = reg.exec(playlistData)) !== null) {
            playlistsItsIn.push(result[1]);
        }
        songData[song] = playlistsItsIn;
    }
    result.value = JSON.stringify(songData, null, '\t');
}
songInput.addEventListener("change", function() {
    loadData("songInput", this);
});
playlistInput.addEventListener("change", function() {
    loadData("playlistInput", this);
});
</script>
</body>
</html>
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers