X-Git-Url: https://git.rvb.name/mpd-web.git/blobdiff_plain/2960e74781dd44518c88c276e8eea4aec245795b..75e2078309389c03d7baa25c2f597b4b42367894:/system/mpd_class.php diff --git a/system/mpd_class.php b/system/mpd_class.php index 6f9f1ac..5cbf0fa 100644 --- a/system/mpd_class.php +++ b/system/mpd_class.php @@ -51,6 +51,7 @@ 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"); // Predefined MPD Response messages define("MPD_RESPONSE_ERR", "ACK"); @@ -105,7 +106,7 @@ class mpd { // Misc Other Vars var $mpd_class_version = "1.2"; - var $debugging = FALSE; // Set to TRUE to turn extended debugging on. + var $debugging = TRUE; // Set to TRUE to turn extended debugging on. var $errStr = ""; // Used for maintaining information about the last error message var $command_queue; // The list of commands for bulk command sending @@ -417,6 +418,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 @@ -814,6 +826,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 +890,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);