Пример #1
0
        private void lblExit_Click(object sender, EventArgs e)
        {
            if (isDownloading)
            {
                ctsDownload.Cancel(false);

                DownloadItemManager.toDeleteFiles.Add(pathToVideo);
                DownloadItemManager.StartTimer();
            }

            if (isConverting)
            {
                //Cancel the convert task
                ctsConvert.Cancel(false);
                FFMpegConverter.Abort();

                DownloadItemManager.toDeleteFiles.Add(pathToSong);
                DownloadItemManager.StartTimer();
            }



            this.Dispose();
            if (isHistory)
            {
                BLHistory.RemoveRecord(historyRecord);
                UCHistory.RepositionDownloadItems();
            }
            else
            {
                DownloadItemManager.RepositionDownloadItems();
            }
        }
Пример #2
0
        private void UCHistory_Load(object sender, EventArgs e)
        {
            pnlVideos.AutoScrollPosition = new Point(pnlVideos.AutoScrollPosition.X, 0);
            new Thread(() =>
            {
                if (BLHistory.GetHistory().Count == 0)
                {
                    lblNoHistory.Invoke((MethodInvoker)(() =>
                    {
                        lblNoHistory.Visible = true;
                    }));
                }

                foreach (DownloadHistory history in BLHistory.GetHistory().OrderBy(d => Convert.ToDateTime(d.DownloadDate)))
                {
                    int y = 0;
                    if (items.Count > 0)
                    {
                        y = items.Count * items.Where(itm => !itm.IsDisposed).ToList()[0].Height;
                    }

                    DownloadItem toAddItem = new DownloadItem(history);
                    toAddItem.Location     = new Point(toAddItem.Location.X, y);
                    items.Add(toAddItem);


                    pnlVideos.Invoke((MethodInvoker)(() =>
                    {
                        toAddItem.Visible = true;
                        pnlVideos.Controls.Add(toAddItem);
                    }));
                }
            }).Start();
        }
Пример #3
0
 public void AddHistory(DownloadItem vid)
 {
     pnlVideos.Invoke((MethodInvoker)(() =>
     {
         if (BLHistory.GetHistory().Where(i => i.VideoId == vid.theVideo.Id).ToList().Count == 0) //No entry in the history yet. Add it to the panel.
         {
             items.Add(vid);
             pnlVideos.Controls.Add(vid);
         }
     }));
 }
Пример #4
0
        private void ConvertToMp3(string filePath)
        {
            //Start converting into .mp3
            convertTask = Task.Factory.StartNew(async() =>
            {
                lblStatus.Invoke((MethodInvoker)(() =>
                {
                    isConverting = true;
                    pbLoad.BackgroundImage = null;
                    pbLoad.Image = Properties.Resources.load25x25;
                    lblStatus.Text = "Converting...";
                }));

                FFMpegConverter = new NReco.VideoConverter.FFMpegConverter();
                FFMpegConverter.FFMpegToolPath   = BLIO.rootFolder + "\\Video\\";
                FFMpegConverter.ConvertProgress += (o, args) =>
                {
                    try
                    {
                        pbDownload.Invoke((MethodInvoker)(() =>
                        {
                            pbDownload.Value = (int)Math.Round((args.Processed.TotalMilliseconds / args.TotalDuration.TotalMilliseconds) * 100);
                            if (pbDownload.Value >= 99)
                            {
                                tmrCheckProgress.Start();
                            }
                        }));
                    }
                    catch (InvalidOperationException) { }//Thread aborted, can't do things with the controls anymore


                    Console.WriteLine(string.Format("Progress: {0} / {1}\r\n", args.Processed, args.TotalDuration));
                };


                pathToSong = GetValidFilePath(BLSettings.MP3Path, theVideo.Title, "." + BLSettings.AudioType);

                try
                {
                    //Create directory in case it doesnt exist
                    Directory.CreateDirectory(Path.GetDirectoryName(pathToSong));

                    await Task.Run(() => FFMpegConverter.ConvertMedia(filePath, pathToSong, BLSettings.AudioType));
                    if (File.Exists(pathToSong))
                    {
                        DownloadHistory historyRecord = new DownloadHistory();
                        historyRecord.ChannelTitle    = theVideo.Author;
                        historyRecord.DownloadDate    = DateTime.Now.ToString();
                        historyRecord.Duration        = theVideo.Duration.ToString();
                        historyRecord.ThumbnailLink   = "http://img.youtube.com/vi/" + theVideo.Id + "/0.jpg";
                        historyRecord.Title           = theVideo.Title;
                        historyRecord.VideoId         = theVideo.Id;

                        UCHistory history = (UCHistory)this.Parent.Parent.Parent.Controls["ucHistory"];
                        DownloadItem item = new DownloadItem(historyRecord);
                        item.theVideo     = theVideo;
                        history.AddHistory(item);

                        BLHistory.InsertRecord(historyRecord);



                        if (BLSettings.KeepMp4)
                        {
                            File.Move(BLIO.rootFolder + "\\Video\\" + RemoveIllegalCharacters(Path.GetFileNameWithoutExtension(filePath)) + "." + BLSettings.VideoType, BLSettings.VideoPath + "\\" + RemoveIllegalCharacters(Path.GetFileNameWithoutExtension(filePath)) + "." + BLSettings.VideoType);
                        }
                        else
                        {
                            File.Delete(BLIO.rootFolder + "\\Video\\" + RemoveIllegalCharacters(filePath) + "." + BLSettings.VideoType);
                        }
                    }
                }
                catch (NullReferenceException) { } //Nullreference exception occurs when aborting the convert task
            }, ctsConvert.Token);
        }