Ejemplo n.º 1
0
        private void ExtractAudio(string path)
        {
            var flvFile = new FlvFile(path, this.SavePath);

            flvFile.ConversionProgressChanged +=
                (sender, args) => this.OnProgressChanged(new ProgressEventArgs(50 + args.ProgressPercentage / 2));

            flvFile.ExtractStreams();
        }
Ejemplo n.º 2
0
        private void ExtractAudio(string path)
        {
            var flvFile = new FlvFile(path, this.SavePath);

            flvFile.ConversionProgressChanged +=
                (sender, args) => this.OnProgressChanged(new ProgressEventArgs(50 + args.ProgressPercentage / 2));

            flvFile.ExtractStreams();
        }
Ejemplo n.º 3
0
        private void ExtractAudio(string path)
        {
            using (var flvFile = new FlvFile(path, this.SavePath))
            {
                flvFile.ConversionProgressChanged += (sender, args) =>
                {
                    if (this.AudioExtractionProgressChanged != null)
                    {
                        this.AudioExtractionProgressChanged(this, new ProgressEventArgs(args.ProgressPercentage));
                    }
                };

                flvFile.ExtractStreams();
            }
        }
        private void ExtractAudio(string path)
        {
            var flvFile = new FlvFile(path, this.SavePath);

            flvFile.ConversionProgressChanged += (sender, args) =>
            {
                // Backwards compatibility
                this.OnProgressChanged(new ProgressEventArgs(50 + args.ProgressPercentage / 2));

                if (this.AudioExtractionProgressChanged != null)
                {
                    this.AudioExtractionProgressChanged(this, new ProgressEventArgs(args.ProgressPercentage));
                }
            };

            flvFile.ExtractStreams();

            flvFile.Dispose();
        }
Ejemplo n.º 5
0
        private void ExtractAudio(string path)
        {
            var flvFile = new FlvFile(path, this.SavePath);

            flvFile.ConversionProgressChanged += (sender, args) =>
            {
                // Backwards compatibility
                this.OnProgressChanged(new ProgressEventArgs(50 + args.ProgressPercentage / 2));

                if (this.AudioExtractionProgressChanged != null)
                {
                    this.AudioExtractionProgressChanged(this, new ProgressEventArgs(args.ProgressPercentage));
                }
            };

            flvFile.ExtractStreams();

            flvFile.Dispose();
        }
