Beispiel #1
0
        protected void TranscodeFile(StorageFile videoFile, StorageFile audioFile)
        {
            var arguments = String.Format("-i \"{0}\" -acodec mp3 -y -ac 2 -ab 160 \"{1}\"", videoFile, audioFile);
            var process = new Process {
                EnableRaisingEvents = true,
                StartInfo = {
                    FileName = _applicationPath + "\\Executables\\ffmpeg.exe",
                    Arguments = arguments,
                    CreateNoWindow = true,
                    RedirectStandardError = true,
                    RedirectStandardOutput = true,
                    UseShellExecute = false,
                }
            };
            if (_onEntryDownloadStatusChange != null) _onEntryDownloadStatusChange(_youtubeEntry, DownloadState.ConvertAudioStart, 50);

            process.Start();
            using (var d = process.StandardError) {
                var duration = new TimeSpan();
                TimeSpan current;
                do {
                    var s = d.ReadLine() ?? "";
                    Debug.WriteLine(s);
                    if (s.Contains("Duration: ")) {
                        duration = ParseDuration("Duration: ", ',', s);
                    }
                    else {
                        if (s.Contains(" time=")) {
                            current = ParseDuration(" time=", ' ', s);
                            var percentage = (current.TotalMilliseconds / duration.TotalMilliseconds) * 50;
                            if (_onEntryDownloadStatusChange != null) _onEntryDownloadStatusChange(_youtubeEntry, DownloadState.DownloadProgressChanged, 50 + percentage );
                            //string currents = functions.ExtractTime(s);
                            //current = functions.CurrentStringToSeconds(currents);
                            //synchCurrent(current.ToString());
                            //synchTextOutput(s);
                        }
                    }
                } while (!d.EndOfStream);
            }
            process.WaitForExit();
            DownloadState state;
            if (process.ExitCode == 0) {
                try {
                    Tag(audioFile.ToString());
                    state = DownloadState.Ready;
                } catch {
                    state = DownloadState.Error;
                }
            } else state = DownloadState.Error;
            if (_onEntryDownloadStatusChange != null) _onEntryDownloadStatusChange(_youtubeEntry, state, 100.0);
            process.Close();
        }
Beispiel #2
0
 public static bool FileExists(StorageFolder folder, string videoFile)
 {
     var file = new StorageFile {StorageFolder = folder, FileName = videoFile};
     return File.Exists(file.ToString());
 }
Beispiel #3
0
 protected void _TranscodeFile(StorageFile videoFile, StorageFile audioFile)
 {
     var arguments = String.Format("-i \"{0}\" -acodec mp3 -y -ac 2 -ab 160 \"{1}\"", videoFile, audioFile);
     var process = new Process {
         EnableRaisingEvents = true,
         StartInfo = {
             FileName = _applicationPath + "\\Executables\\ffmpeg.exe",
             Arguments = arguments,
             CreateNoWindow = true,
             RedirectStandardError = true,
             RedirectStandardOutput = true,
             UseShellExecute = false,
         }
     };
     process.OutputDataReceived += (sender, args) => {
         var s = sender.ToString();
         var a = args.ToString();
         var state = (s + a == "Mert") ? DownloadState.Deleted : DownloadState.ConvertAudioStart;
         if (_onEntryDownloadStatusChange != null) _onEntryDownloadStatusChange(_youtubeEntry, state, 100.0);
     };
     process.ErrorDataReceived += (sender, args) => {
         var s = sender.ToString();
         var a = args.ToString();
         var state = (s + a == "Mert") ? DownloadState.Deleted : DownloadState.ConvertAudioStart;
         if (_onEntryDownloadStatusChange != null) _onEntryDownloadStatusChange(_youtubeEntry, state, 100.0);
     };
     process.Exited += (sender, args) => {
         DownloadState state;
         if (process.ExitCode == 0) {
             try {
                 Tag(audioFile.ToString());
                 state = DownloadState.Ready;
             }
             catch {
                 state = DownloadState.Error;
             }
         }
         else state = DownloadState.Error;
         if (_onEntryDownloadStatusChange != null) _onEntryDownloadStatusChange(_youtubeEntry, state, 100.0);
     };
     process.Start();
 }