module Text.Subtitles.Datatypes
(
module Data.Attoparsec.Text,
module Data.Text,
Subtitles,
Line(..),
Range(..),
Time(..)
) where
import Data.List (intercalate)
import Data.Text (Text, unpack)
import Data.Attoparsec.Text (Parser)
data Time = Time
{ hour :: Int
, minutes :: Int
, seconds :: Int
, frame :: Int
} deriving (Eq, Ord)
data Range = Range
{ from :: Time
, to :: Time
} deriving (Eq, Ord)
data Line = Line
{ index :: Int
, range :: Range
, subs :: Text
} deriving (Eq, Ord)
type Subtitles = [Line]
instance Show Time where
show (Time h m s f) = concat [showT h, ":", showT m, ":", showT s, ",", showF f]
instance Show Range where
show (Range f t) = concat [show f, " --> ", show t]
instance Show Line where
show (Line i t s) = intercalate "\n" (show i : show t : [unpack s]) ++ "\n"
showT :: Int -> String
showT a | a < 10 = '0' : show a
| otherwise = show a
showF :: Int -> String
showF a | a < 10 = '0':'0': show a
| a < 100 = '0': show a
| otherwise = show a