subtitleParser-0.3: A parser for .srt and .sub files

Portabilityunknown
Maintainerruben.astud@gmail.com
Safe HaskellSafe-Infered

Text.Subtitles.SRT

Contents

Description

A basic parser for .srt files (subtitles) based on Attoparsec and Text

Synopsis

Don't use parseOnly!

This module uses now peekChar in parseDialog, which replaces the ad-hoc method used before. As a consequence it doesn't play well with Data.Attoparsec.Text.parseOnly on some conditions.

You should use just parse or the parseOnly' function I provide to avoid problems until further notice. Hopefully in the next version of attoparsec this will be solved , so keep an eye for removal!.

Terminology of the module

All the sections of a Line have their corresponding ADT in Text.Subtitles.SRT.Datatypes

2
00:00:50,050 --> 00:00:52,217
Drama here

The whole Line is represented in the Line ADT which constructors represented by different ADTs

  • The first line is called index, which is the first constructor of Line.
  • The second one is called Range, which correspond to two separated Time.
  • The last one is the subs. which is just Text and correspond to the third constructor of Line.

Re-exported Datatypes

Main parsers

parseSRT :: Parser SubtitlesSource

Main Parser, gives you a list of all the Lines of the subtitle. It fails if the subtitle doesn't have any Lines.

parseSingleLine :: Parser LineSource

The individual Line parser. Given the upper example return the corresponding Line representation

Temporal solutions

parseOnly' :: Parser a -> Text -> Either String aSource

This version avoid the problems associated with peekChar and thus is safe to use in this module. Subject to removal once parseOnly is fixed.