Hello guys,
I'm writing a little program in Java which should be able to download the songs.
But as soon as I try to get the Stream Key, i get the following return:
Code:
{"header":{"session":"15618724056fab1058a5324dddec4d02"},"fault":{"code":256,"message":"invalid token"}}
To generate the token I use the following:
Code:
"59f4a7" + util.generateSHA1("getStreamKeyFromSongIDEx:" + token + ":theTicketsAreNowDiamonds:59f4a7").toLowerCase();
My MainClass.java code is:
Code:
import org.json.JSONObject;
public class MainClass {
static Util util = new Util();
/**
* @param args
* @throws Throwable
*/
public static void main(String[] args) throws Throwable {
String session = util.getSession();
String secretKey = util.generateMD5(session);
System.out.println(session);
System.out.println(secretKey);
String currentPost = "{\"method\":\"getCommunicationToken\",\"parameters\":{\"secretKey\":\"" + secretKey + "\"},\"header\":{\"privacy\":0,\"client\":\"htmlshark\",\"clientRevision\":\"20110906\",\"uuid\":\"A8E97220-4B23-4848-8D69-77736EFFBB02\",\"session\":\"" + session + "\",\"country\":{\"ID\":\"55\",\"CC1\":\"18014398509481984\",\"CC3\":\"0\",\"CC2\":\"0\",\"CC4\":\"0\",\"IPR\":\"9075\"}}}";
String executerequest = util.executePost(currentPost, "http://grooveshark.com/more.php?getCommunicationToken");
System.out.println(executerequest);
JSONObject json = new JSONObject(executerequest);
System.out.println(json.get("result"));
String token = json.getString("result");
currentPost = "{\"method\":\"getStreamKeyFromSongIDEx\",\"parameters\":{\"prefetch\":false,\"country\":{\"IPR\":\"9075\",\"CC2\":\"0\",\"ID\":\"55\",\"CC1\":\"18014398509481984\",\"CC3\":\"0\",\"CC4\":\"0\"},\"songID\":165150,\"mobile\":false},\"header\":{\"uuid\":\"9E2BC2EF-3B5D-46AA-9D15-CCB80826F4AF\",\"country\":{\"IPR\":\"9075\",\"CC2\":\"0\",\"ID\":\"55\",\"CC1\":\"18014398509481984\",\"CC3\":\"0\",\"CC4\":\"0\"},\"privacy\":0,\"session\":\"" + session + "\",\"token\":\"" + "59f4a7" + util.generateSHA1("getStreamKeyFromSongIDEx:" + token + ":theTicketsAreNowDiamonds:" + "59f4a7").toLowerCase() + "\",\"clientRevision\":\"20110906\",\"client\":\"jsqueue\"}}";
executerequest = util.executePost(currentPost, "http://grooveshark.com/more.php?getStreamKeyFromSongIDEx");
System.out.println(executerequest);
//the line below is only for SHA testing purposes
System.out.println(util.generateSHA1("abc"));
}
}
and my Util.java code is
Code:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.math.BigInteger;
import java.net.URL;
import java.net.URLConnection;
import java.security.MessageDigest;
public class Util {
public String executePost(String got, String urlString) throws Throwable {
// Initialisation of Variables
String line;
String returnString;
// Send data
URL url = new URL(urlString);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
conn.setRequestProperty("User-Agent",
"Mozilla/5.0 (X11; Linux i686 rv: 8.0) Gecko/20100101 Firefox/8.0");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Referer", "http://grooveshark.com/JSQueue.swf?20111121.04");
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(got);
wr.flush();
// Get response
BufferedReader rd = new BufferedReader(new InputStreamReader(
conn.getInputStream()));
returnString = rd.readLine();
while ((line = rd.readLine()) != null) {
returnString += "\n" + line;
}
return returnString;
}
public String getContent(String urlString) throws Throwable {
String returnString;
String line;
URL url = new URL(urlString);
URLConnection conn = url.openConnection();
conn.setRequestProperty("User-Agent",
"Mozilla/5.0 (X11; Linux i686 rv: 8.0) Gecko/20100101 Firefox/8.0");
BufferedReader in = new BufferedReader(new InputStreamReader(
conn.getInputStream()));
returnString = in.readLine();
while ((line = in.readLine()) != null) {
returnString += "\n" + line;
}
return returnString;
}
public String getSession() throws Throwable {
URL url = new URL("http://grooveshark.com");
URLConnection conn = url.openConnection();
conn.setRequestProperty("User-Agent",
"Mozilla/5.0 (X11; Linux i686 rv: 8.0) Gecko/20100101 Firefox/8.0");
String split1[], split2[];
split1 = conn.getHeaderField("Set-Cookie").split(";");
split2 = split1[0].split("=");
return split2[1];
}
public String generateMD5(String input) throws Throwable {
String output;
MessageDigest m = MessageDigest.getInstance("MD5");
m.update(input.getBytes(), 0, input.length());
output = new BigInteger(1, m.digest()).toString(16);
while (output.length() < 32) {
output = "0" + output;
}
return output;
}
public String generateSHA1(String input) throws Throwable {
MessageDigest md = MessageDigest.getInstance("SHA1");
md.update(input.getBytes());
byte[] output = md.digest();
return bytesToHex(output);
}
private String bytesToHex(byte[] b) {
char hexDigit[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F' };
StringBuffer buf = new StringBuffer();
for (int j = 0; j < b.length; j++) {
buf.append(hexDigit[(b[j] >> 4) & 0x0f]);
buf.append(hexDigit[b[j] & 0x0f]);
}
return buf.toString();
}
}
The generateMD5 and the generateSHA1-functions are working
If somebody knows why that error keeps happening, please tell me so I can fix it

xxmicloxx
PS: now also tried with retransferring PHPSESSID cookie back to grooveshark in the header. Didn't work. I'm really out of ideas now -,-