mpd-current-json 1.3.2.0 → 1.4.0.0
raw patch · 4 files changed
+35/−13 lines, 4 filesdep ~mpd-current-json
Dependency ranges changed: mpd-current-json
Files
- CHANGELOG.md +4/−0
- lib/Network/MPD/Parse.hs +16/−3
- mpd-current-json.cabal +2/−2
- src/Main.hs +13/−8
CHANGELOG.md view
@@ -1,3 +1,7 @@+# v1.4.0+- Add "`next_filename`" for getting next song file URI relative to the+ music library.+ # v1.3.2 - Add "`next_position`", "`id`" and "`next_id`" keys to `playlist`.
lib/Network/MPD/Parse.hs view
@@ -2,7 +2,8 @@ ( getStatusItem , getTag , processSong- , maybePath+ , maybePathCurrentSong+ , maybePathNextPlaylistSong , headMay , valueToStringMay , (.=?)@@ -51,12 +52,24 @@ let tagVal = MPD.sgGetTag tag song valueToStringMay =<< (headMay =<< tagVal) -maybePath :: Either a (Maybe Song) -> Maybe String-maybePath cs =+{- | Get the current 'Network.MPD.Song' relative path with 'Network.MPD.sgFilePath'+-}+maybePathCurrentSong :: MPD.Response (Maybe Song) -> Maybe String+maybePathCurrentSong cs = case cs of Left _ -> Nothing Right Nothing -> Nothing Right (Just song) -> Just $ MPD.toString $ MPD.sgFilePath song++{- | Get the next song's relative path in the current playlist.++Using 'Network.MPD.sgFilePath' from the returned 'Network.MPD.Response' @[Song]@.+-}+maybePathNextPlaylistSong :: MPD.Response [Song] -> Maybe String+maybePathNextPlaylistSong (Left _) = Nothing+maybePathNextPlaylistSong (Right []) = Nothing+maybePathNextPlaylistSong (Right (_:_:_)) = Nothing+maybePathNextPlaylistSong (Right [s]) = Just $ MPD.toString $ MPD.sgFilePath s {- | Safely get the head of a list. Same as [Safe.headMay](Safe#headMay). -}
mpd-current-json.cabal view
@@ -7,7 +7,7 @@ -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change-version: 1.3.2.0+version: 1.4.0.0 synopsis: Print current MPD song and status as JSON -- A longer description of the package.@@ -60,7 +60,7 @@ , aeson , bytestring >=0.11 && <0.13 , aeson-pretty == 0.8.*- , mpd-current-json == 1.3.*+ , mpd-current-json == 1.4.* -- Directories containing source files. hs-source-dirs: src
src/Main.hs view
@@ -15,7 +15,8 @@ import Network.MPD.Parse ( getStatusItem , getTag- , maybePath+ , maybePathCurrentSong+ , maybePathNextPlaylistSong , (.=?) , objectJson , getStatusIdInt )@@ -33,8 +34,9 @@ main = do opts <- execParser optsParserInfo - cs <- MPD.withMPDEx (optHost opts) (optPort opts) (optPass opts) MPD.currentSong- st <- MPD.withMPDEx (optHost opts) (optPort opts) (optPass opts) MPD.status+ let withMpdOpts = MPD.withMPDEx (optHost opts) (optPort opts) (optPass opts)+ cs <- withMpdOpts MPD.currentSong+ st <- withMpdOpts MPD.status let artist = getTag Artist cs artistSort = getTag ArtistSort cs@@ -107,7 +109,9 @@ nextId = getStatusIdInt MPD.stNextSongID st playlistLength = getStatusItem st MPD.stPlaylistLength - let filename = maybePath cs+ nextPlaylistSong <- withMpdOpts $ MPD.playlistInfo nextId+ let filename = maybePathCurrentSong cs+ filenameNext = maybePathNextPlaylistSong nextPlaylistSong -- sgTags let jTags = objectJson@@ -164,10 +168,11 @@ , "length" .=? playlistLength ] - let jObject = object [ "filename" .= filename- , "playlist" .= jPlaylist- , "status" .= jStatus- , "tags" .= jTags+ let jObject = object [ "filename" .= filename+ , "next_filename" .= filenameNext+ , "playlist" .= jPlaylist+ , "status" .= jStatus+ , "tags" .= jTags ] C.putStrLn $ encodePretty' customEncodeConf jObject