SubtitlesParser

repository·master·Indexed 41 days ago

https://github.com/alexpoint/subtitlesparser

A universal .NET library for parsing and writing various subtitle file formats. It provides a universal SubParser for automatic format detection and specific parsers for MicroDvd, SubRip (Srt), SubStationAlpha (Ssa), SubViewer, TTML, WebVTT, and YouTube XML. It also includes writers for exporting SubtitleItems to SubRip and SubstationAlpha formats.

Tokens
549
Snippets
4
Records
4
Agent score
50%

What's inside SubtitlesParser

  1. Write subtitle items using a specific writer

    master

    To export a list of SubtitleItems to a file or stream, use a specific writer class. Currently, the library supports writing to:

    • SrtWriter (SubRip)
    • SsaWriter (SubstationAlpha)

    Both synchronous WriteStream and asynchronous WriteStreamAsync methods are available.

    var writer = new SubtitlesParser.Classes.Writers.SrtWriter();
    using (var fileStream = File.OpenWrite(pathToSrtFile)) {
    	writer.WriteStream(fileStream, yourListOfSubtitleItems);
    }
  2. Use a specific parser for known formats

    master

    If you already know the format of the subtitle file, you can instantiate a specific parser class for better performance and reliability. Supported parsing formats include:

    • MicroDvdParser
    • SrtParser (SubRip)
    • SsaParser (SubStationAlpha)
    • SubViewerParser
    • TtmlParser (TTML)
    • VttParser (WebVTT)
    • YtXmlFormatParser (Youtube specific XML)
    var parser = new SubtitlesParser.Classes.Parsers.SrtParser();
    using (var fileStream = File.OpenRead(pathToSrtFile)){
    	var items = parser.ParseStream(fileStream);
    }
  3. Use the Universal parser to detect subtitle formats

    master

    If the subtitle format is unknown, use the SubParser class. It will automatically attempt to use all registered parsers (currently supporting MicroDvd, SubRip, SubStationAlpha, SubViewer, TTML, WebVTT, and Youtube specific XML) until one succeeds.

    var parser = new SubtitlesParser.Classes.Parsers.SubParser();
    using (var fileStream = File.OpenRead(pathToSrtFile)){
    	var items = parser.ParseStream(fileStream);
    }