public static async Task <Guid> ComputeSubtitle(string text) { FileContainer fileContainer = FileContainer.NewSubtitleContainer(); if (!IsValidVTT(text)) { fileContainer.SubtitleFileItem.IpfsProcess.SetErrorMessage("Not a valid WEBVTT file", "Not a valid WEBVTT file"); return(fileContainer.ProgressToken); } try { await File.WriteAllTextAsync(fileContainer.SubtitleFileItem.TempFilePath, text); fileContainer.SubtitleFileItem.ReplaceOutputPathWithTempPath(); IpfsDaemon.Instance.Queue(fileContainer.SubtitleFileItem); } catch (Exception ex) { LogManager.AddSubtitleMessage(LogLevel.Critical, "Exception non gérée", "Exception", ex); fileContainer.CancelAll("Exception non gérée"); fileContainer.CleanFilesIfEnd(); return(fileContainer.ProgressToken); } return(fileContainer.ProgressToken); }
public static Guid ComputeImage(string sourceFilePath) { FileContainer fileContainer = FileContainer.NewImageContainer(sourceFilePath); FileItem sourceFile = fileContainer.SourceFileItem; /////////////////////////////////////////////////////////////////////////////////////////////// /// resize + crop source image /////////////////////////////////////////////////////////////////////////////////////////////// try { LogManager.AddImageMessage(LogLevel.Information, "SourceFileName " + Path.GetFileName(sourceFile.SourceFilePath), "Start Resize and Crop source"); string arguments = $"{Path.GetFileName(sourceFile.SourceFilePath)} -resize \"{_finalWidthOverlay}x{_finalHeightOverlay}^\" -gravity Center -crop {_finalWidthOverlay}x{_finalHeightOverlay}+0+0 {Path.GetFileName(sourceFile.TempFilePath)}"; var process = new ProcessManager(Path.Combine(GeneralSettings.Instance.ImageMagickPath, "convert"), arguments, LogManager.ImageLogger); bool success = process.Launch(5); if (!success) { LogManager.AddImageMessage(LogLevel.Error, "Erreur convert", "Erreur"); fileContainer.CancelAll("Erreur resize and crop source"); fileContainer.CleanFilesIfEnd(); return(fileContainer.ProgressToken); } sourceFile.ReplaceOutputPathWithTempPath(); LogManager.AddImageMessage(LogLevel.Information, "OutputFileName " + Path.GetFileName(sourceFile.OutputFilePath), "End Resize and Crop source"); } catch (Exception ex) { LogManager.AddImageMessage(LogLevel.Critical, "Exception non gérée resize crop source", "Exception", ex); fileContainer.CancelAll("Exception non gérée"); fileContainer.CleanFilesIfEnd(); return(fileContainer.ProgressToken); } // remplacement de l'image source par l'image de sortie sourceFile.SetSourceFilePath(sourceFile.OutputFilePath); /////////////////////////////////////////////////////////////////////////////////////////////// /// Resize snap image /////////////////////////////////////////////////////////////////////////////////////////////// // changement de la source de SnapFileItem fileContainer.SnapFileItem.SetSourceFilePath(sourceFile.SourceFilePath); try { LogManager.AddImageMessage(LogLevel.Information, "SourceFileName " + Path.GetFileName(fileContainer.SnapFileItem.SourceFilePath), "Start Resize Snap"); string arguments = $"{Path.GetFileName(fileContainer.SnapFileItem.SourceFilePath)} -resize \"{_finalWidthSnap}x{_finalHeightSnap}^\" {Path.GetFileName(fileContainer.SnapFileItem.TempFilePath)}"; var process = new ProcessManager(Path.Combine(GeneralSettings.Instance.ImageMagickPath, "convert"), arguments, LogManager.ImageLogger); bool success = process.Launch(5); if (!success) { LogManager.AddImageMessage(LogLevel.Error, "Erreur snap", "Erreur"); fileContainer.CancelAll("Erreur snap"); fileContainer.CleanFilesIfEnd(); return(fileContainer.ProgressToken); } fileContainer.SnapFileItem.ReplaceOutputPathWithTempPath(); LogManager.AddImageMessage(LogLevel.Information, "OutputFileName " + Path.GetFileName(fileContainer.SnapFileItem.OutputFilePath), "End Resize Snap"); IpfsDaemon.Instance.Queue(fileContainer.SnapFileItem); } catch (Exception ex) { LogManager.AddImageMessage(LogLevel.Critical, "Exception non gérée snap", "Exception", ex); fileContainer.CancelAll("Exception non gérée"); fileContainer.CleanFilesIfEnd(); return(fileContainer.ProgressToken); } /////////////////////////////////////////////////////////////////////////////////////////////// /// Overlay image /////////////////////////////////////////////////////////////////////////////////////////////// // changement de la source de OverlayFileItem fileContainer.OverlayFileItem.SetSourceFilePath(sourceFile.SourceFilePath); try { LogManager.AddImageMessage(LogLevel.Information, "SourceFileName " + Path.GetFileName(fileContainer.OverlayFileItem.SourceFilePath), "Start Overlay"); string arguments = $"-gravity NorthEast {_overlayImagePath} {Path.GetFileName(fileContainer.OverlayFileItem.SourceFilePath)} {Path.GetFileName(fileContainer.OverlayFileItem.TempFilePath)}"; var process = new ProcessManager(Path.Combine(GeneralSettings.Instance.ImageMagickPath, "composite"), arguments, LogManager.ImageLogger); bool success = process.Launch(5); if (!success) { LogManager.AddImageMessage(LogLevel.Error, "Erreur overlay", "Erreur"); fileContainer.CancelAll("Erreur overlay"); fileContainer.CleanFilesIfEnd(); return(fileContainer.ProgressToken); } fileContainer.OverlayFileItem.ReplaceOutputPathWithTempPath(); LogManager.AddImageMessage(LogLevel.Information, "OutputFileName " + Path.GetFileName(fileContainer.OverlayFileItem.OutputFilePath), "End Overlay"); IpfsDaemon.Instance.Queue(fileContainer.OverlayFileItem); } catch (Exception ex) { LogManager.AddImageMessage(LogLevel.Critical, "Exception non gérée overlay", "Exception", ex); fileContainer.CancelAll("Exception non gérée"); fileContainer.CleanFilesIfEnd(); return(fileContainer.ProgressToken); } return(fileContainer.ProgressToken); }