libmpd-0.3.0: An MPD client library.Source codeContentsIndex
Network.MPD
PortabilityHaskell 98
Stabilityalpha
Maintainerbsinclai@turing.une.edu.au
Contents
Basic data types
Connections
Command related data types
Admin commands
Database commands
Playlist commands
Playback commands
Miscellaneous commands
Extensions/shortcuts
Description

An MPD client library. MPD is a daemon for playing music that is controlled over a network socket. Its site is at http://www.musicpd.org/.

To avoid name clashes with the standard Prelude functions, do:

 import qualified Network.MPD as MPD
Synopsis
data MPD a
data MPDError
= NoMPD
| TimedOut
| Unexpected String
| Custom String
| ACK ACKType String
data ACKType
= InvalidArgument
| InvalidPassword
| Auth
| UnknownCommand
| FileNotFound
| PlaylistMax
| System
| PlaylistLoad
| Busy
| NotPlaying
| FileExists
| UnknownACK
type Response a = Either MPDError a
withMPD :: MPD a -> IO (Response a)
withMPDEx :: String -> Integer -> IO (Maybe String) -> MPD a -> IO (Response a)
type Artist = String
type Album = String
type Title = String
type PlaylistName = String
type Path = String
data Meta
= Artist
| Album
| Title
| Track
| Name
| Genre
| Date
| Composer
| Performer
| Disc
| Any
| Filename
data Match = Match Meta String
type Query = [Match]
type Seconds = Integer
data PLIndex
= Pos Integer
| ID Integer
data State
= Playing
| Stopped
| Paused
data Count = Count {
cSongs :: Integer
cPlaytime :: Seconds
}
data Device = Device {
dOutputID :: Int
dOutputName :: String
dOutputEnabled :: Bool
}
data Stats = Stats {
stsArtists :: Integer
stsAlbums :: Integer
stsSongs :: Integer
stsUptime :: Seconds
stsPlaytime :: Seconds
stsDbPlaytime :: Seconds
stsDbUpdate :: Integer
}
data Song = Song {
sgArtist :: String
sgAlbum :: String
sgTitle :: String
sgFilePath :: String
sgGenre :: String
sgName :: String
sgComposer :: String
sgPerformer :: String
sgLength :: Seconds
sgDate :: Int
sgTrack :: (Int, Int)
sgDisc :: (Int, Int)
sgIndex :: Maybe PLIndex
}
data Status = Status {
stState :: State
stVolume :: Int
stRepeat :: Bool
stRandom :: Bool
stPlaylistVersion :: Integer
stPlaylistLength :: Integer
stSongPos :: Maybe PLIndex
stSongID :: Maybe PLIndex
stTime :: (Seconds, Seconds)
stBitrate :: Int
stXFadeWidth :: Seconds
stAudio :: (Int, Int, Int)
stUpdatingDb :: Integer
stError :: String
}
disableOutput :: Int -> MPD ()
enableOutput :: Int -> MPD ()
kill :: MPD ()
outputs :: MPD [Device]
update :: [Path] -> MPD ()
find :: Query -> MPD [Song]
list :: Meta -> Query -> MPD [String]
listAll :: Path -> MPD [Path]
listAllInfo :: Path -> MPD [Either Path Song]
lsInfo :: Path -> MPD [Either Path Song]
search :: Query -> MPD [Song]
count :: Query -> MPD Count
add :: PlaylistName -> Path -> MPD [Path]
add_ :: PlaylistName -> Path -> MPD ()
addId :: Path -> MPD Integer
clear :: PlaylistName -> MPD ()
currentSong :: MPD (Maybe Song)
delete :: PlaylistName -> PLIndex -> MPD ()
load :: PlaylistName -> MPD ()
move :: PlaylistName -> PLIndex -> Integer -> MPD ()
playlistInfo :: Maybe PLIndex -> MPD [Song]
listPlaylist :: PlaylistName -> MPD [Path]
listPlaylistInfo :: PlaylistName -> MPD [Song]
playlist :: MPD [(PLIndex, Path)]
plChanges :: Integer -> MPD [Song]
plChangesPosId :: Integer -> MPD [(PLIndex, PLIndex)]
playlistFind :: Query -> MPD [Song]
playlistSearch :: Query -> MPD [Song]
rm :: PlaylistName -> MPD ()
rename :: PlaylistName -> PlaylistName -> MPD ()
save :: PlaylistName -> MPD ()
shuffle :: MPD ()
swap :: PLIndex -> PLIndex -> MPD ()
crossfade :: Seconds -> MPD ()
next :: MPD ()
pause :: Bool -> MPD ()
play :: Maybe PLIndex -> MPD ()
previous :: MPD ()
random :: Bool -> MPD ()
repeat :: Bool -> MPD ()
seek :: Maybe PLIndex -> Seconds -> MPD ()
setVolume :: Int -> MPD ()
volume :: Int -> MPD ()
stop :: MPD ()
clearError :: MPD ()
close :: MPD ()
commands :: MPD [String]
notCommands :: MPD [String]
password :: String -> MPD ()
ping :: MPD ()
reconnect :: MPD ()
stats :: MPD Stats
status :: MPD Status
tagTypes :: MPD [String]
urlHandlers :: MPD [String]
addMany :: PlaylistName -> [Path] -> MPD ()
deleteMany :: PlaylistName -> [PLIndex] -> MPD ()
complete :: String -> MPD [Either Path Song]
crop :: Maybe PLIndex -> Maybe PLIndex -> MPD ()
prune :: MPD ()
lsDirs :: Path -> MPD [Path]
lsFiles :: Path -> MPD [Path]
lsPlaylists :: MPD [PlaylistName]
findArtist :: Artist -> MPD [Song]
findAlbum :: Album -> MPD [Song]
findTitle :: Title -> MPD [Song]
listArtists :: MPD [Artist]
listAlbums :: Maybe Artist -> MPD [Album]
listAlbum :: Artist -> Album -> MPD [Song]
searchArtist :: Artist -> MPD [Song]
searchAlbum :: Album -> MPD [Song]
searchTitle :: Title -> MPD [Song]
getPlaylist :: MPD [Song]
toggle :: MPD ()
updateId :: [Path] -> MPD Integer
Basic data types
data MPD a Source

