Jump to content

Last.fm Submission Timestamp Issue Thingy...


Mazin07

Recommended Posts

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

Link to comment
Share on other sites

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");

Link to comment
Share on other sites

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.)

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 4 weeks later...
  • 4 weeks later...

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! :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...