public static bool BatchConvert(Options options) { if (options.Job != JobType.Batch) { return(false); } SearchOption searchOption = options.Recurse ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; string[] files = ContainerTypes.ExtensionList .SelectMany(x => Directory.GetFiles(options.InDir, $"*.{x}", searchOption)) .ToArray(); using (var progress = new ProgressBar()) { progress.SetTotal(files.Length); Parallel.ForEach(files, new ParallelOptions { MaxDegreeOfParallelism = Math.Max(Environment.ProcessorCount - 1, 1) }, inPath => { string relativePath = inPath.Substring(options.InDir.Length).TrimStart('\\'); string outPath = Path.ChangeExtension(Path.Combine(options.OutDir, relativePath), options.OutTypeName); var jobFiles = new JobFiles(); jobFiles.InFiles.Add(new AudioFile(inPath)); jobFiles.OutFiles.Add(new AudioFile(outPath)); try { progress.LogMessage(Path.GetFileName(inPath)); Convert.ConvertFile(options, jobFiles, false); } catch (Exception ex) { progress.LogMessage($"Error converting {Path.GetFileName(inPath)}"); progress.LogMessage(ex.ToString()); } progress.ReportAdd(1); }); } return(true); }
private void EncodeFiles(JobFiles files, Options options) { foreach (AudioFile file in files.InFiles.Where(x => x.Channels != null)) { IAudioFormat format = file.Audio.GetAllFormats().First(); file.Audio = new AudioData(format.GetChannels(file.Channels.ToArray())); } AudioData[] toMerge = files.InFiles.Select(x => x.Audio).ToArray(); Audio = AudioData.Combine(toMerge); if (options.NoLoop) { Audio.SetLoop(false); } if (options.Loop) { Audio.SetLoop(options.Loop, options.LoopStart, options.LoopEnd); } }
public static bool ConvertFile(Options options, JobFiles files, bool showProgress = true) { if (options.Job != JobType.Convert && options.Job != JobType.Batch) { return(false); } var converter = new Convert { ShowProgress = showProgress }; foreach (AudioFile file in files.InFiles) { converter.ReadFile(file); } converter.EncodeFiles(files, options); converter.SetConfiguration(files.OutFiles[0].Type, options); converter.WriteFile(files.OutFiles[0].Path); return(true); }