Exemplo n.º 1
0
        private void QueueProcessing_4_DoWork(object sender, DoWorkEventArgs e)
        {
            DownloadFile  newFile = e.Argument as DownloadFile;
            var           worker  = (BackgroundWorker)sender;
            YouTubeResult result  = new YouTubeResult();

            try
            {
                worker.ReportProgress(0);

                newFile.YouTubeVideo = this.youTubeManager.GetVideo(newFile);
                worker.ReportProgress(30);

                this.youTubeManager.WriteFileInFolder(newFile);
                worker.ReportProgress(70);

                this.youTubeManager.Execute(newFile); // gets a Video object with info about the video
                worker.ReportProgress(100);

                result.ProcessedFile = newFile;
            }
            catch (Exception ex)
            {
                result.Error         = ex.Message;
                result.ProcessedFile = newFile;
                result.HasError      = true;
            }

            e.Result = result;
        }
Exemplo n.º 2
0
        //async void SaveVideoToDisk(string link)
        //{
        //    var youTube = YouTube.Default; // starting point for YouTube actions
        //    await youTube.GetVideoAsync(link)
        //        .ContinueWith(x => this.WriteFileInFolder(x.Result))
        //        .ContinueWith(x => this.Execute(x.Result)); // gets a Video object with info about the video
        //}

        private void AddLog(YouTubeResult result)
        {
            ListViewItem item = new ListViewItem();

            if (result.HasError)
            {
                item.Text      = result.ProcessedFile.YouTubeVideo != null ? result.ProcessedFile.YouTubeVideo.FullName : item.Text = result.ProcessedFile.YouTubeLink;
                item.BackColor = Color.Red;
                item.ForeColor = Color.White;
                this.errors.Add(result.Error);
                this.lblError1.Text    = result.Error;
                this.lblError1.Visible = true;
            }
            else
            {
                item.Text      = result.ProcessedFile.YouTubeVideo.FullName;
                item.BackColor = Color.Green;
                item.ForeColor = Color.White;
            }

            this.lvLog.Items.Add(item);
        }