/* Private methods */ private FileProperties GetUpdatedFileProperties(FileProperties properties) { SubtitleFormat format = BuiltInSubtitleFormats.GetFormat(properties.SubtitleType); TimingMode newTimingMode = (format.Mode == SubtitleMode.Both) ? properties.TimingMode : format.ModeAsTimingMode; return(new FileProperties(properties.Path, properties.Encoding, properties.SubtitleType, newTimingMode, properties.NewlineType)); }
/* Public methods */ /// <summary>Saves subtitles to the file with the specified properties.</summary> /// <param name="subtitles">The subtitles to save.</param> /// <param name="properties">The properties of the file to save the subtitles to. Its <see cref="TimingMode" /> property is used to /// choose the timing mode for subtitle formats that support both time and frame modes.</param> /// <param name="textType">The type of text content to save.</param> /// <remarks>An updated <see cref="SubLib.FileProperties" /> object can be accessed with <see cref="FileProperties" /> after saving.</remarks> public void Save(Subtitles subtitles, FileProperties properties, SubtitleTextType textType) { SubtitleFormat format = BuiltInSubtitleFormats.GetFormat(properties.SubtitleType); SubtitleOutput output = new SubtitleOutput(format, textType); string text = output.Build(subtitles.Collection, subtitles.Properties, properties); FileInputOutput.WriteFile(properties.Path, text, properties.Encoding); fileProperties = GetUpdatedFileProperties(properties); Logger.Info("[SubtitleSaver] Saved {0} \"{1}\" with encoding \"{2}\", format \"{3}\" and frame rate \"{4}\"", textType, properties.Path, properties.Encoding, format.Name, subtitles.Properties.CurrentFrameRate); }
/// <exception cref="UnknownSubtitleFormatException">Thrown if the subtitle format could not be detected.</exception> private SubtitleFormat GetSubtitleFormat(string text) { if (subtitleType == SubtitleType.Unknown) { Logger.Info("[SubtitleInput] Trying to autodetect the subtitle format."); } else { Logger.Info("[SubtitleInput] Trying subtitle format \"{0}\"", subtitleType); } SubtitleFormat subtitleFormat = null; if (subtitleType == SubtitleType.Unknown) { subtitleFormat = BuiltInSubtitleFormats.Detect(text); } else { subtitleFormat = BuiltInSubtitleFormats.GetFormat(subtitleType); } return(subtitleFormat); }
/* Public methods */ /// <summary>Get information about an available subtitle type.</summary> /// <param name="type">The subtitle type.</param> /// <returns>The information about the specified subtitle type.</returns> public static SubtitleTypeInfo GetAvailableType(SubtitleType type) { SubtitleFormat format = BuiltInSubtitleFormats.GetFormat(type); return(new SubtitleTypeInfo(format)); }