The MPD monad is basically a reader and error monad combined.

To use the error throwing/catching capabilities:

 import Control.Monad.Error

To run IO actions within the MPD monad:

 import Control.Monad.Trans
show/hide Instances
data MPDError Source
The MPDError type is used to signal errors, both from the MPD and otherwise.
Constructors
NoMPDMPD not responding
TimedOutThe connection timed out
Unexpected StringMPD returned an unexpected response. This is a bug, either in the library or in MPD itself.
Custom StringUsed for misc. errors
ACK ACKType StringACK type and a message from the server
show/hide Instances
data ACKType Source
Represents various MPD errors (aka. ACKs).
Constructors
InvalidArgumentInvalid argument passed (ACK 2)
InvalidPasswordInvalid password supplied (ACK 3)
AuthAuthentication required (ACK 4)
UnknownCommandUnknown command (ACK 5)
FileNotFoundFile or directory not found ACK 50)
PlaylistMaxPlaylist at maximum size (ACK 51)
SystemA system error (ACK 52)
PlaylistLoadPlaylist loading failed (ACK 53)
BusyUpdate already running (ACK 54)
NotPlayingAn operation requiring playback got interrupted (ACK 55)
FileExistsFile already exists (ACK 56)
UnknownACKAn unknown ACK (aka. bug)
show/hide Instances
type Response a = Either MPDError aSource
A response is either an MPDError or some result.
Connections
withMPD :: MPD a -> IO (Response a)Source

A wrapper for withMPDEx that uses localhost:6600 as the default host:port, or whatever is found in the environment variables MPD_HOST and MPD_PORT. If MPD_HOST is of the form "password@host" the password will be supplied as well.

