libmpd-0.9.0.1: An MPD client library.

Copyright(c) Joachim Fasting, Simon Hengel 2012
LicenseMIT
MaintainerJoachim Fasting <joachifm@fastmail.fm>
Stabilityunstable
Portabilityunportable
Safe HaskellNone
LanguageHaskell2010

Network.MPD

Contents

Description

An MPD client library. MPD is a daemon for playing music that is controlled over a network socket.

To use the library, do:

import qualified Network.MPD as MPD

Synopsis

Basic data types

class (Monad m, MonadError MPDError m) => MonadMPD m Source

A typeclass to allow for multiple implementations of a connection to an MPD server.

Minimal complete definition

open, close, send, getPassword, setPassword, getVersion

Instances

data MPD a Source

The main implementation of an MPD client. It actually connects to a server and interacts with it.

To use the error throwing/catching capabilities:

import Control.Monad.Error (throwError, catchError)

To run IO actions within the MPD monad:

import Control.Monad.Trans (liftIO)

data MPDError Source

The MPDError type is used to signal errors, both from the MPD and otherwise.

Constructors

NoMPD

MPD not responding

ConnectionError IOException

An error occurred while talking to MPD.

Unexpected String

MPD returned an unexpected response. This is a bug, either in the library or in MPD itself.

Custom String

Used for misc. errors

ACK ACKType String

ACK type and a message from the server

data ACKType Source

Represents various MPD errors (aka. ACKs).

Constructors

InvalidArgument

Invalid argument passed (ACK 2)

InvalidPassword

Invalid password supplied (ACK 3)

Auth

Authentication required (ACK 4)

UnknownCommand

Unknown command (ACK 5)

FileNotFound

File or directory not found ACK 50)

PlaylistMax

Playlist at maximum size (ACK 51)

System

A system error (ACK 52)

PlaylistLoad

Playlist loading failed (ACK 53)

Busy

Update already running (ACK 54)

NotPlaying

An operation requiring playback got interrupted (ACK 55)

FileExists

File already exists (ACK 56)

UnknownACK

An unknown ACK (aka. bug)

Instances

type Response = Either MPDError Source

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

withMPD_ Source

Arguments

:: Maybe String

optional override for MPD_HOST

-> Maybe String

optional override for MPD_PORT

-> MPD a 
-> IO (Response a) 

Same as withMPD, but takes optional arguments that override MPD_HOST and MPD_PORT.

This is e.g. useful for clients that optionally take --port and --host as command line arguments, and fall back to withMPD's defaults if those arguments are not given.

withMPDEx :: Host -> Port -> Password -> MPD a -> IO (Response a) Source

The most configurable API for running an MPD action.

data Query Source

An interface for creating MPD queries.

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

Artist =? "Foo"

We can also compose queries, thus narrowing the search. For example, to match any song where the value of artist is "Foo" and the value of album is "Bar", we use:

Artist =? "Foo" <&> Album =? "Bar"

Instances

(=?) :: Metadata -> Value -> Query Source

Create a query.

(<&>) :: Query -> Query -> Query infixr 6 Source

Combine queries.

anything :: Query Source

An empty query. Matches anything.

class ToString a where Source

A type class for values that can be converted to Strings.

Methods

toString :: a -> String Source

Convert given value to String.

toText :: a -> Text Source

Convert given value to Text.

toUtf8 :: a -> ByteString Source

Convert given value to a UTF-8 encoded ByteString.

newtype PlaylistName Source

Used for commands which require a playlist name. If empty, the current playlist is used.

Constructors

PlaylistName ByteString 

data Path Source

Used for commands which require a path within the database. If empty, the root path is used.

data Metadata Source

Available metadata types/scope modifiers, used for searching the database for entries with certain metadata values.

data Value Source

A metadata value.

data ObjectType Source

Object types.

Constructors

SongObj 

data State Source

Represents the different playback states.

Constructors

Playing 
Stopped 
Paused 

Instances

data Subsystem Source

Represents the various MPD subsystems.

Constructors

DatabaseS

The song database

UpdateS

Database updates

StoredPlaylistS

Stored playlists

PlaylistS

The current playlist

