private bool _GetToken() { try { GrooveJSON JSONHandler = new GrooveJSON(); JSONHandler.WriteHeader(); JSONHandler.WriteMethod("getCommunicationToken"); Dictionary<string, object> myParams = new Dictionary<string, object>(); myParams.Add("secretKey", Helpers.Hash(Information.SessionID, new MD5CryptoServiceProvider())); JSONHandler.WriteParameters(myParams); JSONHandler.WriteFinish(); byte[] jsonData = Encoding.ASCII.GetBytes(JSONHandler.ToString()); HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://grooveshark.com/more.php"); req.Method = "POST"; req.ContentLength = jsonData.Length; req.ContentType = "application/json"; System.IO.Stream ostream = req.GetRequestStream(); ostream.Write(jsonData, 0, jsonData.Length); ostream.Close(); HttpWebResponse res = (HttpWebResponse)req.GetResponse(); System.IO.Stream istream = res.GetResponseStream(); byte[] buf = new byte[res.ContentLength == -1 ? 8192 : res.ContentLength]; StringBuilder response = new StringBuilder(); while (istream.Read(buf, 0, buf.Length) != 0) response.Append(Encoding.ASCII.GetString(buf, 0, buf.Length)); Information.Token = JSONHandler.Read(response.ToString(), "result"); res.Close(); } catch (Exception) { return false; } return true; }
private int _Search() { try { GrooveJSON JSON = new GrooveJSON(); JSON.WriteHeader("getSearchResultsEx"); Dictionary<string, object> searchParams = new Dictionary<string, object>(); searchParams.Add("query", _searchString); searchParams.Add("type", "Songs"); searchParams.Add("guts", 0); searchParams.Add("ppOverride", false); JSON.WriteParameters(searchParams); JSON.WriteMethod("getSearchResultsEx"); JSON.WriteFinish(); string postJSON = JSON.ToString(); HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://cowbell.grooveshark.com/more.php?getSearchResultsEx"); req.Method = "POST"; req.ContentLength = postJSON.Length; req.ContentType = "application/json"; req.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate"); System.IO.Stream postWriteStream = req.GetRequestStream(); byte[] writeBuf = Encoding.ASCII.GetBytes(postJSON); postWriteStream.Write(writeBuf, 0, writeBuf.Length); postWriteStream.Close(); HttpWebResponse res = (HttpWebResponse)req.GetResponse(); System.IO.Compression.GZipStream decompress = new System.IO.Compression.GZipStream(res.GetResponseStream(), System.IO.Compression.CompressionMode.Decompress); string responseJSON = ""; System.IO.StreamReader decompressRead = new System.IO.StreamReader(decompress, Encoding.ASCII); responseJSON = decompressRead.ReadToEnd(); decompressRead.Close(); decompress.Close(); res.Close(); Dictionary<string, object> ResponseDictionary = JSON.Read(responseJSON); return _ParseResponse(ResponseDictionary); } catch (Exception) { return -1; } }
private bool _RetrieveDownloadURL(GrooveAPI_Song song) { GrooveJSON JSON = new GrooveJSON(); JSON.WriteHeader("getStreamKeyFromSongIDEx", true); Dictionary<string, object> dlParams = new Dictionary<string, object>(); dlParams.Add("prefetch", false); dlParams.Add("songID", song.ID.Song); dlParams.Add("country", null); dlParams.Add("mobile", false); JSON.WriteParameters(dlParams); JSON.WriteMethod("getStreamKeyFromSongIDEx"); JSON.WriteFinish(); string postJSON = JSON.ToString(); HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://cowbell.grooveshark.com/more.php?getStreamKeyFromSongIDEx"); req.Method = "POST"; req.ContentLength = postJSON.Length; req.ContentType = "application/json"; System.IO.Stream postWriteStream = req.GetRequestStream(); byte[] writeBuf = Encoding.ASCII.GetBytes(postJSON); postWriteStream.Write(writeBuf, 0, writeBuf.Length); postWriteStream.Close(); HttpWebResponse res = (HttpWebResponse)req.GetResponse(); System.IO.Stream readStream = res.GetResponseStream(); string responseJSON = ""; System.IO.StreamReader streamReader = new System.IO.StreamReader(readStream); responseJSON = streamReader.ReadToEnd(); streamReader.Close(); res.Close(); Dictionary<string, object> ResponseDictionary = JSON.Read(responseJSON); Dictionary<string, object> ResultsDictionary = new Dictionary<string, object>(); try { ResultsDictionary = (Dictionary<string, object>)ResponseDictionary["result"]; } catch (Exception) { return false; } try { _streamKeys.Add(ResultsDictionary["streamKey"].ToString()); _streamServers.Add(ResultsDictionary["ip"].ToString()); } catch (Exception) { return false; } if (_streamServers.Last() == "" || _streamKeys.Last() == "") return false; return true; }