Examples:

 withMPD $ play Nothing
 withMPD $ add_ "" "tool" >> play Nothing >> currentSong
withMPDExSource
::
=> StringHost name.
-> IntegerPort number.
-> IO (Maybe String)An action that supplies passwords.
-> MPD aThe action to run.
-> IO (Response a)
Run an MPD action against a server.
Command related data types
type Artist = StringSource
type Album = StringSource
type Title = StringSource
type PlaylistName = StringSource
Used for commands which require a playlist name. If empty, the current playlist is used.
type Path = StringSource
Used for commands which require a path within the database. If empty, the root path is used.
data Meta Source
Available metadata types/scope modifiers, used for searching the database for entries with certain metadata values.
Constructors
Artist
Album
Title
Track
Name
Genre
Date
Composer
Performer
Disc
Any
Filename
show/hide Instances
Show Meta
MPDArg Meta
data Match Source

When searching for specific items in a collection of songs, we need a reliable way to build predicates. Match is one way of achieving this. Each Match is a clause, and by putting matches together in lists, we can compose queries.

For example, to match any song where the value of artist is "Foo", we use:

 Match Artist "Foo"

In composite matches (queries), all clauses must be satisfied, which means that each additional clause narrows the search. For example, to match any song where the value of artist is "Foo" AND the value of album is "Bar", we use:

 [Match Artist "Foo", Match Album "Bar"]

By adding additional clauses we can narrow the search even more, but this is usually not necessary.

