{-# LANGUAGE OverloadedStrings #-}
module Network.MPD.Applicative.StoredPlaylists
( listPlaylist
, listPlaylistInfo
, listPlaylists
, load
, playlistAdd
, playlistClear
, playlistDelete
, playlistMove
, rename
, rm
, save
) where
import Network.MPD.Applicative.Internal
import Network.MPD.Applicative.Util
import Network.MPD.Commands.Arg hiding (Command)
import Network.MPD.Commands.Types
import Network.MPD.Util
listPlaylist :: PlaylistName -> Command [Path]
listPlaylist :: PlaylistName -> Command [Path]
listPlaylist PlaylistName
plName = forall a. Parser a -> [String] -> Command a
Command Parser [Path]
p [Command
"listplaylist" forall a. MPDArg a => Command -> a -> String
<@> PlaylistName
plName]
where
p :: Parser [Path]
p = forall a b. (a -> b) -> [a] -> [b]
map ByteString -> Path
Path forall b c a. (b -> c) -> (a -> b) -> a -> c
. [ByteString] -> [ByteString]
takeValues forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [ByteString]
getResponse
listPlaylistInfo :: PlaylistName -> Command [Song]
listPlaylistInfo :: PlaylistName -> Command [Song]
listPlaylistInfo PlaylistName
plName =
forall a. Parser a -> [String] -> Command a
Command (forall a. ([ByteString] -> Either String a) -> Parser a
liftParser [ByteString] -> Either String [Song]
takeSongs) [Command
"listplaylistinfo" forall a. MPDArg a => Command -> a -> String
<@> PlaylistName
plName]
listPlaylists :: Command [PlaylistName]
listPlaylists :: Command [PlaylistName]
listPlaylists = forall a. Parser a -> [String] -> Command a
Command Parser [PlaylistName]
p [String
"listplaylists"]
where
p :: Parser [PlaylistName]
p = forall a b. (a -> b) -> [a] -> [b]
map ByteString -> PlaylistName
PlaylistName forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {a} {a}. [a] -> [(a, a)] -> [a]
go [] forall b c a. (b -> c) -> (a -> b) -> a -> c
. [ByteString] -> [(ByteString, ByteString)]
toAssocList forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [ByteString]
getResponse
go :: [a] -> [(a, a)] -> [a]
go [a]
acc [] = [a]
acc
go [a]
acc ((a
_, a
b):(a, a)
_:[(a, a)]
xs) = [a] -> [(a, a)] -> [a]
go (a
b forall a. a -> [a] -> [a]
: [a]
acc) [(a, a)]
xs
go [a]
_ [(a, a)]
_ = forall a. HasCallStack => String -> a
error String
"listPlaylists: bug"
load :: PlaylistName -> Command ()
load :: PlaylistName -> Command ()
load PlaylistName
plName = forall a. Parser a -> [String] -> Command a
Command Parser ()
emptyResponse [Command
"load" forall a. MPDArg a => Command -> a -> String
<@> PlaylistName
plName]
playlistAdd :: PlaylistName -> Path -> Command ()
playlistAdd :: PlaylistName -> Path -> Command ()
playlistAdd PlaylistName
plName Path
path =
forall a. Parser a -> [String] -> Command a
Command Parser ()
emptyResponse [Command
"playlistadd" forall a. MPDArg a => Command -> a -> String
<@> PlaylistName
plName forall a b. (MPDArg a, MPDArg b) => a -> b -> Args
<++> Path
path]
playlistClear :: PlaylistName -> Command ()
playlistClear :: PlaylistName -> Command ()
playlistClear PlaylistName
plName = forall a. Parser a -> [String] -> Command a
Command Parser ()
emptyResponse [Command
"playlistclear" forall a. MPDArg a => Command -> a -> String
<@> PlaylistName
plName]
playlistDelete :: PlaylistName -> Position -> Command ()
playlistDelete :: PlaylistName -> Position -> Command ()
playlistDelete PlaylistName
name Position
pos =
forall a. Parser a -> [String] -> Command a
Command Parser ()
emptyResponse [Command
"playlistdelete" forall a. MPDArg a => Command -> a -> String
<@> PlaylistName
name forall a b. (MPDArg a, MPDArg b) => a -> b -> Args
<++> Position
pos]
playlistMove :: PlaylistName -> Id -> Position -> Command ()
playlistMove :: PlaylistName -> Id -> Position -> Command ()
playlistMove PlaylistName
name Id
from Position
to =
forall a. Parser a -> [String] -> Command a
Command Parser ()
emptyResponse [Command
"playlistmove" forall a. MPDArg a => Command -> a -> String
<@> PlaylistName
name forall a b. (MPDArg a, MPDArg b) => a -> b -> Args
<++> Id
from forall a b. (MPDArg a, MPDArg b) => a -> b -> Args
<++> Position
to]
rename :: PlaylistName -> PlaylistName -> Command ()
rename :: PlaylistName -> PlaylistName -> Command ()
rename PlaylistName
plName PlaylistName
new = forall a. Parser a -> [String] -> Command a
Command Parser ()
emptyResponse [Command
"rename" forall a. MPDArg a => Command -> a -> String
<@> PlaylistName
plName forall a b. (MPDArg a, MPDArg b) => a -> b -> Args
<++> PlaylistName
new]
rm :: PlaylistName -> Command ()
rm :: PlaylistName -> Command ()
rm PlaylistName
plName = forall a. Parser a -> [String] -> Command a
Command Parser ()
emptyResponse [Command
"rm" forall a. MPDArg a => Command -> a -> String
<@> PlaylistName
plName]
save :: PlaylistName -> Command ()
save :: PlaylistName -> Command ()
save PlaylistName
plName = forall a. Parser a -> [String] -> Command a
Command Parser ()
emptyResponse [Command
"save" forall a. MPDArg a => Command -> a -> String
<@> PlaylistName
plName]