X-Git-Url: https://git.rvb.name/mpd-web.git/blobdiff_plain/2960e74781dd44518c88c276e8eea4aec245795b..40bb089389b428c836f544e2d94a48dfae415229:/system/mpd_class.php?ds=sidebyside diff --git a/system/mpd_class.php b/system/mpd_class.php index 6f9f1ac..d32748d 100644 --- a/system/mpd_class.php +++ b/system/mpd_class.php @@ -51,6 +51,8 @@ define("MPD_CMD_PLSWAPTRACK", "swap"); define("MPD_CMD_PLMOVETRACK", "move"); define("MPD_CMD_PASSWORD", "password"); define("MPD_CMD_TABLE", "list"); +define("MPD_CMD_LISTS", "listplaylists"); +define("MPD_CMD_DELLIST", "rm"); // Predefined MPD Response messages define("MPD_RESPONSE_ERR", "ACK"); @@ -417,6 +419,17 @@ class mpd { return $resp; } + /* PLList() + * + * Retrieves the playlists info. + */ + function PLList() { + if ( $this->debugging ) echo "mpd->PLList()\n"; + if ( ! is_null($resp = $this->SendCommand(MPD_CMD_LISTS))) $this->RefreshInfo(); + if ( $this->debugging ) echo "mpd->PLList() / return\n"; + return $resp; + } + /* PLSave() * * Saves the playlist to .m3u for later retrieval. The file is saved in the MPD playlist @@ -429,6 +442,17 @@ class mpd { return $resp; } + /* PLDel() + * + * Deletes playlist .m3u in the MPD playlist directory. + */ + function PLDel($file) { + if ( $this->debugging ) echo "mpd->PLDel()\n"; + $resp = $this->SendCommand(MPD_CMD_DELLIST,$file); + if ( $this->debugging ) echo "mpd->PLDel() / return\n"; + return $resp; + } + /* PLClear() * * Empties the playlist. @@ -814,6 +838,35 @@ class mpd { return $plistArray; } + /* _parsePlayListsResponse() + * + * Builds a multidimensional array with MPD response lists. + * + * NOTE: This function is used internally within the class. It should not be used. + */ + function _parsePlayListsResponse($resp) { + if ( is_null($resp) ) { + return NULL; + } else { + $plistArray = array(); + $plistLine = strtok($resp,"\n"); + $plistFile = ""; + $plCounter = -1; + while ( $plistLine ) { + list ( $element, $value ) = explode(": ",$plistLine); + if($element == "playlist") { + $plCounter++; + $plistArray[$plCounter]['name']=$value; + } + if($element == "Last-Modified") { + $plistArray[$plCounter]['timestamp']=$value; + } + $plistLine = strtok("\n"); + } + } + return $plistArray; + } + /* RefreshInfo() * * Updates all class properties with the values from the MPD server. @@ -849,6 +902,10 @@ class mpd { } } + // Get list of lists + $plStr = $this->SendCommand(MPD_CMD_LISTS); + $this->playlists = $this->_parsePlayListsResponse($plStr); + // Get the Playlist $plStr = $this->SendCommand(MPD_CMD_PLLIST); $this->playlist = $this->_parseFileListResponse($plStr);