Last active
August 12, 2018 12:20
-
-
Save atommarvel/6863432 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var songs = document.getElementsByClassName("track-list ui-sortable")[1].children; | |
var final = ""; | |
var trackInfo = ""; | |
var artistName = ""; | |
var trackName = ""; | |
for (var track=0;track<songs.length;track++) { | |
trackInfo = songs[track].getElementsByClassName("track-info")[0]; | |
artistName = trackInfo.getElementsByClassName("album-name")[0].textContent.trim(); | |
trackName = trackInfo.getElementsByClassName("name")[0].textContent.trim(); | |
final += artistName + " - " + trackName + "\n"; | |
} | |
console.log(final); | |
/* Original Version... website has been updated since so the above was created by Tesla0 | |
var songs = document.getElementsByClassName("sortable-track-list track-list ui-sortable")[0].children; | |
var final = ""; | |
for (var track=0;track<songs.length;track++) { | |
final += songs[track].getAttribute("artist_name")+" - "+songs[track].getAttribute("track_name")+"\n"; | |
} | |
console.log(final); | |
*/ |
Using this script, I'm getting an Uncaught TypeError: Cannot read property 'getElementsByClassName' of undefined(...)
(anonymous function) @VM7419:7
Any ideas?
I wanted to dump all my playlists. I clicked through each one so that the content was pre-loaded, and then did this dirty hack based on the above.
var playlists = document.getElementsByClassName("playlist-link");
for (var i = 0; i < playlists.length; i++) {
var playlist = playlists[i];
var name = playlist.innerText.trim();
console.log('Playlist:', name);
console.log('Name\tArtist\tAlbum\n');
playlist.click();
var songs = document.getElementsByClassName("track");
var song = "";
var songInfo = "";
for (var track=0;track < songs.length; track++) {
song = songs[track];
var songName = song.getElementsByClassName("name");
var songName2 = songName[0];
var songName3 = songName2.firstElementChild;
var songName4 = songName3.attributes;
var songName5 = songName4.getNamedItem("title");
var songName6 = songName5.value;
var artistName = song.getElementsByClassName("artist");
var artistName2 = artistName[0];
var artistName3 = artistName2.firstElementChild;
var artistName4 = artistName3.textContent.trim();
var album = song.getElementsByClassName("album-name")[0].firstElementChild.textContent.trim();
console.log(songName6 + '\t' + artistName4 + '\t' + album);
}
}
This updates for a site change ("track-info" is just "track" now) and fixes @sdavies2720's problem (which is caused by track > songList.length, due to the hardcoded 500). It also outputs a slightly different format.
EDIT: fix some typos, change format to a "csv" style acceptable for iTunes import
How is this used? How do I hook this up? Is there a primer for hacking Rhapsody somewhere?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fixed up a couple of typo's in Eric's most recent gist.
Also, I was unable to get childElementCount with the latest version of Rhapsody/Napster's UI. I'm sure there is a way, but I'm not much of a web developer and I gave up after 5 minutes. Just manually entering the number of tracks to iterate over is a gross hack that works, so long as you don't have too many playlists to export.
Finally, make sure your "Queue" is empty before you do this. Both the Rhapsody/Napster Queue and the playlist page use the track-info div, so you'll get duplicate tracks unless the Queue is cleared out.