module FFProbe.Data.Chapter (Chapter (..), duration, title) where
import Data.Aeson
import FFProbe.Data.Tags
import FFProbe.Data.Tags.Internal
import FFProbe.Internal (parseReadable)
import Prelude hiding (id)
data Chapter = Chapter
{ Chapter -> Integer
id :: Integer,
Chapter -> String
timeBase :: String,
Chapter -> Float
startTime :: Float,
Chapter -> Float
endTime :: Float,
Chapter -> TagList
tags :: TagList,
Chapter -> Object
raw :: Object
}
instance HasTags Chapter where
getTags :: Chapter -> TagList
getTags = Chapter -> TagList
tags
duration :: Chapter -> Float
duration :: Chapter -> Float
duration Chapter
chapter = Chapter -> Float
endTime Chapter
chapter Float -> Float -> Float
forall a. Num a => a -> a -> a
- Chapter -> Float
startTime Chapter
chapter
title :: Chapter -> Maybe String
title :: Chapter -> Maybe String
title Chapter
chapter = do
TagValue
value <- String -> Chapter -> Maybe TagValue
forall a. HasTags a => String -> a -> Maybe TagValue
lookupTag String
"title" Chapter
chapter
case TagValue
value of
StringTag String
t -> String -> Maybe String
forall a. a -> Maybe a
forall (m :: * -> *) a. Monad m => a -> m a
return String
t
TagValue
_ -> Maybe String
forall a. Maybe a
Nothing
instance FromJSON Chapter where
parseJSON :: Value -> Parser Chapter
parseJSON = String -> (Object -> Parser Chapter) -> Value -> Parser Chapter
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"Chapter Entry" ((Object -> Parser Chapter) -> Value -> Parser Chapter)
-> (Object -> Parser Chapter) -> Value -> Parser Chapter
forall a b. (a -> b) -> a -> b
$ \Object
v -> do
let raw :: Object
raw = Object
v
Integer
id <- Object
v Object -> Key -> Parser Integer
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"id"
String
timeBase <- Object
v Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"time_base"
Float
startTime <- String -> Parser Float
forall a. Read a => String -> Parser a
parseReadable (String -> Parser Float) -> Parser String -> Parser Float
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Object
v Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"start_time"
Float
endTime <- String -> Parser Float
forall a. Read a => String -> Parser a
parseReadable (String -> Parser Float) -> Parser String -> Parser Float
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Object
v Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"end_time"
TagList
tags <- Value -> Parser TagList
parseTags (Value -> Parser TagList) -> Parser Value -> Parser TagList
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Object
v Object -> Key -> Parser Value
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"tags"
Chapter -> Parser Chapter
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return Chapter {Float
Integer
String
TagList
Object
id :: Integer
timeBase :: String
startTime :: Float
endTime :: Float
tags :: TagList
raw :: Object
raw :: Object
id :: Integer
timeBase :: String
startTime :: Float
endTime :: Float
tags :: TagList
..}