{-# LANGUAGE OverloadedStrings #-}
module Network.MPD.Applicative.CurrentPlaylist
( add
, addId
, clear
, delete
, deleteRange
, deleteId
, move
, moveId
, moveRange
, playlistFind
, playlistInfo
, playlistInfoRange
, playlistId
, playlistSearch
, plChanges
, plChangesPosId
, prio
, prioId
, shuffle
, swap
, swapId
, addTagId
, clearTagId
, rangeId
) where
import Network.MPD.Commands.Arg hiding (Command)
import qualified Network.MPD.Commands.Arg as Arg
import Network.MPD.Util
import Network.MPD.Commands.Query
import Network.MPD.Commands.Parse
import Network.MPD.Commands.Types
import Network.MPD.Applicative.Internal
import Network.MPD.Applicative.Util
add :: Path -> Command ()
add :: Path -> Command ()
add Path
path = Parser () -> [[Char]] -> Command ()
forall a. Parser a -> [[Char]] -> Command a
Command Parser ()
emptyResponse [Command
"add" Command -> Path -> [Char]
forall a. MPDArg a => Command -> a -> [Char]
<@> Path
path]
addId :: Path -> Maybe Position -> Command Id
addId :: Path -> Maybe Position -> Command Id
addId Path
path Maybe Position
pos = Parser Id -> [[Char]] -> Command Id
forall a. Parser a -> [[Char]] -> Command a
Command Parser Id
p [[Char]]
c
where
c :: [[Char]]
c = [Command
"addid" Command -> Args -> [Char]
forall a. MPDArg a => Command -> a -> [Char]
<@> Path
path Path -> Maybe Position -> Args
forall a b. (MPDArg a, MPDArg b) => a -> b -> Args
<++> Maybe Position
pos]
p :: Parser Id
p = do
[ByteString]
r <- Parser [ByteString]
getResponse
case [ByteString] -> [(ByteString, ByteString)]
toAssocList [ByteString]
r of
[(ByteString
"Id", ByteString
n)] -> Parser Id -> (Position -> Parser Id) -> Maybe Position -> Parser Id
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ([ByteString] -> Parser Id
forall a. [ByteString] -> Parser a
unexpected [ByteString]
r) (Id -> Parser Id
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return (Id -> Parser Id) -> (Position -> Id) -> Position -> Parser Id
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Position -> Id
Id) (ByteString -> Maybe Position
forall a. (Read a, Integral a) => ByteString -> Maybe a
parseNum ByteString
n)
[(ByteString, ByteString)]
_ -> [ByteString] -> Parser Id
forall a. [ByteString] -> Parser a
unexpected [ByteString]
r
clear :: Command ()
clear :: Command ()
clear = Parser () -> [[Char]] -> Command ()
forall a. Parser a -> [[Char]] -> Command a
Command Parser ()
emptyResponse [[Char]
"clear"]
delete :: Position -> Command ()
delete :: Position -> Command ()
delete Position
pos = Parser () -> [[Char]] -> Command ()
forall a. Parser a -> [[Char]] -> Command a
Command Parser ()
emptyResponse [Command
"delete" Command -> Position -> [Char]
forall a. MPDArg a => Command -> a -> [Char]
<@> Position
pos]
deleteRange :: Range -> Command ()
deleteRange :: Range -> Command ()
deleteRange Range
range = Parser () -> [[Char]] -> Command ()
forall a. Parser a -> [[Char]] -> Command a
Command Parser ()
emptyResponse [Command
"delete" Command -> Range -> [Char]
forall a. MPDArg a => Command -> a -> [Char]
<@> Range
range]
deleteId :: Id -> Command ()
deleteId :: Id -> Command ()
deleteId Id
i = Parser () -> [[Char]] -> Command ()
forall a. Parser a -> [[Char]] -> Command a
Command Parser ()
emptyResponse [Command
"deleteid" Command -> Id -> [Char]
forall a. MPDArg a => Command -> a -> [Char]
<@> Id
i]
move :: Position -> Position -> Command ()
move :: Position -> Position -> Command ()
move Position
pos Position
to = Parser () -> [[Char]] -> Command ()
forall a. Parser a -> [[Char]] -> Command a
Command Parser ()
emptyResponse [Command
"move" Command -> Args -> [Char]
forall a. MPDArg a => Command -> a -> [Char]
<@> Position
pos Position -> Position -> Args
forall a b. (MPDArg a, MPDArg b) => a -> b -> Args
<++> Position
to]
moveRange :: Range -> Position -> Command ()
moveRange :: Range -> Position -> Command ()
moveRange Range
range Position
to = Parser () -> [[Char]] -> Command ()
forall a. Parser a -> [[Char]] -> Command a
Command Parser ()
emptyResponse [Command
"move" Command -> Args -> [Char]
forall a. MPDArg a => Command -> a -> [Char]
<@> Range
range Range -> Position -> Args
forall a b. (MPDArg a, MPDArg b) => a -> b -> Args
<++> Position
to]
moveId :: Id -> Position -> Command ()
moveId :: Id -> Position -> Command ()
moveId Id
i Position
to = Parser () -> [[Char]] -> Command ()
forall a. Parser a -> [[Char]] -> Command a
Command Parser ()
emptyResponse [Command
"moveid" Command -> Args -> [Char]
forall a. MPDArg a => Command -> a -> [Char]
<@> Id
i Id -> Position -> Args
forall a b. (MPDArg a, MPDArg b) => a -> b -> Args
<++> Position
to]
playlist' :: MPDArg a => Arg.Command -> a -> Command [Song]
playlist' :: forall a. MPDArg a => Command -> a -> Command [Song]
playlist' Command
cmd a
q = Parser [Song] -> [[Char]] -> Command [Song]
forall a. Parser a -> [[Char]] -> Command a
Command (([ByteString] -> Either [Char] [Song]) -> Parser [Song]
forall a. ([ByteString] -> Either [Char] a) -> Parser a
liftParser [ByteString] -> Either [Char] [Song]
takeSongs) [Command
cmd Command -> a -> [Char]
forall a. MPDArg a => Command -> a -> [Char]
<@> a
q]
playlistFind :: Query -> Command [Song]
playlistFind :: Query -> Command [Song]
playlistFind = Command -> Query -> Command [Song]
forall a. MPDArg a => Command -> a -> Command [Song]
playlist' Command
"playlistfind"
playlistInfo :: Maybe Position -> Command [Song]
playlistInfo :: Maybe Position -> Command [Song]
playlistInfo = Command -> Maybe Position -> Command [Song]
forall a. MPDArg a => Command -> a -> Command [Song]
playlist' Command
"playlistinfo"
playlistInfoRange :: Maybe Range -> Command [Song]
playlistInfoRange :: Maybe Range -> Command [Song]
playlistInfoRange = Command -> Maybe Range -> Command [Song]
forall a. MPDArg a => Command -> a -> Command [Song]
playlist' Command
"playlistinfo"
playlistId :: Maybe Id -> Command [Song]
playlistId :: Maybe Id -> Command [Song]
playlistId = Command -> Maybe Id -> Command [Song]
forall a. MPDArg a => Command -> a -> Command [Song]
playlist' Command
"playlistid"
playlistSearch :: Query -> Command [Song]
playlistSearch :: Query -> Command [Song]
playlistSearch = Command -> Query -> Command [Song]
forall a. MPDArg a => Command -> a -> Command [Song]
playlist' Command
"playlistsearch"
plChanges :: Integer -> Command [Song]
plChanges :: Integer -> Command [Song]
plChanges = Command -> Integer -> Command [Song]
forall a. MPDArg a => Command -> a -> Command [Song]
playlist' Command
"plchanges"
plChangesPosId :: Integer -> Command [(Position, Id)]
plChangesPosId :: Integer -> Command [(Position, Id)]
plChangesPosId Integer
ver = Parser [(Position, Id)] -> [[Char]] -> Command [(Position, Id)]
forall a. Parser a -> [[Char]] -> Command a
Command Parser [(Position, Id)]
p [Command
"plchangesposid" Command -> Integer -> [Char]
forall a. MPDArg a => Command -> a -> [Char]
<@> Integer
ver]
where
p :: Parser [(Position, Id)]
p :: Parser [(Position, Id)]
p = ([ByteString] -> Either [Char] [(Position, Id)])
-> Parser [(Position, Id)]
forall a. ([ByteString] -> Either [Char] a) -> Parser a
liftParser (([ByteString] -> Either [Char] [(Position, Id)])
-> Parser [(Position, Id)])
-> ([ByteString] -> Either [Char] [(Position, Id)])
-> Parser [(Position, Id)]
forall a b. (a -> b) -> a -> b
$ ([(ByteString, ByteString)] -> Either [Char] (Position, Id))
-> [[(ByteString, ByteString)]] -> Either [Char] [(Position, Id)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM [(ByteString, ByteString)] -> Either [Char] (Position, Id)
forall {a} {a}.
(Eq a, IsString a, IsString a) =>
[(a, ByteString)] -> Either a (Position, Id)
f ([[(ByteString, ByteString)]] -> Either [Char] [(Position, Id)])
-> ([ByteString] -> [[(ByteString, ByteString)]])
-> [ByteString]
-> Either [Char] [(Position, Id)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [ByteString]
-> [(ByteString, ByteString)] -> [[(ByteString, ByteString)]]
splitGroups [ByteString
"cpos"] ([(ByteString, ByteString)] -> [[(ByteString, ByteString)]])
-> ([ByteString] -> [(ByteString, ByteString)])
-> [ByteString]
-> [[(ByteString, ByteString)]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [ByteString] -> [(ByteString, ByteString)]
toAssocList
f :: [(a, ByteString)] -> Either a (Position, Id)
f [(a, ByteString)]
xs | [(a
"cpos", ByteString
x), (a
"Id", ByteString
y)] <- [(a, ByteString)]
xs
, Just (Position
x', Position
y') <- (ByteString -> Maybe Position)
-> (ByteString, ByteString) -> Maybe (Position, Position)
forall a.
(ByteString -> Maybe a) -> (ByteString, ByteString) -> Maybe (a, a)
pair ByteString -> Maybe Position
forall a. (Read a, Integral a) => ByteString -> Maybe a
parseNum (ByteString
x, ByteString
y)
= (Position, Id) -> Either a (Position, Id)
forall a b. b -> Either a b
Right (Position
x', Position -> Id
Id Position
y')
| Bool
otherwise = a -> Either a (Position, Id)
forall a b. a -> Either a b
Left a
""
prio :: Priority -> Range -> Command ()
prio :: Priority -> Range -> Command ()
prio Priority
p Range
range = Parser () -> [[Char]] -> Command ()
forall a. Parser a -> [[Char]] -> Command a
Command Parser ()
emptyResponse [Command
"prio" Command -> Args -> [Char]
forall a. MPDArg a => Command -> a -> [Char]
<@> Priority
p Priority -> Range -> Args
forall a b. (MPDArg a, MPDArg b) => a -> b -> Args
<++> Range
range]
prioId :: Priority -> Id -> Command ()
prioId :: Priority -> Id -> Command ()
prioId Priority
p Id
ids = Parser () -> [[Char]] -> Command ()
forall a. Parser a -> [[Char]] -> Command a
Command Parser ()
emptyResponse [Command
"prioid" Command -> Args -> [Char]
forall a. MPDArg a => Command -> a -> [Char]
<@> Priority
p Priority -> Id -> Args
forall a b. (MPDArg a, MPDArg b) => a -> b -> Args
<++> Id
ids]
shuffle :: Maybe Range -> Command ()
shuffle :: Maybe Range -> Command ()
shuffle Maybe Range
mbRange = Parser () -> [[Char]] -> Command ()
forall a. Parser a -> [[Char]] -> Command a
Command Parser ()
emptyResponse [Command
"shuffle" Command -> Maybe Range -> [Char]
forall a. MPDArg a => Command -> a -> [Char]
<@> Maybe Range
mbRange]
swap :: Position -> Position -> Command ()
swap :: Position -> Position -> Command ()
swap Position
pos1 Position
pos2 = Parser () -> [[Char]] -> Command ()
forall a. Parser a -> [[Char]] -> Command a
Command Parser ()
emptyResponse [Command
"swap" Command -> Args -> [Char]
forall a. MPDArg a => Command -> a -> [Char]
<@> Position
pos1 Position -> Position -> Args
forall a b. (MPDArg a, MPDArg b) => a -> b -> Args
<++> Position
pos2]
swapId :: Id -> Id -> Command ()
swapId :: Id -> Id -> Command ()
swapId Id
id1 Id
id2 = Parser () -> [[Char]] -> Command ()
forall a. Parser a -> [[Char]] -> Command a
Command Parser ()
emptyResponse [Command
"swapid" Command -> Args -> [Char]
forall a. MPDArg a => Command -> a -> [Char]
<@> Id
id1 Id -> Id -> Args
forall a b. (MPDArg a, MPDArg b) => a -> b -> Args
<++> Id
id2]
addTagId :: Id -> Metadata -> Value -> Command ()
addTagId :: Id -> Metadata -> Value -> Command ()
addTagId Id
id' Metadata
tag Value
val = Parser () -> [[Char]] -> Command ()
forall a. Parser a -> [[Char]] -> Command a
Command Parser ()
emptyResponse [Command
"addtagid" Command -> Args -> [Char]
forall a. MPDArg a => Command -> a -> [Char]
<@> Id
id' Id -> Metadata -> Args
forall a b. (MPDArg a, MPDArg b) => a -> b -> Args
<++> Metadata
tag Args -> Value -> Args
forall a b. (MPDArg a, MPDArg b) => a -> b -> Args
<++> Value
val]
clearTagId :: Id -> Metadata -> Command ()
clearTagId :: Id -> Metadata -> Command ()
clearTagId Id
id' Metadata
tags = Parser () -> [[Char]] -> Command ()
forall a. Parser a -> [[Char]] -> Command a
Command Parser ()
emptyResponse [Command
"cleartagid" Command -> Args -> [Char]
forall a. MPDArg a => Command -> a -> [Char]
<@> Id
id' Id -> Metadata -> Args
forall a b. (MPDArg a, MPDArg b) => a -> b -> Args
<++> Metadata
tags]
rangeId :: Id -> (Maybe Double, Maybe Double) -> Command ()
rangeId :: Id -> (Maybe Double, Maybe Double) -> Command ()
rangeId Id
id' (Maybe Double
mbStart, Maybe Double
mbEnd) = Parser () -> [[Char]] -> Command ()
forall a. Parser a -> [[Char]] -> Command a
Command Parser ()
emptyResponse [[Char]
"rangeid " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Id -> [Char]
forall a. Show a => a -> [Char]
show Id
id' [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
" " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
arg ]
where arg :: [Char]
arg = [Char] -> (Double -> [Char]) -> Maybe Double -> [Char]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [Char]
"" Double -> [Char]
forall a. Show a => a -> [Char]
show Maybe Double
mbStart [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
":" [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char] -> (Double -> [Char]) -> Maybe Double -> [Char]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [Char]
"" Double -> [Char]
forall a. Show a => a -> [Char]
show Maybe Double
mbEnd