Example #1
0
        private async void DownloadButton_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(UrlTextBox.Text))
            {
                MessageBox.Show("Please enter a valid YouTube URL.", "Invalid or Empty URL");
            }
            else if (string.IsNullOrEmpty(DownloadPathTextBox.Text))
            {
                MessageBox.Show("Please select a download path.", "Invalid or Empty Download Path");
            }
            else
            {
                try
                {
                    string url    = UrlTextBox.Text;
                    string dlPath = DownloadPathTextBox.Text;

                    DisableControls();

                    if (Downloader.UrlIsPlaylist(url))
                    {
                        List <DownloadItem> items = await _downloader.DownloadPlaylistAudio(url, dlPath, new Progress <ProgressItem>(i => ReportProgress(i)));
                    }

                    else
                    {
                        DownloadItem item = await _downloader.DownloadAudio(url, dlPath, new Progress <DownloadItem>(i => DisplayItem(i)));
                    }
                }
                catch (Exception ex)
                {
                    EnableControls();
                    MessageBox.Show($"Error: {ex.Message}", "Error");
                    return;
                }

                EnableControls();
                MessageBox.Show("The operation completed. Check the appropriate download lists.", "Finished");
            }
        }