Ejemplo n.º 6
0
        private void ExtractAudio(string path)
        {
            using (var flvFile = new FlvFile(path, this.SavePath))
            {
                flvFile.ConversionProgressChanged += (sender, args) =>
                {
                    if (this.AudioExtractionProgressChanged != null)
                    {
                        this.AudioExtractionProgressChanged(this, new ProgressEventArgs(args.ProgressBytes, args.ProgressPercentage));
                    }
                };

                flvFile.ExtractStreams();
            }
        }
        private async Task ExtractAudio(string path) {
            var cache = new FileInfo(context.audioSaveableFilename); //target cache
            var SavePath = context.audioSaveableFilename;//to universal string
            for (int i = 1; File.Exists(SavePath); i++) {
                SavePath = Path.Combine(cache.Directory.FullName, $"{cache.Name.Replace(cache.Extension,"")} ({i}){cache.Extension}");
            }
            context.AudioPath = new FileInfo(SavePath);
            switch (context.VideoInfo.VideoType) {
                case VideoType.Mobile:
                    break;
                case VideoType.Flash:
                    using (var flvFile = new FlvFile(path, SavePath)) {
                        flvFile.ConversionProgressChanged += (sender, args) => {
                            context.OnProgresStateChanged(YoutubeStage.ExtractingAudio, args.ProgressPercentage);
                        };

                        await Task.Run(()=>flvFile.ExtractStreams());
                    }
                    break;
                case VideoType.Mp4:
                    var @in = new MediaFile(path);
                    var @out = new MediaFile(SavePath);
                    using (var engine = new Engine()) {
                        //Desperate attempt to catch the extraction from the MediaToolkit lib but it simply does not pass into those events.
                        //engine.ConvertProgressEvent += (sender, args) => AudioExtractionProgressChanged?.Invoke(this, new ProgressEventArgs((args.ProcessedDuration.TotalMilliseconds / args.TotalDuration.TotalMilliseconds) * 100f));
                        //engine.ConversionCompleteEvent += (sender, args) => AudioExtractionProgressChanged?.Invoke(this, new ProgressEventArgs((args.ProcessedDuration.TotalMilliseconds / args.TotalDuration.TotalMilliseconds) * 100f));
                        //informing on 0% and 100%, btw those conversions are pretty fast, 5 to 10 seconds for a 50MB 1048p video.
                        context.OnProgresStateChanged(YoutubeStage.StartingAudioExtraction);
                        await Task.Run(()=>engine.Convert(@in, @out)); //begin conversion progress. it is executed serially.
                        context.OnProgresStateChanged(YoutubeStage.FinishedAudioExtraction);
                    }
                    break;
                case VideoType.WebM:
                    break;
                case VideoType.Unknown:
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
        private async Task ExtractAudio(string path) {
            var cache = new FileInfo(context.AudioPath?.FullName ?? context.AudioSaveableFilename); //target cache
            var SavePath = context.AudioPath?.FullName ?? context.AudioSaveableFilename;//to universal string
            for (int i = 1; File.Exists(SavePath); i++) {
                SavePath = Path.Combine(cache.Directory.FullName, $"{cache.Name.Replace(cache.Extension,"")} ({i}){cache.Extension}");
            }
            SavePath = Path.ChangeExtension(SavePath, "aac");
            context.OnProgresStateChanged(YoutubeStage.StartingAudioExtraction);
            switch (context.VideoInfo.VideoType) {
                case VideoType.Mobile:
                    //no one is really going to use this..
                    break;
                case VideoType.Flash: {
                    using (var flvFile = new FlvFile(path, SavePath)) {
                        flvFile.ConversionProgressChanged += (sender, args) => {
                            context.OnProgresStateChanged(YoutubeStage.ExtractingAudio, args.ProgressPercentage);
                        };

                        await Task.Run(() => flvFile.ExtractStreams());
                    }
                    break;
                }
                case VideoType.Mp4: {
                    var @in = new MediaFile(new FileInfo(path).FullName);
                    var @out = new MediaFile(new FileInfo(SavePath).FullName);
                    using (var engine = new Engine()) {
                        //Desperate attempt to catch the extraction from the MediaToolkit lib but it simply does not pass into those events.
                        //engine.ConvertProgressEvent += (sender, args) => AudioExtractionProgressChanged?.Invoke(this, new ProgressEventArgs((args.ProcessedDuration.TotalMilliseconds / args.TotalDuration.TotalMilliseconds) * 100f));
                        //engine.ConversionCompleteEvent += (sender, args) => AudioExtractionProgressChanged?.Invoke(this, new ProgressEventArgs((args.ProcessedDuration.TotalMilliseconds / args.TotalDuration.TotalMilliseconds) * 100f));
                        //informing on 0% and 100%, btw those conversions are pretty fast, 5 to 10 seconds for a 50MB 1048p video.
                        await Task.Run(()=> engine.CustomCommand($"-i \"{@in.Filename.Replace("\\", "/")}\" -vn -acodec copy \"{@out.Filename.Replace("\\", "/")}\"")); //begin conversion progress. it is executed serially.
                    }
                    break;
                }
                case VideoType.WebM:
                    //the mkv files do not contain any audio files.
                    break;
                case VideoType.Unknown:
                    switch (context.VideoInfo?.AudioType ?? AudioType.None) {
                        case AudioType.Unknown:
                            break;
                        case AudioType.Aac:
                            File.Move(path, SavePath);
                            break;
                        case AudioType.Mp3:
                            SavePath = Path.ChangeExtension(SavePath, "mp3");
                            File.Move(path, SavePath);
                            break;
                        case AudioType.Vorbis: {
                            var @in = new MediaFile(new FileInfo(path).FullName);
                            var @out = new MediaFile(new FileInfo(SavePath).FullName);
                            using (var engine = new Engine()) {
                                await Task.Run(() => engine.Convert(@in, @out));
                            }
                            break;
                        }
                        case AudioType.Opus: {
                            var @in = new MediaFile(new FileInfo(path).FullName);
                            var @out = new MediaFile(new FileInfo(SavePath).FullName);
                            using (var engine = new Engine()) {
                                await Task.Run(()=> engine.CustomCommand($"-i {@in.Filename.Replace("\\","/")} -c:a libvo_aacenc -b:a 192k  {@out.Filename.Replace("\\","/")}"));
                            }
                            break;
                        }
                        default:
                            break;
                    }
                    break;
                default:
                    SavePath = Path.ChangeExtension(SavePath, cache.Extension.Replace(".",""));
                    File.Move(path, SavePath);
                    break;
            }
            context.OnProgresStateChanged(YoutubeStage.FinishedAudioExtraction);
            context.AudioPath = new FileInfo(SavePath);
        }
Ejemplo n.º 9
0
        void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
        {
            if (radioButton1.Checked == true)
            {
                if (!viddling.Contains("flv"))
                {
                    label1.Text = "Status: Ready";
                    File.Copy(viddling, mp4out);
                    File.Delete(viddling);
                }
                else
                {
                    this.Cursor = Cursors.WaitCursor;
                    ProcessStartInfo psi = new ProcessStartInfo();
                    string startdir = Directory.GetCurrentDirectory();
                    if (Environment.Is64BitOperatingSystem)
                    {
                        psi.FileName = ffmpeg + @"\Data\ffmpeg-64.exe";
                    }
                    else
                    {
                        psi.FileName = ffmpeg + @"\Data\ffmpeg-32.exe";
                    }
                    string convert = viddling;
                    psi.Arguments = string.Format("-i \"{0}\" -y -sameq -ar 22050 \"{1}\"", viddling, mp4out);
                    psi.WindowStyle = ProcessWindowStyle.Normal;
                    Process p = Process.Start(psi);
                    p.WaitForExit();
                    if (p.HasExited == true)
                    {
                        this.Cursor = Cursors.Default;
                        File.Delete(viddling);
                    }
                }
            }
            else if (radioButton2.Checked == true)
            {
                if (RipLeech.Properties.Settings.Default.ffmpeg == true)
                {
                    this.Cursor = Cursors.WaitCursor;
                    Process proc = new Process();
                    string convert = viddling;
                    string bitrate = RipLeech.Properties.Settings.Default.audioquality;
                    if (Environment.Is64BitOperatingSystem)
                    {
                        proc.StartInfo.FileName = ffmpeg + @"\Data\ffmpeg-64.exe";
                    }
                    else
                    {
                        proc.StartInfo.FileName = ffmpeg + @"\Data\ffmpeg-32.exe";
                    }
                    proc.StartInfo.Arguments = string.Format("-i \"{0}\" -vn -y -f mp3 -ab 320k \"{1}\"", viddling, vidout);
                    proc.StartInfo.RedirectStandardError = true;
                    proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                    proc.StartInfo.CreateNoWindow = true;
                    proc.StartInfo.UseShellExecute = false;
                    if (!proc.Start())
                    {
                        listBox1.Items.Add("Error starting");
                        return;
                    }
                    StreamReader reader = proc.StandardError;
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        listBox1.Items.Add(line);
                    }
                    proc.Close();
                    try
                    {
                        System.IO.StreamWriter sw = new System.IO.StreamWriter(Directory.GetCurrentDirectory() + @"\ffmpeg.log");
                        foreach (object item in listBox1.Items)
                        {
                            sw.WriteLine(item.ToString());
                        }
                        sw.Close();
                    }
                    catch
                    {

                    }
                    button6.Visible = true;
                    if (File.Exists(viddling))
                    {
                        File.Delete(viddling);
                        if (File.Exists(vidout))
                        {
                            string mymusic = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic) + @"\" + vidname;
                            //MessageBox.Show(mymusic);
                            if (!String.IsNullOrEmpty(RipLeech.Properties.Settings.Default.audiosavepath))
                            {
                                File.Copy(vidout, RipLeech.Properties.Settings.Default.audiosavepath + @"\" + vidname);
                            }
                            else
                            {
                                if (!File.Exists(mymusic))
                                {
                                    File.Copy(vidout, mymusic);
                                }
                            }
                            File.Delete(vidout);
                        }
                    }
                    this.Cursor = Cursors.Default;
                }
                else
                {
                    //non ffmpeg functions
                    var flvFile = new FlvFile(viddling, root + @"\" + vidname);
                    flvFile.ExtractStreams();
                    if (File.Exists(viddling))
                    {
                        File.Delete(viddling);
                        if (File.Exists(vidout))
                        {
                            string mymusic = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic) + @"\" + vidname;
                            //MessageBox.Show(mymusic);
                            if (!File.Exists(mymusic))
                            {
                                File.Copy(vidout, mymusic);
                            }
                            File.Delete(vidout);
                        }
                    }
                }
            }
            else
            {

            }
            if (timer1.Enabled == true)
            {
                timer1.Stop();
                timer1.Enabled = false;
            }
            label1.Text = "Status: Complete";
            progressBar1.Value = 0;
            button4.Visible = true;
            button8.Visible = true;
        }