module TD.Data.Audio
(Audio(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified Data.Text as T
import qualified TD.Data.Minithumbnail as Minithumbnail
import qualified TD.Data.Thumbnail as Thumbnail
import qualified TD.Data.File as File
data Audio
= Audio
{ Audio -> Maybe Int
duration :: Maybe Int
, Audio -> Maybe Text
title :: Maybe T.Text
, Audio -> Maybe Text
performer :: Maybe T.Text
, Audio -> Maybe Text
file_name :: Maybe T.Text
, Audio -> Maybe Text
mime_type :: Maybe T.Text
, Audio -> Maybe Minithumbnail
album_cover_minithumbnail :: Maybe Minithumbnail.Minithumbnail
, Audio -> Maybe Thumbnail
album_cover_thumbnail :: Maybe Thumbnail.Thumbnail
, Audio -> Maybe [Thumbnail]
external_album_covers :: Maybe [Thumbnail.Thumbnail]
, Audio -> Maybe File
audio :: Maybe File.File
}
deriving (Audio -> Audio -> Bool
(Audio -> Audio -> Bool) -> (Audio -> Audio -> Bool) -> Eq Audio
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Audio -> Audio -> Bool
== :: Audio -> Audio -> Bool
$c/= :: Audio -> Audio -> Bool
/= :: Audio -> Audio -> Bool
Eq, Int -> Audio -> ShowS
[Audio] -> ShowS
Audio -> String
(Int -> Audio -> ShowS)
-> (Audio -> String) -> ([Audio] -> ShowS) -> Show Audio
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Audio -> ShowS
showsPrec :: Int -> Audio -> ShowS
$cshow :: Audio -> String
show :: Audio -> String
$cshowList :: [Audio] -> ShowS
showList :: [Audio] -> ShowS
Show)
instance I.ShortShow Audio where
shortShow :: Audio -> String
shortShow Audio
{ duration :: Audio -> Maybe Int
duration = Maybe Int
duration_
, title :: Audio -> Maybe Text
title = Maybe Text
title_
, performer :: Audio -> Maybe Text
performer = Maybe Text
performer_
, file_name :: Audio -> Maybe Text
file_name = Maybe Text
file_name_
, mime_type :: Audio -> Maybe Text
mime_type = Maybe Text
mime_type_
, album_cover_minithumbnail :: Audio -> Maybe Minithumbnail
album_cover_minithumbnail = Maybe Minithumbnail
album_cover_minithumbnail_
, album_cover_thumbnail :: Audio -> Maybe Thumbnail
album_cover_thumbnail = Maybe Thumbnail
album_cover_thumbnail_
, external_album_covers :: Audio -> Maybe [Thumbnail]
external_album_covers = Maybe [Thumbnail]
external_album_covers_
, audio :: Audio -> Maybe File
audio = Maybe File
audio_
}
= String
"Audio"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"duration" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
duration_
, String
"title" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
title_
, String
"performer" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
performer_
, String
"file_name" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
file_name_
, String
"mime_type" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
mime_type_
, String
"album_cover_minithumbnail" String -> Maybe Minithumbnail -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Minithumbnail
album_cover_minithumbnail_
, String
"album_cover_thumbnail" String -> Maybe Thumbnail -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Thumbnail
album_cover_thumbnail_
, String
"external_album_covers" String -> Maybe [Thumbnail] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Thumbnail]
external_album_covers_
, String
"audio" String -> Maybe File -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe File
audio_
]
instance AT.FromJSON Audio where
parseJSON :: Value -> Parser Audio
parseJSON v :: Value
v@(AT.Object Object
obj) = do
String
t <- Object
obj Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"@type" :: AT.Parser String
case String
t of
String
"audio" -> Value -> Parser Audio
parseAudio Value
v
String
_ -> Parser Audio
forall a. Monoid a => a
mempty
where
parseAudio :: A.Value -> AT.Parser Audio
parseAudio :: Value -> Parser Audio
parseAudio = String -> (Object -> Parser Audio) -> Value -> Parser Audio
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"Audio" ((Object -> Parser Audio) -> Value -> Parser Audio)
-> (Object -> Parser Audio) -> Value -> Parser Audio
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
duration_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"duration"
Maybe Text
title_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"title"
Maybe Text
performer_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"performer"
Maybe Text
file_name_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"file_name"
Maybe Text
mime_type_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"mime_type"
Maybe Minithumbnail
album_cover_minithumbnail_ <- Object
o Object -> Key -> Parser (Maybe Minithumbnail)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"album_cover_minithumbnail"
Maybe Thumbnail
album_cover_thumbnail_ <- Object
o Object -> Key -> Parser (Maybe Thumbnail)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"album_cover_thumbnail"
Maybe [Thumbnail]
external_album_covers_ <- Object
o Object -> Key -> Parser (Maybe [Thumbnail])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"external_album_covers"
Maybe File
audio_ <- Object
o Object -> Key -> Parser (Maybe File)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"audio"
Audio -> Parser Audio
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Audio -> Parser Audio) -> Audio -> Parser Audio
forall a b. (a -> b) -> a -> b
$ Audio
{ duration :: Maybe Int
duration = Maybe Int
duration_
, title :: Maybe Text
title = Maybe Text
title_
, performer :: Maybe Text
performer = Maybe Text
performer_
, file_name :: Maybe Text
file_name = Maybe Text
file_name_
, mime_type :: Maybe Text
mime_type = Maybe Text
mime_type_
, album_cover_minithumbnail :: Maybe Minithumbnail
album_cover_minithumbnail = Maybe Minithumbnail
album_cover_minithumbnail_
, album_cover_thumbnail :: Maybe Thumbnail
album_cover_thumbnail = Maybe Thumbnail
album_cover_thumbnail_
, external_album_covers :: Maybe [Thumbnail]
external_album_covers = Maybe [Thumbnail]
external_album_covers_
, audio :: Maybe File
audio = Maybe File
audio_
}
parseJSON Value
_ = Parser Audio
forall a. Monoid a => a
mempty