PlayerS

The player

MixerS

The volume mixer

OutputS

Audio outputs

OptionsS

Playback options

StickerS

Sticker database

SubscriptionS

Subscription

MessageS

Message on subscribed channel

data ReplayGainMode Source

Constructors

Off

Disable replay gain

TrackMode

Per track mode

AlbumMode

Per album mode

data Count Source

Represents the result of running count.

Constructors

Count 

Fields

cSongs :: Integer

Number of songs matching the query

cPlaytime :: Seconds

Total play time of matching songs

data LsResult Source

Result of the lsInfo operation

Constructors

LsDirectory Path

Directory

LsSong Song

Song

LsPlaylist PlaylistName

Playlist

Instances

data Device Source

Represents an output device.

Constructors

Device 

Fields

dOutputID :: Int

Output's ID number

dOutputName :: String

Output's name as defined in the MPD configuration file

dOutputEnabled :: Bool
 

data Song Source

Represents a single song item.

Constructors

Song 

Fields

sgFilePath :: Path
 
sgTags :: Map Metadata [Value]

Map of available tags (multiple occurrences of one tag type allowed)

sgLastModified :: Maybe UTCTime

Last modification date

sgLength :: Seconds

Length of the song in seconds

sgId :: Maybe Id

Id in playlist

sgIndex :: Maybe Position

Position in playlist

Instances

type Position = Int Source

The position of a song in a playlist.

newtype Id Source

Constructors

Id Int 

Instances

sgGetTag :: Metadata -> Song -> Maybe [Value] Source

Get list of specific tag type

sgAddTag :: Metadata -> Value -> Song -> Song Source

Add metadata tag value.

data Stats Source

Container for database statistics.

Constructors

Stats 

Fields

stsArtists :: Integer

Number of artists.

stsAlbums :: Integer

Number of albums.

stsSongs :: Integer

Number of songs.

stsUptime :: Seconds

Daemon uptime in seconds.

stsPlaytime :: Seconds

Total playing time.

stsDbPlaytime :: Seconds

Total play time of all the songs in the database.

stsDbUpdate :: Integer

Last database update in UNIX time.

data Status Source

Container for MPD status.

Constructors

Status 

Fields

stState :: State
 
stVolume :: Maybe Int

A percentage (0-100).

Nothing indicates that the output lacks mixer support.

stRepeat :: Bool
 
stRandom :: Bool
 
stPlaylistVersion :: Integer

A value that is incremented by the server every time the playlist changes.

stPlaylistLength :: Integer

The number of items in the current playlist.

stSongPos :: Maybe Position

Current song's position in the playlist.

stSongID :: Maybe Id

Current song's playlist ID.

stNextSongPos :: Maybe Position

Next song's position in the playlist.

stNextSongID :: Maybe Id

Next song's playlist ID.

stTime :: Maybe (Double, Seconds)

Time elapsed/total time of playing song (if any).

stBitrate :: Maybe Int

Bitrate (in kilobytes per second) of playing song (if any).

stXFadeWidth :: Seconds

Crossfade time.

stMixRampdB :: Double

MixRamp threshold in dB

stMixRampDelay :: Double

MixRamp extra delay in seconds

stAudio :: (Int, Int, Int)

Samplerate/bits/channels for the chosen output device (see mpd.conf).

stUpdatingDb :: Maybe Integer

Job ID of currently running update (if any).

stSingle :: Bool

If True, MPD will play only one song and stop after finishing it.

stConsume :: Bool

If True, a song will be removed after it has been played.

stError :: Maybe String

Last error message (if any).

def :: Default a => a

The default value for this type.

clearError :: MonadMPD m => m () Source

Clear the current error message in status.

currentSong :: MonadMPD m => m (Maybe Song) Source

Get the currently playing song.

idle :: MonadMPD m => [Subsystem] -> m [Subsystem] Source

Wait until there is a noteworthy change in one or more of MPD's susbystems.

The first argument is a list of subsystems that should be considered. An empty list specifies that all subsystems should be considered.

A list of subsystems that have noteworthy changes is returned.

Note that running this command will block until either idle returns or is cancelled by noidle.

