SpongeEngine.SubtitleSharp
3.1.2
Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package SpongeEngine.SubtitleSharp --version 3.1.2
NuGet\Install-Package SpongeEngine.SubtitleSharp -Version 3.1.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SpongeEngine.SubtitleSharp" Version="3.1.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SpongeEngine.SubtitleSharp --version 3.1.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SpongeEngine.SubtitleSharp, 3.1.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SpongeEngine.SubtitleSharp as a Cake Addin #addin nuget:?package=SpongeEngine.SubtitleSharp&version=3.1.2 // Install SpongeEngine.SubtitleSharp as a Cake Tool #tool nuget:?package=SpongeEngine.SubtitleSharp&version=3.1.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
SubtitleSharp
SubtitleSharp is a C# library for parsing and writing subtitles in the SubRip (SRT) format.
Features
- Only SRT Support: Parse and write subtitles in SRT.
- Customizable Options: Configure parsing behavior using
SubtitleParserOptions
and control timecode requirements withSubtitleTimecodeMode
. - Asynchronous Processing: Fully supports async/await for non-blocking I/O operations.
- Cross-Platform Compatibility: Works with .NET 7.0, .NET 8.0, and .NET 9.0+.
Installation
Install via NuGet:
dotnet add package SpongeEngine.SubtitleSharp
Examples
Parsing SRT Files
using System.Text;
using SpongeEngine.SubtitleSharp;
// Open the SRT file as a stream.
using FileStream fileStream = new FileStream("path_to_subtitle.srt", FileMode.Open, FileAccess.Read);
// Initialize the parser.
SubtitleParser parser = new SubtitleParser();
// Parse the stream into a list of SubtitleCue objects.
List<SubtitleCue> subtitleCues = parser.ParseStream(fileStream, new SubtitleParserOptions { Encoding = Encoding.UTF8 });
// Output subtitle start and end times.
foreach (SubtitleCue subtitleCue in subtitleCues)
{
Console.WriteLine($"Start: {subtitleCue.StartTime} ms, End: {subtitleCue.EndTime} ms");
foreach (string line in subtitleCue.Lines)
{
Console.WriteLine(line);
}
Parsing from Text
using System.Text;
using SpongeEngine.SubtitleSharp;
string subtitleContent = File.ReadAllText("path_to_subtitle.srt", Encoding.UTF8);
List<SubtitleCue> subtitleCues = new SubtitleParser().ParseText(subtitleContent, new SubtitleParserOptions { Encoding = Encoding.UTF8 });
Optional Timecode Mode
using System.Text;
using SpongeEngine.SubtitleSharp;
using FileStream fileStream = new FileStream("path_to_subtitle_no_timecodes.srt", FileMode.Open, FileAccess.Read);
List<SubtitleCue> subtitleCues = new SubtitleParser().ParseStream(
fileStream,
new SubtitleParserOptions { Encoding = Encoding.UTF8, TimecodeMode = SubtitleTimecodeMode.Optional }
);
// Each cue will have dummy start and end times assigned.
Writing SRT Files
using SpongeEngine.SubtitleSharp;
using System.IO;
// Assume subtitleCues is a List<SubtitleCue> obtained from parsing.
using FileStream outputStream = new FileStream("output.srt", FileMode.Create, FileAccess.Write);
SubtitleWriter writer = new SubtitleWriter();
writer.WriteStream(outputStream, subtitleCues);
Writing SRT Files
using SpongeEngine.SubtitleSharp;
using SpongeEngine.SubtitleSharp.Writers;
// Assume subtitleCues is a List<SubtitleCue> obtained from parsing.
using FileStream outputStream = new FileStream("output.srt", FileMode.Create, FileAccess.Write);
SrtWriter srtWriter = new SrtWriter();
srtWriter.WriteStream(outputStream, subtitleCues);
Asynchronous Writing
using SpongeEngine.SubtitleSharp;
using System.IO;
using System.Threading.Tasks;
// Assume subtitleCues is a List<SubtitleCue> obtained from parsing.
using FileStream outputStream = new FileStream("output.srt", FileMode.Create, FileAccess.Write);
SubtitleWriter writer = new SubtitleWriter();
await writer.WriteStreamAsync(outputStream, subtitleCues);
Testing
To run the unit tests, execute:
dotnet test
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Support
For issues and feature requests, please use the GitHub issues page.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net7.0
- Polly (>= 8.5.2)
- System.Linq.Async (>= 6.0.1)
-
net8.0
- Polly (>= 8.5.2)
- System.Linq.Async (>= 6.0.1)
-
net9.0
- Polly (>= 8.5.2)
- System.Linq.Async (>= 6.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.