Ejemplo n.º 1
0
        private void DownloadAndExtract()
        {
            // 0. Preparation
            string   inProgressDir = Properties.Settings.Default["RootDirPath"].ToString() + "\\Downloaded\\InProgress";
            FileInfo fileInfo;

            // 1. Download video
            Cursor = Cursors.Wait;
            string  video_builtCli = CoreMethods.VideoDownload_BuildCLI_With(TextBox_url.Text);
            Process videoProcess   = new Process()
            {
                StartInfo = CoreMethods.PrepareProcess(video_builtCli)
            };

            videoProcess.EnableRaisingEvents = true;
            videoProcess.OutputDataReceived += (s, o) => Debug.WriteLine(o.Data);
            videoProcess.ErrorDataReceived  += (s, err) => Debug.WriteLine($@"Error: {err.Data}");

            videoProcess.Start();
            videoProcess.BeginOutputReadLine();
            videoProcess.BeginErrorReadLine();
            videoProcess.WaitForExit();

            while (!videoProcess.HasExited)
            {
                continue;
            }
            Cursor = Cursors.Arrow;

            // 2. Move downloaded video from InProgress\ to Video\
            fileInfo = new FileInfo(Directory.GetFiles(inProgressDir)[0]);
            string filepath         = fileInfo.FullName;
            string filename         = fileInfo.Name;
            string videoDestination = Properties.Settings.Default["RootDirPath"].ToString() + @"\Downloaded\Video\" + filename;

            Thread.Sleep(250); // HACK : To be sure the file is not busy anymore, so it's ready to be moved
            File.Move(filepath, videoDestination);

            // 3. Extract audio
            Cursor = Cursors.Wait;
            string  audio_builtCli = CoreMethods.AudioExtraction_BuildCLI_With(videoDestination);
            Process audioProcess   = new Process()
            {
                StartInfo = CoreMethods.PrepareProcess(audio_builtCli)
            };

            audioProcess.EnableRaisingEvents = true;
            audioProcess.OutputDataReceived += (s, o) => Debug.WriteLine(o.Data);
            audioProcess.ErrorDataReceived  += (s, err) => Debug.WriteLine($@"Error: {err.Data}");

            audioProcess.Start();
            audioProcess.BeginOutputReadLine();
            audioProcess.BeginErrorReadLine();
            audioProcess.WaitForExit();

            while (!audioProcess.HasExited)
            {
                continue;
            }
            Cursor = Cursors.Arrow;
            System.Media.SystemSounds.Asterisk.Play();
        }
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é");
        }