Constructors
Match Meta String
show/hide Instances
type Query = [Match]Source
A query comprises a list of Match predicates
type Seconds = IntegerSource
data PLIndex Source
Represents a song's playlist index.
Constructors
Pos IntegerA playlist position index (starting from 0)
ID IntegerA playlist ID number that more robustly identifies a song.
show/hide Instances
data State Source
Represents the different playback states.
Constructors
Playing
Stopped
Paused
show/hide Instances
data Count Source
Represents the result of running count.
Constructors
Count
cSongs :: IntegerNumber of songs matching the query
cPlaytime :: SecondsTotal play time of matching songs
show/hide Instances
data Device Source
Represents an output device.
Constructors
Device
dOutputID :: IntOutput's ID number
dOutputName :: StringOutput's name as defined in the MPD configuration file
dOutputEnabled :: Bool
show/hide Instances
data Stats Source
Container for database statistics.
Constructors
Stats
stsArtists :: IntegerNumber of artists.
stsAlbums :: IntegerNumber of albums.
stsSongs :: IntegerNumber of songs.
stsUptime :: SecondsDaemon uptime in seconds.
stsPlaytime :: SecondsTotal playing time.
stsDbPlaytime :: SecondsTotal play time of all the songs in the database.
stsDbUpdate :: IntegerLast database update in UNIX time.
show/hide Instances
data Song Source
Represents a single song item.
Constructors
Song
sgArtist :: String
sgAlbum :: String
sgTitle :: String
sgFilePath :: String
sgGenre :: String
sgName :: String
sgComposer :: String
sgPerformer :: String
sgLength :: SecondsLength in seconds
sgDate :: IntYear
sgTrack :: (Int, Int)Track number/total tracks
sgDisc :: (Int, Int)Position in set/total in set
sgIndex :: Maybe PLIndex
show/hide Instances
data Status Source
Container for MPD status.
Constructors
Status
stState :: State
stVolume :: IntA percentage (0-100)
stRepeat :: Bool
stRandom :: Bool
stPlaylistVersion :: IntegerA value that is incremented by the server every time the playlist changes.
stPlaylistLength :: IntegerThe number of items in the current playlist.
stSongPos :: Maybe PLIndexCurrent song's position in the playlist.
stSongID :: Maybe PLIndexCurrent song's playlist ID.
stTime :: (Seconds, Seconds)Time elapsed/total time.
stBitrate :: IntBitrate (in kilobytes per second) of playing song (if any).
stXFadeWidth :: SecondsCrossfade time.
stAudio :: (Int, Int, Int)Samplerate/bits/channels for the chosen output device (see mpd.conf).
stUpdatingDb :: IntegerJob ID of currently running update (if any).
stError :: StringLast error message (if any).
show/hide Instances
Admin commands
disableOutput :: Int -> MPD ()Source
Turn off an output device.
enableOutput :: Int -> MPD ()Source
Turn on an output device.
kill :: MPD ()Source
Kill the server. Obviously, the connection is then invalid.
outputs :: MPD [Device]Source
Retrieve information for all output devices.
update :: [Path] -> MPD ()Source
Update the server's database. If no paths are given, all paths will be scanned. Unreadable or non-existent paths are silently ignored.
Database commands
find :: Query -> MPD [Song]Source
Search the database for entries exactly matching a query.
listSource
:: MetaMetadata to list
-> Query
-> MPD [String]
List all metadata of metadata (sic).
listAll :: Path -> MPD [Path]Source
List the songs (without metadata) in a database directory recursively.
listAllInfo :: Path -> MPD [Either Path Song]Source
Recursive lsInfo.
lsInfo :: Path -> MPD [Either Path Song]Source
Non-recursively list the contents of a database directory.
search :: Query -> MPD [Song]Source
Search the database using case insensitive matching.
count :: Query -> MPD CountSource
Count the number of entries matching a query.
Playlist commands
Unless otherwise noted all playlist commands operate on the current playlist.
add :: PlaylistName -> Path -> MPD [Path]Source
Like add_ but returns a list of the files added.
add_ :: PlaylistName -> Path -> MPD ()Source
Add a song (or a whole directory) to a playlist. Adds to current if no playlist is specified. Will create a new playlist if the one specified does not already exist.
addId :: Path -> MPD IntegerSource
Like add, but returns a playlist id.
clear :: PlaylistName -> MPD ()Source
Clear a playlist. Clears current playlist if no playlist is specified. If the specified playlist does not exist, it will be created.
currentSong :: MPD (Maybe Song)Source
Get the currently playing song.
delete :: PlaylistName -> PLIndex -> MPD ()Source
Remove a song from a playlist. If no playlist is specified, current playlist is used. Note that a playlist position (Pos) is required when operating on playlists other than the current.
load :: PlaylistName -> MPD ()Source
Load an existing playlist.
move :: PlaylistName -> PLIndex -> Integer -> MPD ()Source
Move a song to a given position. Note that a playlist position (Pos) is required when operating on playlists other than the current.
playlistInfo :: Maybe PLIndex -> MPD [Song]Source
Retrieve metadata for songs in the current playlist.
listPlaylist :: PlaylistName -> MPD [Path]Source
Retrieve a list of files in a given playlist.
listPlaylistInfo :: PlaylistName -> MPD [Song]Source
Retrieve metadata for files in a given playlist.
playlist :: MPD [(PLIndex, Path)]Source
Retrieve file paths and positions of songs in the current playlist. Note that this command is only included for completeness sake; it's deprecated and likely to disappear at any time, please use playlistInfo instead.
plChanges :: Integer -> MPD [Song]Source
Retrieve a list of changed songs currently in the playlist since a given playlist version.
plChangesPosId :: Integer -> MPD [(PLIndex, PLIndex)]Source
Like plChanges but only returns positions and ids.
playlistFind :: Query -> MPD [Song]Source
Search for songs in the current playlist with strict matching.
playlistSearch :: Query -> MPD [Song]Source
Search case-insensitively with partial matches for songs in the current playlist.
rm :: PlaylistName -> MPD ()Source
Delete existing playlist.
renameSource
:: PlaylistNameOriginal playlist
-> PlaylistNameNew playlist name
-> MPD ()
Rename an existing playlist.
save :: PlaylistName -> MPD ()Source
Save the current playlist.
shuffle :: MPD ()Source
Shuffle the playlist.
swap :: PLIndex -> PLIndex -> MPD ()Source
Swap the positions of two songs. Note that the positions must be of the same type, i.e. mixing Pos and ID will result in a no-op.
Playback commands
crossfade :: Seconds -> MPD ()Source
Set crossfading between songs.
next :: MPD ()Source
Play the next song.
pause :: Bool -> MPD ()Source
Pause playing.
play :: Maybe PLIndex -> MPD ()Source
Begin/continue playing.
previous :: MPD ()Source
Play the previous song.
random :: Bool -> MPD ()Source
Set random playing.
repeat :: Bool -> MPD ()Source
Set repeating.
seek :: Maybe PLIndex -> Seconds -> MPD ()Source
Seek to some point in a song. Seeks in current song if no position is given.
setVolume :: Int -> MPD ()Source
Set the volume (0-100 percent).
volume :: Int -> MPD ()Source
Increase or decrease volume by a given percent, e.g. 'volume 10' will increase the volume by 10 percent, while 'volume (-10)' will decrease it by the same amount. Note that this command is only included for completeness sake ; it's deprecated and may disappear at any time, please use setVolume instead.
stop :: MPD ()Source
Stop playing.
Miscellaneous commands
clearError :: MPD ()Source
Clear the current error message in status.
close :: MPD ()Source
Close an MPD connection.
commands :: MPD [String]Source
Retrieve a list of available commands.
notCommands :: MPD [String]Source
Retrieve a list of unavailable (due to access restrictions) commands.
password :: String -> MPD ()Source
Send password to server to authenticate session. Password is sent as plain text.
ping :: MPD ()Source
Check that the server is still responding.
reconnect :: MPD ()Source
Refresh a connection.
stats :: MPD StatsSource
Get server statistics.
status :: MPD StatusSource
Get the server's status.
tagTypes :: MPD [String]Source
Retrieve a list of available song metadata.
urlHandlers :: MPD [String]Source
Retrieve a list of supported urlhandlers.
Extensions/shortcuts
addMany :: PlaylistName -> [Path] -> MPD ()Source
Add a list of songs/folders to a playlist. Should be more efficient than running add many times.
deleteMany :: PlaylistName -> [PLIndex] -> MPD ()Source
Delete a list of songs from a playlist. If there is a duplicate then no further songs will be deleted, so take care to avoid them (see prune for this).
complete :: String -> MPD [Either Path Song]Source
Returns all songs and directories that match the given partial path name.
crop :: Maybe PLIndex -> Maybe PLIndex -> MPD ()Source
Crop playlist. The bounds are inclusive. If Nothing or ID is passed the cropping will leave your playlist alone on that side.
prune :: MPD ()Source
Remove duplicate playlist entries.
lsDirs :: Path -> MPD [Path]Source
List directories non-recursively.
lsFiles :: Path -> MPD [Path]Source
List files non-recursively.
lsPlaylists :: MPD [PlaylistName]Source
List all playlists.
findArtist :: Artist -> MPD [Song]Source
Search the database for songs relating to an artist.
findAlbum :: Album -> MPD [Song]Source
Search the database for songs relating to an album.
findTitle :: Title -> MPD [Song]Source
Search the database for songs relating to a song title.
listArtists :: MPD [Artist]Source
List the artists in the database.
listAlbums :: Maybe Artist -> MPD [Album]Source
List the albums in the database, optionally matching a given artist.
listAlbum :: Artist -> Album -> MPD [Song]Source
List the songs in an album of some artist.
searchArtist :: Artist -> MPD [Song]Source
Search the database for songs relating to an artist using search.
searchAlbum :: Album -> MPD [Song]Source
Search the database for songs relating to an album using search.
searchTitle :: Title -> MPD [Song]Source
Search the database for songs relating to a song title.
getPlaylist :: MPD [Song]Source
Retrieve the current playlist. Equivalent to playlistinfo Nothing.
toggle :: MPD ()Source
Toggles play/pause. Plays if stopped.
updateId :: [Path] -> MPD IntegerSource
Like update, but returns the update job id.
Produced by Haddock version 2.1.0