X-Git-Url: https://git.rvb.name/mpd-web.git/blobdiff_plain/e05325ceb8b812fc40b7c3475c59602dde9efdae..75e2078309389c03d7baa25c2f597b4b42367894:/system/mpd_class.php?ds=sidebyside diff --git a/system/mpd_class.php b/system/mpd_class.php index 8ffddcd..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,10 +890,14 @@ 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); - $this->playlist_count = count($this->playlist); + $this->playlist_count = count($this->playlist); // Set Misc Other Variables $this->state = $status['state'];