Exemplo n.º 1
0
        private void btnBatchDownloadStartStopExit_Click(object sender, EventArgs e)
        {
            if (Program.IsDebug)
            {
                Batch.Default.SelectedType = cbBatchDownloadType.SelectedIndex;
                if (cbBatchDownloadType.SelectedIndex == 0)
                {
                    Batch.Default.DownloadVideoSound   = chkBatchDownloaderSoundVBR.Checked;
                    Batch.Default.SelectedVideoQuality = cbBatchQuality.SelectedIndex;
                    Batch.Default.SelectedVideoFormat  = cbBatchFormat.SelectedIndex;
                }
                else if (cbBatchDownloadType.SelectedIndex == 1)
                {
                    if (chkBatchDownloaderSoundVBR.Checked)
                    {
                        Batch.Default.DownloadAudioVBR        = true;
                        Batch.Default.SelectedAudioQualityVBR = cbBatchQuality.SelectedIndex;
                    }
                    else
                    {
                        Batch.Default.DownloadAudioVBR     = false;
                        Batch.Default.SelectedAudioQuality = cbBatchQuality.SelectedIndex;
                    }
                    Batch.Default.SelectedAudioFormat = cbBatchFormat.SelectedIndex;
                }
                else if (cbBatchDownloadType.SelectedIndex == 2)
                {
                    Batch.Default.CustomArguments = txtBatchDownloadVideoSpecificArgument.Text;
                }
                if (!Program.IsPortable)
                {
                    Batch.Default.Save();
                }
            }

            if (DownloadUrls.Count == 0)
            {
                return;
            }
            if (InProgress)
            {
                Downloader.Dispose();
            }
            else if (lvBatchDownloadQueue.Items.Count > 0)
            {
                btnBatchDownloadRemoveSelected.Enabled = false;
                btnBatchDownloadStartStopExit.Text     = lang.btnBatchDownloadStop;
                InProgress = true;
                string BatchTime = "\\# Batch Downloads #" + BatchDownloader.CurrentTime();
                for (int i = 0; i < DownloadUrls.Count; i++)
                {
                    CurrentItem = i;
                    Downloader  = new frmDownloader();
                    Downloader.BatchDownload = true;
                    Downloader.BatchTime    += BatchTime;
                    Downloader.DownloadUrl   = DownloadUrls[i];
                    Downloader.DownloadPath  = Downloads.Default.downloadPath;
                    if (DownloadTypes[i] != 2)
                    {
                        Downloader.DownloadQuality = DownloadQuality[i];
                        Downloader.DownloadFormat  = DownloadFormat[i];
                    }
                    switch (DownloadTypes[i])
                    {
                    case 0:
                        Downloader.DownloadVideoAudio = DownloadSoundVBR[i];
                        Downloader.DownloadType       = 0;
                        break;

                    case 1:
                        Downloader.DownloadType = 1;
                        Downloader.UseVBR       = DownloadSoundVBR[i];
                        break;

                    case 2:
                        Downloader.DownloadArguments = DownloadArgs[i];
                        Downloader.DownloadType      = 2;
                        break;

                    default:
                        continue;
                    }
                    lvBatchDownloadQueue.Items[i].ImageIndex = (int)BatchDownloader.ConversionIcon.Downloading;

                    bool AbortDownload = false;
                    sbBatchDownloader.Text = lang.sbBatchDownloaderDownloading;
                    switch (Downloader.ShowDialog())
                    {
                    case System.Windows.Forms.DialogResult.Yes:
                        lvBatchDownloadQueue.Items[i].ImageIndex = (int)BatchDownloader.ConversionIcon.Finished;
                        break;

                    case System.Windows.Forms.DialogResult.No:
                        lvBatchDownloadQueue.Items[i].ImageIndex = (int)BatchDownloader.ConversionIcon.Errored;
                        break;

                    case System.Windows.Forms.DialogResult.Abort:
                        lvBatchDownloadQueue.Items[i].ImageIndex = (int)BatchDownloader.ConversionIcon.Waiting;
                        break;

                    case System.Windows.Forms.DialogResult.Ignore:
                        lvBatchDownloadQueue.Items[i].ImageIndex = (int)BatchDownloader.ConversionIcon.Waiting;
                        AbortDownload = true;
                        break;

                    default:
                        lvBatchDownloadQueue.Items[i].ImageIndex = (int)BatchDownloader.ConversionIcon.Finished;
                        break;
                    }
                    if (AbortDownload)
                    {
                        break;
                    }
                }
                InProgress = false;
                System.Media.SystemSounds.Exclamation.Play();
                sbBatchDownloader.Text             = lang.sbBatchDownloaderFinished;
                btnBatchDownloadStartStopExit.Text = lang.btnBatchDownloadStart;
            }
        }
        private void btnBatchDownloadStartStopExit_Click(object sender, EventArgs e)
        {
            if (DownloadUrls.Count == 0)
            {
                return;
            }
            if (InProgress)
            {
                Downloader.Dispose();
            }
            else if (lvBatchDownloadQueue.Items.Count > 0)
            {
                btnBatchDownloadRemoveSelected.Enabled = false;
                btnBatchDownloadStartStopExit.Text     = lang.btnBatchDownloadStop;
                InProgress = true;
                string BatchTime = BatchDownloader.CurrentTime();
                for (int i = 0; i < DownloadUrls.Count; i++)
                {
                    CurrentItem           = i;
                    Downloader            = new frmDownloader();
                    NewInfo               = new DownloadInfo();
                    NewInfo.BatchDownload = true;
                    NewInfo.BatchTime     = BatchTime;
                    NewInfo.DownloadURL   = DownloadUrls[i];
                    switch (DownloadTypes[i])
                    {
                    case 0:
                        NewInfo.Type               = DownloadType.Video;
                        NewInfo.VideoQuality       = (VideoQualityType)DownloadQuality[i];
                        NewInfo.VideoFormat        = (VideoFormatType)DownloadFormat[i];
                        NewInfo.SkipAudioForVideos = !DownloadSoundVBR[i];
                        break;

                    case 1:
                        NewInfo.Type = DownloadType.Audio;
                        if (DownloadSoundVBR[i])
                        {
                            NewInfo.UseVBR          = true;
                            NewInfo.AudioVBRQuality = (AudioVBRQualityType)DownloadQuality[i];
                        }
                        else
                        {
                            NewInfo.UseVBR          = false;
                            NewInfo.AudioCBRQuality = (AudioCBRQualityType)DownloadQuality[i];
                        }
                        NewInfo.AudioFormat = (AudioFormatType)DownloadFormat[i];
                        break;

                    case 2:
                        NewInfo.Type = DownloadType.Custom;
                        NewInfo.DownloadArguments = DownloadArgs[i];
                        break;

                    default:
                        continue;
                    }
                    lvBatchDownloadQueue.Items[i].ImageIndex = (int)BatchDownloader.ConversionIcon.Downloading;

                    bool AbortDownload = false;
                    sbBatchDownloader.Text = lang.sbBatchDownloaderDownloading;
                    switch (Downloader.ShowDialog())
                    {
                    case System.Windows.Forms.DialogResult.Yes:
                        lvBatchDownloadQueue.Items[i].ImageIndex = (int)BatchDownloader.ConversionIcon.Finished;
                        break;

                    case System.Windows.Forms.DialogResult.No:
                        lvBatchDownloadQueue.Items[i].ImageIndex = (int)BatchDownloader.ConversionIcon.Errored;
                        break;

                    case System.Windows.Forms.DialogResult.Abort:
                        lvBatchDownloadQueue.Items[i].ImageIndex = (int)BatchDownloader.ConversionIcon.Waiting;
                        break;

                    case System.Windows.Forms.DialogResult.Ignore:
                        lvBatchDownloadQueue.Items[i].ImageIndex = (int)BatchDownloader.ConversionIcon.Waiting;
                        AbortDownload = true;
                        break;

                    default:
                        lvBatchDownloadQueue.Items[i].ImageIndex = (int)BatchDownloader.ConversionIcon.Finished;
                        break;
                    }
                    if (AbortDownload)
                    {
                        break;
                    }
                }
                InProgress = false;
                System.Media.SystemSounds.Exclamation.Play();
                sbBatchDownloader.Text             = lang.sbBatchDownloaderFinished;
                btnBatchDownloadStartStopExit.Text = lang.btnBatchDownloadStart;
            }
        }