Skip to content

Instantly share code, notes, and snippets.

@codewizard13
Created May 8, 2016 18:37
Show Gist options
  • Select an option

  • Save codewizard13/27c69ec5309114185955a3e851016a81 to your computer and use it in GitHub Desktop.

Select an option

Save codewizard13/27c69ec5309114185955a3e851016a81 to your computer and use it in GitHub Desktop.
Outputs a list of all your Pandora liked tracks to the console. #jQuery #JavaScript
/*
NAME: ListPandoraLikedTracks
AUTHOR: Eric Hepperle
DATE: 2016-04-23
PURPOSE: Outputs a list of all your Pandora liked tracks
to the console.
REVISION: 2.0
USAGE:
1) First, login to your Pandora account.
2) Next, use a plugin like "jquery-injector" to add jquery
to the page.
3) Use the mouse-wheel to scroll down a bit;
this script is only able to retrieve about 150-250
songs informations at time.
4) Open the console tab in the code inspector.
5) Cut and paste the below code into the console and hit enter.
The result will be pipe-separated list of songs.
6) Copy that from the console into a spreadsheet file for posterity.
*/
// !!! WORKS !!!
/*
FUNCTIONS:
*/
function toTitleCase(str) {
// split title into word array
var wordArray = str.split(" ");
// for each word in the array
for(i=0;i<wordArray.length;i++){
// get the current word, store all but first char
// and convert to lower case
var restOfWord = wordArray[i].substring(1).toLowerCase();
wordArray[i] = wordArray[i][0].toUpperCase() + restOfWord;
}
finalTitle = wordArray.join(" ");
return finalTitle;
}
// get jquery array of song info objects
var songs_arr = $('#track_like_pages .infobox.i-t-shade-1.clearfix');
// print how many songs were found
console.log(songs_arr.length);
// for each song info object, get all the info...
songs_arr.each(function (i, v) {
var artist = $(this).find('.infobox-body p.s-0.line-h-1_4 a')[0].innerHTML;
var title = $(this).find('.infobox-body a.first')[0].innerHTML;
var album_url = $(this).find('.infobox-body a.first').attr('href');
console.log("album_url: " + album_url);
// parse album url. this is composed of
// author, album name, and track title and there
// is a "/" at the beginning which is element '0'
// of the url parts array.
var album_parts = album_url.split('/');
// console.log('%cAlbum Parts:','background-color:yellowgreen');
//console.log(album_parts);
// the 3rd element of album parts array contains
// the allbum name. Replace all hyphens in album
// name with spaces. Now we have album name, albeit
// in lower case.
var album = (album_parts[2].split('-')).join(' ');
// Convert album to title case
album = toTitleCase(album);
var playlist = $(this).find('');
// console.log('%cv: ', 'background-color:orange');
// console.log("Artist: " + artist);
// console.log("Title: " + title);
// console.log("Album: " + album);
var out_str = [(i+1),artist,title,album].join('|');
console.log(out_str);
});
/*
UPDATES:
2016-05-08 - Added toTitleCase() function.
- Changed from comma-separated to
pipe-separated csv.
2016-04-23 - Created script. Works. Took 2 hrs total.
one of the big gotchas was remembering
to put the "[0]" in when using jquery
selectors.
Also, doesn't do title case for the album
name yet.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment