SpongeEngine.SubtitleSharp 2.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package SpongeEngine.SubtitleSharp --version 2.0.1                
NuGet\Install-Package SpongeEngine.SubtitleSharp -Version 2.0.1                
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="2.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SpongeEngine.SubtitleSharp --version 2.0.1                
#r "nuget: SpongeEngine.SubtitleSharp, 2.0.1"                
#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=2.0.1

// Install SpongeEngine.SubtitleSharp as a Cake Tool
#tool nuget:?package=SpongeEngine.SubtitleSharp&version=2.0.1                

SubtitleSharp

NuGet NuGet Downloads Run Tests License .NET

C# library for parsing and handling subtitle files (e.g., SRT, VTT, ASS).

Features

  • Supports parsing subtitle formats including SubRip (SRT), WebVTT (VTT), and SubStation Alpha (ASS).
  • Converts subtitle files to structured data (SubtitleItem) for easy processing.
  • Handles timecode validation and parsing.
  • Cross-platform compatibility with .NET 6.0+.
  • Async/await support for non-blocking subtitle processing.

📦 View Package on NuGet

Installation

Install via NuGet:

dotnet add package SpongeEngine.SubtitleSharp

Quick Start

Basic Usage

using SpongeEngine.SubtitleSharp;

// Parse an SRT file into structured subtitle items
var srtFilePath = "path_to_subtitle.srt";
using var fileStream = new FileStream(srtFilePath, FileMode.Open, FileAccess.Read);
var parser = new SrtParser();
var subtitleItems = parser.ParseStream(fileStream, Encoding.UTF8);

// Output subtitle start and end times
foreach (var item in subtitleItems)
{
    Console.WriteLine($"Start: {item.StartTime}, End: {item.EndTime}");
}

Configuration

Parsing Options

// Manually specify format for parsing
SubtitlesFormat format = SubtitlesFormat.SubRipFormat;
using var fileStream = new FileStream("path_to_subtitle.srt", FileMode.Open, FileAccess.Read);
var parser = new SubtitleParser();
var subtitleItems = parser.ParseStream(fileStream, Encoding.UTF8, format);

Error Handling

try
{
    var subtitleItems = parser.ParseStream(fileStream, Encoding.UTF8, format);
}
catch (ArgumentException ex)
{
    Console.WriteLine($"Error parsing subtitle: {ex.Message}");
}

Logging

ILogger logger = LoggerFactory
    .Create(builder => builder
        .AddConsole()
        .SetMinimumLevel(LogLevel.Debug))
    .CreateLogger<SubtitleParser>();

// Example usage of logger in subtitle parsing
var parser = new SubtitleParser(logger);

Testing

To run the tests:

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 Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  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 was computed.  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.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.2.3 0 2/26/2025
2.2.2 0 2/26/2025
2.2.1 50 2/24/2025
2.2.0 41 2/24/2025
2.1.1 44 2/24/2025
2.1.0 43 2/24/2025
2.0.3 55 2/24/2025
2.0.2 48 2/24/2025
2.0.1 43 2/24/2025
1.1.1 51 2/20/2025
1.1.0 42 2/19/2025
1.0.1 37 2/18/2025
1.0.0 52 2/17/2025