Beispiel #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();
            }
        }
Beispiel #2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            new Thread(() =>
            {
                //Version number
                System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
                FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
                lblVersion.Invoke((MethodInvoker)(() =>
                {
                    lblVersion.Text = "Version " + fvi.FileVersion;
                }));

                ucSettings = new UCSettings();
                ucHistory  = new UCHistory();



                //Clear the .mp4 files in the folder if the application has been exited during downloading/converting
                if (FSManager.Files.GetFileNamesInFolder(BLIO.rootFolder + "\\Video\\").Length > 0)
                {
                    FSManager.Folders.DeleteFilesInFolder(BLIO.rootFolder + "\\Video\\");
                }

                if (!File.Exists(BLSettings.SoundFile))
                {//Sound file from the database doesn't exist. Set to default
                    BLSettings.SoundFile = null;
                }


                LoadUserControls();
            }).Start();
        }
Beispiel #3
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);
        }