示例#1
0
 private void RunNewDownloadWorker(string server, string streamkey, GrooveAPI_Song song)
 {
     GrooveAPI_DownloadWorker worker = new GrooveAPI_DownloadWorker(server, streamkey, song);
     worker.ProgressChanged += new ProgressChangedEventHandler(_WorkerProgressChanged);
     worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(_WorkerCompleted);
     worker.RunWorkerAsync();
     Helpers.ThreadNeutralAction(InterfaceType.IT_PROGRESS,
         new MethodInvoker(() => { Information.Progress.DownloadBeginning(song); }));
     Log(LogType.LT_DOWNLOAD | LogType.LT_INFO, "Downloading " + Helpers.CalculateFileName(song));
     _downloaders.Add(worker);
 }
 public GrooveAPI_DownloadWorker(string downloadURL, string streamKey, GrooveAPI_Song song)
 {
     _downloadURL = "http://" + downloadURL + "/stream.php";
     _streamKey = streamKey;
     _song = song;
     _fileName = Helpers.CalculateFileName(song);
     try
     {
         System.IO.Directory.CreateDirectory(Information.BaseDownloadDirectory + _fileName.Substring(0, _fileName.LastIndexOf('\\') + 1));
     }
     catch (Exception)
     {
         Log(LogType.LT_DOWNLOAD | LogType.LT_ERROR, "Could not download to directory" + Information.BaseDownloadDirectory);
         Dispose();
     }
 }
示例#3
0
 public void StartDownload(GrooveAPI_Song song)
 {
     _ResetWorkers();
     _downloader.Songs.Add(song);
     _downloader.RunWorkerAsync();
 }
示例#4
0
        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;
        }