Exemple #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());
            }
        }
        public static string VideoDownload_BuildCLI_With(string url)
        {
            string commandLine = "";

            try
            {
                string rootDirPath   = Properties.Settings.Default["RootDirPath"].ToString();
                string downloadedDir = rootDirPath + @"\Downloaded";
                string youtubeDlDir  = rootDirPath + @"\resources\youtube-dl";

                // youtube-dl parameters :
                // -o                   -> Output filename template
                // -q                   -> Quiet mode
                // --console-title      -> Display progression as windows title

                // In cmd.exe, the command line would be :
                // start "" "path/to/youtube-dl.exe" [-option] "path/as/destination/nom.extension" <youtube video url>

                commandLine = String.Format(
                    "/c start \"\" \"{0}\\youtube-dl.exe\" --console-title -o \"{1}\\InProgress\\%(title)s.%(ext)s\" {2}", // -q
                    youtubeDlDir,
                    downloadedDir,
                    url
                    );

                IOMethods.WriteToLog("Command line (video) :\n" + commandLine);
            }
            catch (Exception ex)
            {
                IOMethods.WriteToLog("Erreur dans VideoDownload_BuildCLI_From(string url). Exception =\n" + ex.ToString());
            }

            return(commandLine);
        }
Exemple #3
0
        private void SetAudioQuality(int bitrate)
        {
            try
            {
                switch (bitrate)
                {
                case 128000:
                    RadioButton_mp3_128.IsChecked = true;
                    break;

                case 256000:
                    RadioButton_mp3_256.IsChecked = true;
                    break;

                case 320000:
                    RadioButton_mp3_320.IsChecked = true;
                    break;

                default:
                    return;
                }
            }
            catch (Exception ex)
            {
                IOMethods.WriteToLog("Erreur dans SetAudioQuality(int bitrate). Exception =\n" + ex.ToString());
            }
        }
Exemple #4
0
        private void LoadSettings()
        {
            try
            {
                Properties.Settings.Default["RootDirPath"] = IOMethods.GetRootDirPath();

                bool isReadOnly = Convert.ToBoolean(Properties.Settings.Default["TextBox_readonly"]);
                SetTextBoxReadOnly(isReadOnly);

                int audioBitrate = Convert.ToInt32(Properties.Settings.Default["AudioBitrate"]);
                SetAudioQuality(audioBitrate);
            }
            catch (Exception ex)
            {
                IOMethods.WriteToLog("Erreur dans LoadSettings(). Exception =\n" + ex.ToString());
            }
        }
 public static ProcessStartInfo PrepareProcess(string cli)
 {
     try
     {
         return(new ProcessStartInfo("cmd.exe")
         {
             Arguments = cli,
             CreateNoWindow = true,
             RedirectStandardOutput = true,
             RedirectStandardError = true,
             UseShellExecute = false
         });
     }
     catch (Exception ex)
     {
         IOMethods.WriteToLog("Erreur dans ExecuteCLI_With(string cli). Exception =\n" + ex.ToString());
         return(null);
     }
 }
Exemple #6
0
 private void SetTextBoxReadOnly(bool readOnly)
 {
     try
     {
         if (readOnly)
         {
             TextBox_url.IsReadOnly = true;
             TextBox_url.Cursor     = Cursors.Arrow;
             TextBox_url.Background = (Brush) new BrushConverter().ConvertFrom("#F2F2F2");
         }
         else
         {
             TextBox_url.IsReadOnly = false;
             TextBox_url.Cursor     = Cursors.IBeam;
             TextBox_url.Background = new SolidColorBrush(Colors.Transparent);
         }
     }
     catch (Exception ex)
     {
         IOMethods.WriteToLog("Erreur dans SetReadOnly(bool flag). Exception =\n" + ex.ToString());
     }
 }
        //public static List<string> Audio_BuildCLI_WithTEST(string filepath)
        //{
        //    List<string> ls = new List<string>();


        //}



        public static string AudioExtraction_BuildCLI_With(string filepath)
        {
            string commandLine = "";

            try
            {
                FileInfo fileInfo             = new FileInfo(filepath);
                string   filename             = fileInfo.Name;
                string   filename_noExtension = filename.Substring(0, filename.Length - fileInfo.Extension.Length);
                string   ffmpegDir            = Properties.Settings.Default["RootDirPath"].ToString() + @"\resources\ffmpeg";

                // FFmpeg parameters :
                // -i         -> ignore error
                // -f         -> output format
                // -ab        -> audio bitrate
                // -vn        -> don't include video

                // In cmd.exe, the command line would be :
                // start "" "path/to/youtube-dl.exe" [-options] "path/as/destination/name.extension" <youtube video url>

                commandLine = String.Format(
                    "/c start \"\" \"{0}\\bin\\ffmpeg.exe\" -i \"{1}\" -f mp3 -ab {2} -vn \"{3}\\Downloaded\\Audio\\{4}.mp3\"",
                    ffmpegDir,
                    filepath,
                    Properties.Settings.Default["AudioBitrate"].ToString(),
                    Properties.Settings.Default["RootDirPath"].ToString(),
                    filename_noExtension
                    );
                IOMethods.WriteToLog("Command line (audio) :\n" + commandLine);
            }
            catch (Exception ex)
            {
                IOMethods.WriteToLog("Erreur dans AudioExtraction_BuildCLI_From(string filepath). Exception =\n" + ex.ToString());
            }

            return(commandLine); // TODO : return filename too ?
        }
Exemple #8
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é");
        }
Exemple #9
0
 private void Button_ToVideoFolder_Click(object sender, RoutedEventArgs e)
 {
     IOMethods.OpenFolder("Video");
 }