示例#1
0
        private void CompletedGetPlaylist(object sender, RunWorkerCompletedEventArgs e)
        {
            // Quando terminar de buscar as urls no modo playlist

            PlaylistReturn ret = (PlaylistReturn)e.Result;

            if (ret.Item1 == 0)
            {
                var firstRet   = ret.Item2 as Tuple <string, List <Tuple <string, string> > >;
                var toDownload = firstRet.Item2 as List <Tuple <string, string> >;

                otherForm = new ListForm(toDownload, this);
                otherForm.Show();

                downWorker = new BackgroundWorker {
                    WorkerSupportsCancellation = true
                };
                downWorker.DoWork             += otherForm.Download;
                downWorker.RunWorkerCompleted += CompletedMultipleDownload;
                downWorker.RunWorkerAsync(firstRet.Item1 as string);
            }
            else
            {
                CmdReturn cmdRet = (CmdReturn)ret.Item2;
                ShowMessage(String.Format(OPT3_ERROR, cmdRet.Item1, cmdRet.Item2), DOWNLOAD_ERROR_TITLE);
                ChangeControlsState(true);
            }
        }
示例#2
0
        private void DownloadList(string fname, string dir)
        {
            // Baixa um lista (em um arquivo) de musicas

            var toDownload = new List <Tuple <string, string> >();

            // Read file
            using (StreamReader reader = new StreamReader(fname)) {
                string line;

                while ((line = reader.ReadLine()) != null)
                {
                    line = line.Trim(' ');
                    if (line == "")
                    {
                        continue;
                    }

                    string url = line.Split(new[] { ' ' })[0];
                    if (url.Length == 0)
                    {
                        continue;
                    }

                    string name = line.Substring(url.Length, line.Length - url.Length).Trim(' ');
                    if (name == "")
                    {
                        name = "%(title)s";
                    }

                    var tup = new Tuple <string, string>(url, name);
                    toDownload.Add(tup);
                }
            }

            otherForm = new ListForm(toDownload, this);
            otherForm.Show();

            downWorker = new BackgroundWorker {
                WorkerSupportsCancellation = true
            };
            downWorker.DoWork             += otherForm.Download;
            downWorker.RunWorkerCompleted += CompletedMultipleDownload;
            downWorker.RunWorkerAsync(dir);
        }