noidle :: MonadMPD m => m () Source

Cancel idle.

stats :: MonadMPD m => m Stats Source

Get server statistics.

status :: MonadMPD m => m Status Source

Get the server's status.

consume :: MonadMPD m => Bool -> m () Source

Set consume mode

crossfade :: MonadMPD m => Seconds -> m () Source

Set crossfading between songs.

random :: MonadMPD m => Bool -> m () Source

Set random playing.

repeat :: MonadMPD m => Bool -> m () Source

Set repeating.

setVolume :: MonadMPD m => Int -> m () Source

Set the volume (0-100 percent).

single :: MonadMPD m => Bool -> m () Source

Set single mode

replayGainMode :: MonadMPD m => ReplayGainMode -> m () Source

Set the replay gain mode.

replayGainStatus :: MonadMPD m => m [(String, String)] Source

Get the replay gain options.

next :: MonadMPD m => m () Source

Play the next song.

pause :: MonadMPD m => Bool -> m () Source

Pause playing.

play :: MonadMPD m => Maybe Position -> m () Source

Begin/continue playing.

playId :: MonadMPD m => Id -> m () Source

Play a file with given id.

previous :: MonadMPD m => m () Source

Play the previous song.

seek :: MonadMPD m => Position -> Seconds -> m () Source

Seek to some point in a song.

seekId :: MonadMPD m => Id -> Seconds -> m () Source

Seek to some point in a song (id version)

stop :: MonadMPD m => m () Source

Stop playing.

addId :: MonadMPD m => Path -> Maybe Position -> m Id Source

Like add, but returns a playlist id.

add :: MonadMPD m => Path -> m () Source

Add a song (or a whole directory) to the current playlist.

clear :: MonadMPD m => m () Source

Clear the current playlist.

delete :: MonadMPD m => Position -> m () Source

Remove a song from the current playlist.

deleteId :: MonadMPD m => Id -> m () Source

Remove a song from the current playlist.

move :: MonadMPD m => Position -> Position -> m () Source

Move a song to a given position in the current playlist.

moveId :: MonadMPD m => Id -> Position -> m () Source

Move a song from (songid) to (playlist index) in the playlist. If to is negative, it is relative to the current song in the playlist (if there is one).

playlist :: MonadMPD m => m [(Position, Path)] Source

Warning: this is deprecated; please use playlistInfo instead.

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.

playlistFind :: MonadMPD m => Query -> m [Song] Source

Search for songs in the current playlist with strict matching.

playlistInfo :: MonadMPD m => Maybe Position -> m [Song] Source

Retrieve metadata for songs in the current playlist.

playlistInfoRange :: MonadMPD m => Maybe (Position, Position) -> m [Song] Source

Like playlistInfo but can restrict to a range of songs.

playlistId :: MonadMPD m => Maybe Id -> m [Song] Source

Displays a list of songs in the playlist. If id is specified, only its info is returned.

playlistSearch :: MonadMPD m => Query -> m [Song] Source

Search case-insensitively with partial matches for songs in the current playlist.

plChanges :: MonadMPD m => Integer -> m [Song] Source

Retrieve a list of changed songs currently in the playlist since a given playlist version.

plChangesPosId :: MonadMPD m => Integer -> m [(Position, Id)] Source

Like plChanges but only returns positions and ids.

shuffle Source

Arguments

:: MonadMPD m 
=> Maybe (Position, Position)

Optional range (start, end)

-> m () 

Shuffle the playlist.

swap :: MonadMPD m => Position -> Position -> m () Source

Swap the positions of two songs.

swapId :: MonadMPD m => Id -> Id -> m () Source

Swap the positions of two songs (Id version)

listPlaylist :: MonadMPD m => PlaylistName -> m [Path] Source

Retrieve a list of files in a given playlist.

listPlaylistInfo :: MonadMPD m => PlaylistName -> m [Song] Source

Retrieve metadata for files in a given playlist.

listPlaylists :: MonadMPD m => m [PlaylistName] Source

Retreive a list of stored playlists.

load :: MonadMPD m => PlaylistName -> m () Source

Load an existing playlist.

playlistAdd :: MonadMPD m => PlaylistName -> Path -> m () Source

