X-Git-Url: https://git.rvb.name/mpd-web.git/blobdiff_plain/e05325ceb8b812fc40b7c3475c59602dde9efdae..585224f5dbe2565ed04c97b054e8d8354c21dc5e:/system/mpd_class.php diff --git a/system/mpd_class.php b/system/mpd_class.php index 8ffddcd..38769e3 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"); @@ -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'];