-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Print current MPD song and status as JSON -- -- Print currently playing MPD's song metadata and status as JSON @package mpd-current-json @version 1.5.0.1 module Network.MPD.Parse -- | Extract a field from the returned MPD.Status data record. -- -- Helper to extract a specific field from the Network.MPD.Status -- data record by providing the corresponding field label. If the input -- status "st" is not Right a, indicating an -- error, or the field label function is not applicable, it returns -- Nothing. -- --

Example:

-- --
--   ghci> import qualified Network.MPD as MPD
--   ghci> st <- MPD.withMPD MPD.status
--   ghci> getStatusField st MPD.stVolume
--   
-- -- Just (Just 100) getStatusField :: Response Status -> (Status -> a) -> Maybe a -- | Go a level deeper than getStatusField. For nested Maybe -- a fields from Status. -- --

Example:

-- --
--   ghci> import qualified Network.MPD as MPD
--   ghci> st <- MPD.withMPD MPD.status
--   ghci> getStatusFieldElement st MPD.stVolume
--   
-- -- Just 100 getStatusFieldElement :: Response Status -> (Status -> Maybe a) -> Maybe a -- | Either check for the returned value of currentSong, -- then call processSong or return Nothing. getTag :: Metadata -> Either a (Maybe Song) -> Maybe String -- | Use sgGetTag to extract a tag from a song, -- safely get only the head item of the returned Maybe list, -- then safely convert it to a string. processSong :: Metadata -> Maybe Song -> Maybe String -- | Get the current Song relative path with sgFilePath maybePathCurrentSong :: Response (Maybe Song) -> Maybe String -- | Get the next song's relative path in the current playlist. -- -- Using sgFilePath from the returned Response -- [Song]. maybePathNextPlaylistSong :: Response [Song] -> Maybe String -- | Safely get the head of a list. Same as Safe.headMay. headMay :: [a] -> Maybe a -- | Convert Value to String within a Maybe -- context. -- -- This Value is from MPD and is basically the same as a -- String but used internally to store metadata values. -- --

Example:

-- --
--   processSong :: Metadata -> Maybe Song -> Maybe String
--   processSong _ Nothing = Nothing
--   processSong tag (Just song) = do
--     let tagVal = MPD.sgGetTag tag song
--     valueToStringMay =<< (headMay =<< tagVal)
--   
-- -- sgGetTag returns a Maybe [Value]. libmpd also -- provides toString that can convert, along other types, a -- Value to a String. valueToStringMay :: Value -> Maybe String -- | Check if Maybe v exists and is of type expected by -- object as defined in Value, if it is return both the -- key and value within the Maybe context tied -- with .=. This gives support to 'optional' fields using -- catMaybes that discard Nothing values and is meant to -- prevent creating JSON key/value pairs with null values, e.g.: -- --
--   jsonTags = object . catMaybes $
--       [ "artist"  .=? artist
--       , "album"   .=? album
--       , "title"   .=? title
--       ]
--   
-- -- Where if a value on the right is Nothing that key/value pair -- will not be included in object because of catMaybes. (.=?) :: (KeyValue e a, ToJSON v) => Key -> Maybe v -> Maybe a -- | Helper function for creating an JSON object where -- catMaybes won't include items from the '[Maybe Pair]' list that -- return Nothing. objectJson :: [Maybe Pair] -> Value -- | Extracts the Int value from an Id within Status, -- if present and the Either value is a Right. getStatusIdInt :: (Status -> Maybe Id) -> Either MPDError Status -> Maybe Int