Skip to content

Instantly share code, notes, and snippets.

@BenWard
Created November 27, 2011 01:25
Show Gist options
  • Save BenWard/1396739 to your computer and use it in GitHub Desktop.
Save BenWard/1396739 to your computer and use it in GitHub Desktop.
Scrobble my Jam: A pre-configured, bookmarklet version of Scrobble my Jam ready for use. Scrobbles playback from http://thisismyjam.com to http://last.fm. Enjoy.
/* Scrobble my Jam
*
* Bookmarklet JavaScript for scrobbling http://thisismyjam.com to
* Last.FM. If it doesn't scrobble, it doesn't count.
*
* (c) 2011 Ben Ward (@benward, http://benward.me)
*
* BSD License
*
* Instructions: Select all of the JavaScript text below, and drag it to your bookmarks
* bar. You'll see right near the start of the code is an object setting "username" and
* "password" variables. These are your Last.FM credentials. (%22 is an escaped double-
* quote char, so if your username is "benward", you're editing the below to read
* `username:%22benward%22`. Likewise the password. If you're suspicious that the script
* isn't working, then change `logging:false` to `logging:true` for very verbose
* console output.
*
* File issues and fork the source from https://github.com/BenWard/scrobblemyjam.
*
* This version: Compressed with uglifyjs, then HTTP escaped.
*/
javascript:(function(){var%20a={username:%22%22,password:%22%22,logging:false};!function(a){function%20s(){!q||!r?alert(%22You%27re%20using%20a%20copy%20of%20Scrobble%20my%20Jam%20code%20that%20doesn%27t%20have%20Last.FM%20API%20keys.%20Get%20some%20from%20http://last.fm/api.%22):!b||!c?alert(%22You%20need%20to%20set%20the%20`username`%20and%20`password`%20variables.%22):(m=new%20this.lastfm({apiKey:q,apiSecret:r}),m.auth.getMobileSession({username:b,password:c},{success:function(a){n=a.session,o=setInterval(x,5e3),sci=setInterval(w,2e4)},error:function(a,b){alert(%22Last.FM%20Login%20Failed.%20Check%20your%20username%20and%20password.%22)}}))}function%20t(){d&&console&&console.log(arguments)}function%20u(a,b,c){t(%22Now%20Playing:%22,a,b),e=a+b,m.track.updateNowPlaying({track:b,artist:a,duration:c},n,{success:function(a){t(%22Now%20playing%20success:%22,e,a)},error:function(a,b){t(%22Now%20playing%20failure%22,b,e,a)}})}function%20v(a,b){t(%22Enqueued%20Scrobble:%22,a,b),h.push({artist:a,track:b,album:null,timestamp:Math.round(Date.now()/1e3)}),f=a+b}function%20w(){t(%22Processing%20Scrobble%20Queue.%22);var%20a;while(a=h.shift())t(%22Scrobbling%22,a),m.track.scrobble(a,n,{success:function(b){t(%22Scrobble%20success:%22,a,b)},error:function(b,c){t(%22Scrobble%20failure%22,c,a,b),h.push(a)}})}function%20x(){t(%22Polling%20Track%22);var%20a=$(%22#artist-name%22).text(),b=$(%22#track-title%22).text(),c=a+b,d=window.player&&window.player.currentSound&&Math.round(window.player.currentSound.position/1e3),h=window.player&&window.player.currentSound&&Math.round(window.player.currentSound.duration/1e3),i=window.player&&window.player.currentSound&&!window.player.currentSound.paused;a&&b&&i?(c==e&&d<g&&(g=0,e=f=%22%22,t(%22Detected%20playing%20same%20track%20twice.%20Hot%20jam.%22)),t(%22Playback%20Position%22,d/h),h>30&&(d/h>.5||d>240)&&(c==f||v(a,b)),!e!=c&&(c==e||u(a,b,h))):t(%22No%20playback%22)}var%20b=a.username,c=a.password,d=a.logging,e,f,g,h=[],k=this,l,m,n,o,p;!function(a){function%20e(a){return%20f(a)}function%20f(a){return%20r(h(q(a),a.length*d))}function%20g(){return%20f(%22abc%22)==%22900150983cd24fb0d6963f7d28e17f72%22}function%20h(a,b){a[b>>5]|=128<<b%2532,a[(b+64>>>9<<4)+14]=b;var%20c=1732584193,d=-271733879,e=-1732584194,f=271733878;for(var%20g=0;g<a.length;g+=16){var%20h=c,i=d,n=e,p=f;c=j(c,d,e,f,a[g+0],7,-680876936),f=j(f,c,d,e,a[g+1],12,-389564586),e=j(e,f,c,d,a[g+2],17,606105819),d=j(d,e,f,c,a[g+3],22,-1044525330),c=j(c,d,e,f,a[g+4],7,-176418897),f=j(f,c,d,e,a[g+5],12,1200080426),e=j(e,f,c,d,a[g+6],17,-1473231341),d=j(d,e,f,c,a[g+7],22,-45705983),c=j(c,d,e,f,a[g+8],7,1770035416),f=j(f,c,d,e,a[g+9],12,-1958414417),e=j(e,f,c,d,a[g+10],17,-42063),d=j(d,e,f,c,a[g+11],22,-1990404162),c=j(c,d,e,f,a[g+12],7,1804603682),f=j(f,c,d,e,a[g+13],12,-40341101),e=j(e,f,c,d,a[g+14],17,-1502002290),d=j(d,e,f,c,a[g+15],22,1236535329),c=k(c,d,e,f,a[g+1],5,-165796510),f=k(f,c,d,e,a[g+6],9,-1069501632),e=k(e,f,c,d,a[g+11],14,643717713),d=k(d,e,f,c,a[g+0],20,-373897302),c=k(c,d,e,f,a[g+5],5,-701558691),f=k(f,c,d,e,a[g+10],9,38016083),e=k(e,f,c,d,a[g+15],14,-660478335),d=k(d,e,f,c,a[g+4],20,-405537848),c=k(c,d,e,f,a[g+9],5,568446438),f=k(f,c,d,e,a[g+14],9,-1019803690),e=k(e,f,c,d,a[g+3],14,-187363961),d=k(d,e,f,c,a[g+8],20,1163531501),c=k(c,d,e,f,a[g+13],5,-1444681467),f=k(f,c,d,e,a[g+2],9,-51403784),e=k(e,f,c,d,a[g+7],14,1735328473),d=k(d,e,f,c,a[g+12],20,-1926607734),c=l(c,d,e,f,a[g+5],4,-378558),f=l(f,c,d,e,a[g+8],11,-2022574463),e=l(e,f,c,d,a[g+11],16,1839030562),d=l(d,e,f,c,a[g+14],23,-35309556),c=l(c,d,e,f,a[g+1],4,-1530992060),f=l(f,c,d,e,a[g+4],11,1272893353),e=l(e,f,c,d,a[g+7],16,-155497632),d=l(d,e,f,c,a[g+10],23,-1094730640),c=l(c,d,e,f,a[g+13],4,681279174),f=l(f,c,d,e,a[g+0],11,-358537222),e=l(e,f,c,d,a[g+3],16,-722521979),d=l(d,e,f,c,a[g+6],23,76029189),c=l(c,d,e,f,a[g+9],4,-640364487),f=l(f,c,d,e,a[g+12],11,-421815835),e=l(e,f,c,d,a[g+15],16,530742520),d=l(d,e,f,c,a[g+2],23,-995338651),c=m(c,d,e,f,a[g+0],6,-198630844),f=m(f,c,d,e,a[g+7],10,1126891415),e=m(e,f,c,d,a[g+14],15,-1416354905),d=m(d,e,f,c,a[g+5],21,-57434055),c=m(c,d,e,f,a[g+12],6,1700485571),f=m(f,c,d,e,a[g+3],10,-1894986606),e=m(e,f,c,d,a[g+10],15,-1051523),d=m(d,e,f,c,a[g+1],21,-2054922799),c=m(c,d,e,f,a[g+8],6,1873313359),f=m(f,c,d,e,a[g+15],10,-30611744),e=m(e,f,c,d,a[g+6],15,-1560198380),d=m(d,e,f,c,a[g+13],21,1309151649),c=m(c,d,e,f,a[g+4],6,-145523070),f=m(f,c,d,e,a[g+11],10,-1120210379),e=m(e,f,c,d,a[g+2],15,718787259),d=m(d,e,f,c,a[g+9],21,-343485551),c=o(c,h),d=o(d,i),e=o(e,n),f=o(f,p)}return%20Array(c,d,e,f)}function%20i(a,b,c,d,e,f){return%20o(p(o(o(b,a),o(d,f)),e),c)}function%20j(a,b,c,d,e,f,g){return%20i(b&c|~b&d,a,b,e,f,g)}function%20k(a,b,c,d,e,f,g){return%20i(b&d|c&~d,a,b,e,f,g)}function%20l(a,b,c,d,e,f,g){return%20i(b^c^d,a,b,e,f,g)}function%20m(a,b,c,d,e,f,g){return%20i(c^(b|~d),a,b,e,f,g)}function%20n(a,b){var%20c=q(a);c.length>16&&(c=h(c,a.length*d));var%20e=Array(16),f=Array(16);for(var%20g=0;g<16;g++)e[g]=c[g]^909522486,f[g]=c[g]^1549556828;var%20i=h(e.concat(q(b)),512+b.length*d);return%20h(f.concat(i),640)}function%20o(a,b){var%20c=(a&65535)+(b&65535),d=(a>>16)+(b>>16)+(c>>16);return%20d<<16|c&65535}function%20p(a,b){return%20a<<b|a>>>32-b}function%20q(a){var%20b=Array(),c=(1<<d)-1;for(var%20e=0;e<a.length*d;e+=d)b[e>>5]|=(a.charCodeAt(e/d)&c)<<e%2532;return%20b}function%20r(a){var%20c=b?%220123456789ABCDEF%22:%220123456789abcdef%22,d=%22%22;for(var%20e=0;e<a.length*4;e++)d+=c.charAt(a[e>>2]>>e%254*8+4&15)+c.charAt(a[e>>2]>>e%254*8&15);return%20d}var%20b=0,c=%22%22,d=8;a.md5=e}(k),!function(a){function%20b(a){var%20b=a.apiKey||%22%22,c=a.apiSecret||%22%22,d=a.apiUrl||%22http://ws.audioscrobbler.com/2.0/%22,e=a.cache||undefined;this.setApiKey=function(a){b=a},this.setApiSecret=function(a){c=a},this.setApiUrl=function(a){d=a},this.setCache=function(a){e=a};var%20f=0,g=function(a,b,c){if(c==%22POST%22){var%20g=document.getElementsByTagName(%22html%22)[0],h=document.createElement(%22iframe%22),i;h.width=1,h.height=1,h.style.border=%22none%22,h.onload=function(){typeof%20b.success!=%22undefined%22&&b.success()},g.appendChild(h),typeof%20h.contentWindow!=%22undefined%22?i=h.contentWindow.document:typeof%20h.contentDocument.document!=%22undefined%22?i=h.contentDocument.document.document:i=h.contentDocument.document,i.open(),i.clear(),i.write(%27<form%20method=%22post%22%20action=%22%27+d+%27%22%20id=%22form%22>%27);for(var%20j%20in%20a)i.write(%27<input%20type=%22text%22%20name=%22%27+j+%27%22%20value=%22%27+a[j]+%27%22>%27);i.write(%22</form>%22),i.write(%27<script%20type=%22application/x-javascript%22>%27),i.write(%27document.getElementById(%22form%22).submit();%27),i.write(%22</script>%22),i.close()}else{var%20k=%22jsonp%22+(new%20Date).getTime()+f;f+=1;var%20l=m.getApiSignature(a);if(typeof%20e!=%22undefined%22&&e.contains(l)&&!e.isExpired(l)){typeof%20b.success!=%22undefined%22&&b.success(e.load(l));return}a.callback=k,a.format=%22json%22,window[k]=function(c){if(typeof%20e!=%22undefined%22){var%20d=e.getExpirationTime(a);d>0&&e.store(l,c,d)}typeof%20c.error!=%22undefined%22?typeof%20b.error!=%22undefined%22&&b.error(c.error,c.message):typeof%20b.success!=%22undefined%22&&b.success(c),window[k]=undefined;try{delete%20window[k]}catch(f){}n&&n.removeChild(o)};var%20n=document.getElementsByTagName(%22head%22)[0],o=document.createElement(%22script%22),p=[];for(var%20j%20in%20a)p.push(encodeURIComponent(j)+%22=%22+encodeURIComponent(a[j]));o.src=d+%22?%22+p.join(%22&%22).replace(/%2520/g,%22+%22),n.appendChild(o)}},h=function(a,c,d,e){c=c||{},d=d||{},e=e||%22GET%22,c.method=a,c.api_key=b,g(c,d,e)},k=function(a,c,d,e,f){c=c||{},e=e||{},f=f||%22GET%22,c.method=a,c.api_key=b,d&&typeof%20d.key!=%22undefined%22&&(c.sk=d.key),c.api_sig=m.getApiSignature(c),g(c,e,f)};this.auth={getMobileSession:function(a,b){a={username:a.username,authToken:l(a.username+l(a.password))},k(%22auth.getMobileSession%22,a,null,b)},getSession:function(a,b){k(%22auth.getSession%22,a,null,b)},getToken:function(a){k(%22auth.getToken%22,null,null,a)}},this.track={addTags:function(a,b,c){k(%22track.addTags%22,a,b,c,%22POST%22)},getInfo:function(a,b){h(%22track.getInfo%22,a,b)},love:function(a,b,c){k(%22track.love%22,a,b,c,%22POST%22)},scrobble:function(a,b,c){if(a.constructor.toString().indexOf(%22Array%22)!=-1){var%20d={};for(i%20in%20a)for(j%20in%20a[i])d[j+%22[%22+i+%22]%22]=a[i][j];a=d}k(%22track.scrobble%22,a,b,c,%22POST%22)},unlove:function(a,b,c){k(%22track.unlove%22,a,b,c,%22POST%22)},updateNowPlaying:function(a,b,c){k(%22track.updateNowPlaying%22,a,b,c,%22POST%22)}};var%20m={getApiSignature:function(a){var%20b=[],d=%22%22;for(var%20e%20in%20a)b.push(e);b.sort();for(var%20f%20in%20b){var%20e=b[f];d+=e+a[e]}return%20d+=c,l(d)}}}a.lastfm=b}(k),l=this.md5;var%20q=[%22c31%22,%22b77%22,%22d81be%22,%22ee09%22,%222654%22,%22381a%22,%2205e7%22,%225174f%22].join(%22%22),r=[%2210c%22,%22e7e%22,%22418%22,%22f6b4%22,%22bde%22,%22a79f8%22,%22402d%22,%2275f0%22,%2208a%22].join(%22%22);s()}(a)})();
@philgyford
Copy link

I've tried this a couple of times, but never managed to get it to work. With logging on, and music playing on thisismyjam.com, I get lots of "Polling Track", "No playback" and occasionally "Processing Scrobble Queue", but nothing appears at Last.fm. Any thoughts?

@BenWard
Copy link
Author

BenWard commented Jan 2, 2012

Hi Phil. This is my Jam changed their playback mechanism about a day after I released the script, so alas it broke. Need to change the playback detection to be based on the UI, rather than underlying music player object. Still holding out for native support, really.

@philgyford
Copy link

philgyford commented Jan 2, 2012 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment