Mazin07 Posted October 31, 2006 Share Posted October 31, 2006 Back story: When I started to use Pandora, I had it submit my tracks to last.fm so it would show up on my profile. But, it didn't. Last.fm would give me a message saying that spam protection was triggered because the timestamp on the submission was before my last submission (from amaroK). So, a little test shows that it does submit it, only 5 hours in the past. Not coincidentally, I'm in UTC-5 timezone. So, PJ submits tracks with improper timestamps. Audioscrobbler needs Unix timestamps to accompany each submission. Unix timestamps are always in UTC, BTW. I poked around in LastFmLookup.java, and found this: Date date = new Date(); DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); req = new GetMethodWebRequest(lastFMUrl); req.setParameter("u", userName); String s = md5(md5(password) + key); LOG.debug("hex = " + s); req.setParameter("s", s); req.setParameter("a[0]", songInfo.getArtist()); req.setParameter("t[0]", songInfo.getTitle()); req.setParameter("b[0]", songInfo.getAlbum()!=null?songInfo.getAlbum():""); req.setParameter("m[0]", ""); req.setParameter("l[0]", "255"); req.setParameter("i[0]", simpleDateFormat.format(date)); res = wc.getResponse(req); text = res.getText(); if (text.indexOf("OK") == -1) { String msg = "a problem was encountered whille attempting to add track to last.fm: " + text; LOG.warn(msg); throw new RuntimeException(msg); } LOG.info("successfully added track to last.fm"); Where i[0] is the timestamp. It's submitting with the format "yyyy-MM-dd HH:mm:ss", and if I'm not mistaken, Unix timestamps look like "1162252620". So: #1: It isn't UTC time #2: It's not a unix timestamp Quote Link to comment Share on other sites More sharing options...
cooper Posted October 31, 2006 Share Posted October 31, 2006 Change that bit to: req = new GetMethodWebRequest(lastFMUrl); req.setParameter("u", userName); String s = md5(md5(password) + key); LOG.debug("hex = " + s); req.setParameter("s", s); req.setParameter("a[0]", songInfo.getArtist()); req.setParameter("t[0]", songInfo.getTitle()); req.setParameter("b[0]", songInfo.getAlbum()!=null?songInfo.getAlbum():""); req.setParameter("m[0]", ""); req.setParameter("l[0]", "255"); req.setParameter("i[0]", System.currentTimeMillis()); res = wc.getResponse(req); text = res.getText(); if (text.indexOf("OK") == -1) { String msg = "a problem was encountered whille attempting to add track to last.fm: " + text; LOG.warn(msg); throw new RuntimeException(msg); } LOG.info("successfully added track to last.fm"); Quote Link to comment Share on other sites More sharing options...
Mazin07 Posted October 31, 2006 Author Share Posted October 31, 2006 I haven't tried it, but I looked on the Java site and... 1. It's UTC, right? From what I infer from the Java site, it is (minus leap seconds). 2. Isn't Unix time measured in seconds from the epoch, and not milliseconds? If that's what AudioScrobbler wants, then it would need to be divided by 1 000. 3. No need to convert to string first, right? (I'm no Java pro.) Quote Link to comment Share on other sites More sharing options...
cooper Posted November 1, 2006 Share Posted November 1, 2006 I haven't tried it, but I looked on the Java site and... Good, coz this was from the top of my head. No testing of any kind took place. :) 1. It's UTC, right? From what I infer from the Java site, it is (minus leap seconds). Yup. Jooking at the Audioscrobbler plugin version 0.3.8.1 that's what's needed. 2. Isn't Unix time measured in seconds from the epoch, and not milliseconds? If that's what AudioScrobbler wants, then it would need to be divided by 1 000. UNIX does indeed use seconds. A division is required. 3. No need to convert to string first, right? (I'm no Java pro.) Probably, yes. So instead of System.currentTimeMillis() you should use ""+(System.currentTimeMillis()/1000L) Quote Link to comment Share on other sites More sharing options...
Mazin07 Posted November 2, 2006 Author Share Posted November 2, 2006 OK, now I just sound dumb. How do I compile pandora's jar? Quote Link to comment Share on other sites More sharing options...
cooper Posted November 2, 2006 Share Posted November 2, 2006 Install Ant, open a command prompt, enter the Pandora directory and type "ant pandora". Look in the 'dist' subdirectory for your new pandora.jar Quote Link to comment Share on other sites More sharing options...
Mazin07 Posted November 4, 2006 Author Share Posted November 4, 2006 System.currentTimeMillis()/1000L has been confirmed to give the correct unix time. I tried this: import java.lang.System; public class nixtime { public static void main (String[] args) { while(true) { System.out.println(System.currentTimeMillis()/ 1000L); try { Thread.sleep(1000); } catch(Exception e) { } } } } and it matches output from $ date +%s I haven't put it in Pandora's Jar yet, but I'll try that soon. Quote Link to comment Share on other sites More sharing options...
homebrew Hacks Posted November 6, 2006 Share Posted November 6, 2006 The audioscrobbler wiki says that the current protocol is 1.1 The timeformat is correct, but the timezone shuld be set to UTC. Quote Link to comment Share on other sites More sharing options...
Mazin07 Posted November 7, 2006 Author Share Posted November 7, 2006 and it is. Quote Link to comment Share on other sites More sharing options...
Calypsoli Posted December 5, 2006 Share Posted December 5, 2006 So, any solution? I tryed to recompile with your code but i get incorrect format... I switched back to original version but get +5h timestamp on songs. Quote Link to comment Share on other sites More sharing options...
Calypsoli Posted December 29, 2006 Share Posted December 29, 2006 public Date getTime ( ) { TimeZone zone = TimeZone.getTimeZone ( "GMT-5" ); Calendar calendar = Calendar.getInstance ( zone ); return calendar.getTime ( ); } Think this would be an idea? Quote Link to comment Share on other sites More sharing options...
Calypsoli Posted December 29, 2006 Share Posted December 29, 2006 ok here's my solution, i am GMT-5 import java.util.Calendar; Date oldDate = new Date(); Calendar cal = Calendar.getInstance(); cal.setTime(oldDate); cal.add(Calendar.HOUR_OF_DAY, 5); Date date = cal.getTime(); DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); This worked perfectly for me! :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.