Add a song (or a whole directory) to a stored playlist. Will create a new playlist if the one specified does not already exist.

playlistClear :: MonadMPD m => PlaylistName -> m () Source

Clear a playlist. If the specified playlist does not exist, it will be created.

playlistDelete :: MonadMPD m => PlaylistName -> Position -> m () Source

Remove a song from a playlist.

playlistMove :: MonadMPD m => PlaylistName -> Id -> Position -> m () Source

Move a song to a given position in the playlist specified.

rename Source

Arguments

:: MonadMPD m 
=> PlaylistName

Original playlist

-> PlaylistName

New playlist name

-> m () 

Rename an existing playlist.

rm :: MonadMPD m => PlaylistName -> m () Source

Delete existing playlist.

save :: MonadMPD m => PlaylistName -> m () Source

Save the current playlist.

count :: MonadMPD m => Query -> m Count Source

Count the number of entries matching a query.

find :: MonadMPD m => Query -> m [Song] Source

Search the database for entries exactly matching a query.

findAdd :: MonadMPD m => Query -> m () Source

Adds songs matching a query to the current playlist.

list Source

Arguments

:: MonadMPD m 
=> Metadata

Metadata to list

-> Maybe Artist 
-> m [Value] 

List all tags of the specified type.

listAll :: MonadMPD m => Path -> m [Path] Source

List the songs (without metadata) in a database directory recursively.

listAllInfo :: MonadMPD m => Path -> m [LsResult] Source

Recursive lsInfo.

lsInfo :: MonadMPD m => Path -> m [LsResult] Source

Non-recursively list the contents of a database directory.

search :: MonadMPD m => Query -> m [Song] Source

Search the database using case insensitive matching.

update :: MonadMPD m => Maybe Path -> m Integer Source

Update the server's database.

If no path is given, the whole library will be scanned. Unreadable or non-existent paths are silently ignored.

The update job id is returned.

rescan :: MonadMPD m => Maybe Path -> m Integer Source

Like update but also rescans unmodified files.

stickerGet Source

Arguments

:: MonadMPD m 
=> ObjectType 
-> String

Object URI

-> String

Sticker name

-> m [String] 

Reads a sticker value for the specified object.

stickerSet Source

Arguments

:: MonadMPD m 
=> ObjectType 
-> String

Object URI

-> String

Sticker name

-> String

Sticker value

-> m () 

Adds a sticker value to the specified object.

stickerDelete Source

Arguments

:: MonadMPD m 
=> ObjectType 
-> String

Object URI

-> String

Sticker name

-> m () 

Delete a sticker value from the specified object.

stickerList Source

Arguments

:: MonadMPD m 
=> ObjectType 
-> String

Object URI

-> m [(String, String)]

Sticker name/sticker value

Lists the stickers for the specified object.

stickerFind Source

Arguments

:: MonadMPD m 
=> ObjectType 
-> String

Path

-> String

Sticker name

-> m [(String, String)]

URI/sticker value

Searches the sticker database for stickers with the specified name, below the specified path.

password :: MonadMPD m => String -> m () Source

Send password to server to authenticate session. Password is sent as plain text.

ping :: MonadMPD m => m () Source

Check that the server is still responding.

disableOutput :: MonadMPD m => Int -> m () Source

Turn off an output device.

enableOutput :: MonadMPD m => Int -> m () Source

Turn on an output device.

outputs :: MonadMPD m => m [Device] Source

Retrieve information for all output devices.

commands :: MonadMPD m => m [String] Source

Retrieve a list of available commands.

notCommands :: MonadMPD m => m [String] Source

Retrieve a list of unavailable (due to access restrictions) commands.

tagTypes :: MonadMPD m => m [String] Source

Retrieve a list of available song metadata.

urlHandlers :: MonadMPD m => m [String] Source

Retrieve a list of supported urlhandlers.

decoders :: MonadMPD m => m [(String, [(String, String)])] Source

Retreive a list of decoder plugins with associated suffix and mime types.

config :: MonadMPD m => m [(String, String)] Source

Retrieve configuration keys and values.

Types

Subscribing to channels

Communicating with other clients