Exemplo n.º 1
0
        public byte[] Download(Track track)
        {
            try
            {
                WebDownload c = new WebDownload();
                c.Timeout = Config.GetInstance().DownloadTimeout;

                return c.DownloadData(track.Uri);
            }
            catch (Exception e)
            {
                Console.WriteLine("VKComDataProvider error: " + e.Message);
            }
            return null;
        }
Exemplo n.º 2
0
        public byte[] Download(Track track)
        {
            try
            {
                string url = "http://vk.com/al_audio.php";
                string parameters = "act=reload_audio&al=1&ids=" + HttpUtility.UrlEncode(track.Uri.OriginalString);

                string content = MakeRequest(url, parameters, _cookie);

                var trackUrl = content.Split(new string[] { "<!json>[[" }, StringSplitOptions.None)[1].Split(',')[2];
                trackUrl = Regex.Unescape(trackUrl).Replace("\"", "");
                track.Uri = new Uri(trackUrl);

                WebDownload downloader = new WebDownload();
                downloader.Timeout = Config.GetInstance().DownloadTimeout;

                Stream trackStream = downloader.OpenRead(track.Uri);
                MemoryStream resultStream = new MemoryStream();

                byte[] buffer = new byte[4096];
                while (trackStream.CanRead)
                {
                    Array.Clear(buffer, 0, buffer.Length);
                    int bytesRead = trackStream.Read(buffer, 0, buffer.Length);

                    if (bytesRead == 0)
                    {
                        break;
                    }

                    resultStream.Write(buffer, 0, bytesRead);
                }

                return resultStream.ToArray();
            }
            catch (Exception e)
            {
                Console.WriteLine("VKComDataProvider error: " + e.Message);
            }
            return null;
        }