Пример #1
0
        public static async Task DownloadAllSongs(ListBox InfoList, Label ProgressBar)
        {
            foreach (var value in InfoList.Items)
            {
                try
                {
                    var down_name = value.ToString();
                    var regex     = "(\\[.*\\])|(\".*\")|('.*')|(\\(.*\\))";
                    down_name = Regex.Replace(down_name, regex, "");
                    down_name = down_name.Trim();

                    await Functions.DownloadSong(down_name, ProgressBar);

                    FormProperties.DownloadStatus("Set", "Start");
                    FormProperties.DownloadStatus("Set", "InProgress");
                    FormProperties.DownloadStatus("Set", "Completed");
                    ProgressBar.Text = "Completed";
                }
                catch
                {
                    Console.Write("Failure.");
                    FormProperties.DownloadStatus("Set", "Failure");
                }
            }
            return;
        }
Пример #2
0
        private async void DownloadAll_Click(object sender, EventArgs e)
        {
            if (enabled == false)
            {
                enabled               = true;
                Navigate              = false;
                Download.ForeColor    = Color.FromArgb(255, 100, 100, 100);
                DownloadAll.ForeColor = Color.FromArgb(255, 100, 100, 100);
                await Functions.DownloadAllSongs(ListInfo, ProgressDisplay);

                string status = FormProperties.DownloadStatus("Get", null);

                if (status == "Failure")
                {
                    Download.ForeColor    = Color.FromArgb(255, 255, 255, 255);
                    DownloadAll.ForeColor = Color.FromArgb(255, 100, 0, 0);
                }
                else if (status == "Completed")
                {
                    Download.ForeColor    = Color.FromArgb(255, 255, 255, 255);
                    DownloadAll.ForeColor = Color.FromArgb(255, 255, 255, 255);
                }

                enabled  = false;
                Navigate = true;
            }
        }
Пример #3
0
        public async void Download_Click(object sender, EventArgs e)
        {
            if (enabled == false)
            {
                if (ListInfo.SelectedItem != null)
                {
                    enabled               = true;
                    Navigate              = false;
                    Download.ForeColor    = Color.FromArgb(255, 100, 100, 100);
                    DownloadAll.ForeColor = Color.FromArgb(255, 100, 100, 100);

                    var down_name = ListInfo.SelectedItem.ToString();
                    var regex     = "(\\[.*\\])|(\".*\")|('.*')|(\\(.*\\))";
                    down_name = Regex.Replace(down_name, regex, "");
                    down_name = down_name.Trim();

                    await Functions.DownloadSong(down_name, ProgressDisplay);

                    string status = FormProperties.DownloadStatus("Get", null);

                    if (status == "Failure")
                    {
                        Download.ForeColor    = Color.FromArgb(255, 100, 0, 0);
                        DownloadAll.ForeColor = Color.FromArgb(255, 255, 255, 255);
                    }
                    else if (status == "Completed")
                    {
                        Download.ForeColor    = Color.FromArgb(255, 255, 255, 255);
                        DownloadAll.ForeColor = Color.FromArgb(255, 255, 255, 255);
                    }

                    enabled  = false;
                    Navigate = true;
                }
            }
        }
Пример #4
0
        public static async Task DownloadSong(string name, Label ProgressBar)
        {
            if (name != null & name != "")
            {
                //
                var values = new Dictionary <string, string>
                {
                    { "submit", "submit" },
                    { "cmdownloadname", name }
                };
                var content = new FormUrlEncodedContent(values);

                try
                {
                    Dictionary <string, string> siteinfo = ReturnSiteInfo();

                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(siteinfo["Main"] + "RBX-C/phpget.php");
                    request.Method    = "POST";
                    request.Timeout   = 1000;
                    request.UserAgent = "Mozilla/5.0 (Linux; U; Android 4.0.4; pt-br; MZ608 Build/7.7.1-141-7-FLEM-UMTS-LA) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30";

                    byte[] contents = await content.ReadAsByteArrayAsync();

                    request.ContentLength = contents.Length;
                    request.ContentType   = "application/x-www-form-urlencoded";
                    Stream dataStream = request.GetRequestStream();
                    dataStream.Write(contents, 0, contents.Length);
                    dataStream.Close();
                    WebResponse response = await request.GetResponseAsync();

                    Stream data = response.GetResponseStream();

                    string DIR = "music";

                    int total = new int();
                    //var datatotal = SizeSuffix(GetStreamLength(data));

                    FormProperties.DownloadStatus("Set", "Start");

                    var ctype = response.Headers.Get("Content-Type");
                    var ext   = ".unknown";

                    if (ctype == "audio/mpeg")
                    {
                        ext = ".mp3";
                    }
                    else if (ctype == "audio/ogg")
                    {
                        ext = ".ogg";
                    }


                    using (FileStream DestinationStream = File.Create(DIR + "\\" + values["cmdownloadname"] + ext))
                    {
                        FormProperties.DownloadStatus("Set", "InProgress");
                        byte[] buffer = new byte[16 * 2048];
                        int    read;

                        while ((read = data.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            string totalstring = SizeSuffix(total);
                            total            = total + read;
                            ProgressBar.Text = totalstring;
                            await DestinationStream.WriteAsync(buffer, 0, read);

                            ProgressBar.Text = "Completed";
                        }
                        DestinationStream.Close();
                        FormProperties.DownloadStatus("Set", "Completed");
                        return;
                    }
                }
                catch
                {
                    Console.Write("Failure.");
                    FormProperties.DownloadStatus("Set", "Failure");
                }

                //
            }
        }