SciLor's Open Source Forums

Also visit my Website!
It is currently Thu Jun 21, 2018 6:22 am

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Thu Dec 08, 2011 6:45 pm 
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 :D

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 -,-


Top
  
 
 
Online
The Adswinger

Joined: Wed Jan 13, 2010 11:56 pm
Posts: Too many!
Donated: Ad Posts


PostPosted: Thu Dec 08, 2011 10:21 pm 
Offline
The Developer

Joined: Wed Jan 13, 2010 11:56 pm
Posts: 1467
Donated: free software
It looks fine, it should work. Check for typos.
Please println out your (session)token and the created token, including the random prefix.

here is an working example
Quote:
HashHelper.GetSHA1Hash("getStreamKeysFromSongIDs:4ec54306d656e:theTicketsAreNowDiamonds:6cd039") == "ca64ab62184348d0ac6563d6ed5f8a9ecde03f07"


PS: You may try to build your app using my api, its documented!
Just take the needed class files from my java version:
http://www.scilor.com/java-grooveshark-downloader.html

If you wanna release your tool to the public, please contact me again ;)

_________________
My Windows Mobile and Windows Open Source Website:
www.scilor.com

Like my work? Donate!
Donation Website

My Programs:
grooveshark™.com Downloader, GrooveMobile, Fuel Blaster, Chameleon TicTacToe, QuickTap, WiMoBlue, Driving Licence Trainer, CodeSnippetViewer, Gesture Launcher, Fahrplanauskunft, GSensor Control


Top
 Profile  
 
PostPosted: Fri Dec 09, 2011 4:46 pm 
SUCCESS! I just failed: I sent two different UUIDs - but now it WORKS! *celebration*
As soon as my project is finished I'll probably release my whole code so you guys can try around with it.

xxmicloxx

P.S: MP3 playing librarys for Java are terrible! Switching over to adobe Flash/Flex now. Works fine until now.


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
template->_php_include(): File ./counter/foruminclude.php does not exist or is empty Powered by phpBB® Forum Software © phpBB Group