Ejemplo n.º 1
0
        //private void DisplayHelpToolTip()
        //{
        //    Label_Help.ToolTip =
        //        Properties.Resources.Help_AudioBitrate +
        //        "\n\n----------\n\n" +
        //        Properties.Resources.Help_RetrieveContent;
        //}

        private void HandleDrop(DragEventArgs e)
        {
            try
            {
                if (IOMethods.DropType_isFile(e))
                {
                    FileInfo fileInfo = new FileInfo(((string[])e.Data.GetData(DataFormats.FileDrop))[0]);
                    if (IOMethods.ValidateFileExtension(fileInfo))
                    {
                        TextBox_url.Text = fileInfo.FullName;
                        return;
                    }
                    MessageBox.Show("Erreur : Fichier non supporté.");
                    return;
                }

                if (IOMethods.DropType_isURL(e))
                {
                    TextBox_url.Text = e.Data.GetData(DataFormats.UnicodeText).ToString();
                    return;
                }
                MessageBox.Show("Erreur : Doit être spécifié soit l'URL d'une vidéo Youtube, soit le lien complet vers un fichier vidéo.");
            }
            catch (Exception ex)
            {
                IOMethods.WriteToLog("Erreur dans HandleDrop(DragEventArgs e). Exception =\n" + ex.ToString());
            }
        }
Ejemplo n.º 2
0
        private void Button_Download_Click(object sender, RoutedEventArgs e)
        {
            string textBoxInput = TextBox_url.Text;


            if (textBoxInput == "")
            {
                MessageBox.Show("Erreur : Pas d'URL ou de fichier vidéo spécifié");
                return;
            }


            if ((int)Properties.Settings.Default["AudioBitrate"] == 0)
            {
                MessageBox.Show("Erreur : Qualité audio MP3 non définie");
                return;
            }


            if (File.Exists(textBoxInput))
            {
                if (IOMethods.ValidateFileExtension(new FileInfo(textBoxInput)))
                {
                    // It's a video file and it is supported : Do audio extraction
                    string  audio_builtCli = CoreMethods.AudioExtraction_BuildCLI_With(textBoxInput);
                    Process process        = new Process()
                    {
                        StartInfo = CoreMethods.PrepareProcess(audio_builtCli)
                    };

                    process.EnableRaisingEvents = true;
                    process.OutputDataReceived += (s, o) => Debug.WriteLine(o.Data);
                    process.ErrorDataReceived  += (s, err) => Debug.WriteLine($@"Error: {err.Data}");
                    process.Start();
                    Cursor = Cursors.Wait;
                    process.BeginOutputReadLine();
                    process.BeginErrorReadLine();
                    process.WaitForExit();

                    while (!process.HasExited)
                    {
                        continue;
                    }
                    Cursor = Cursors.Arrow;
                    System.Media.SystemSounds.Asterisk.Play();
                    return;
                }
                MessageBox.Show("Erreur : Le format du fichier spécifié n'est pas supporté");
                return;
            }


            if (Uri.IsWellFormedUriString(textBoxInput, UriKind.Absolute))
            {
                if (textBoxInput.Contains("youtube.com/watch?") | textBoxInput.Contains("youtu.be/"))
                {
                    // It must be a Youtube video URL : Download video & Extract audio
                    DownloadAndExtract();
                    return;
                }
                MessageBox.Show("Erreur : L'URL donnée n'est pas celle d'une vidéo Youtube");
                return;
            }
            MessageBox.Show("Erreur : L'entrée texte ne désigne ni une URL Youtube, ni un fichier vidéo supporté");
        }