define("MPD_CMD_PLMOVETRACK", "move");\r
define("MPD_CMD_PASSWORD", "password");\r
define("MPD_CMD_TABLE", "list");\r
+define("MPD_CMD_LISTS", "listplaylists");\r
\r
// Predefined MPD Response messages\r
define("MPD_RESPONSE_ERR", "ACK");\r
// Misc Other Vars \r
var $mpd_class_version = "1.2";\r
\r
- var $debugging = FALSE; // Set to TRUE to turn extended debugging on.\r
+ var $debugging = TRUE; // Set to TRUE to turn extended debugging on.\r
var $errStr = ""; // Used for maintaining information about the last error message\r
\r
var $command_queue; // The list of commands for bulk command sending\r
return $resp;\r
}\r
\r
+ /* PLList() \r
+ * \r
+ * Retrieves the playlists info. \r
+ */\r
+ function PLList() {\r
+ if ( $this->debugging ) echo "mpd->PLList()\n";\r
+ if ( ! is_null($resp = $this->SendCommand(MPD_CMD_LISTS))) $this->RefreshInfo();\r
+ if ( $this->debugging ) echo "mpd->PLList() / return\n";\r
+ return $resp;\r
+ }\r
+\r
/* PLSave() \r
* \r
* Saves the playlist to <file>.m3u for later retrieval. The file is saved in the MPD playlist\r
return $plistArray;\r
}\r
\r
+ /* _parsePlayListsResponse() \r
+ * \r
+ * Builds a multidimensional array with MPD response lists.\r
+ *\r
+ * NOTE: This function is used internally within the class. It should not be used.\r
+ */\r
+ function _parsePlayListsResponse($resp) {\r
+ if ( is_null($resp) ) {\r
+ return NULL;\r
+ } else {\r
+ $plistArray = array();\r
+ $plistLine = strtok($resp,"\n");\r
+ $plistFile = "";\r
+ $plCounter = -1;\r
+ while ( $plistLine ) {\r
+ list ( $element, $value ) = explode(": ",$plistLine);\r
+ if($element == "playlist") {\r
+ $plCounter++;\r
+ $plistArray[$plCounter]['name']=$value;\r
+ }\r
+ if($element == "Last-Modified") {\r
+ $plistArray[$plCounter]['timestamp']=$value;\r
+ }\r
+ $plistLine = strtok("\n");\r
+ } \r
+ }\r
+ return $plistArray;\r
+ }\r
+\r
/* RefreshInfo() \r
* \r
* Updates all class properties with the values from the MPD server.\r
}\r
}\r
\r
+ // Get list of lists\r
+ $plStr = $this->SendCommand(MPD_CMD_LISTS);\r
+ $this->playlists = $this->_parsePlayListsResponse($plStr);\r
+\r
// Get the Playlist\r
$plStr = $this->SendCommand(MPD_CMD_PLLIST);\r
$this->playlist = $this->_parseFileListResponse($plStr);\r
- $this->playlist_count = count($this->playlist);\r
+ $this->playlist_count = count($this->playlist);\r
\r
// Set Misc Other Variables\r
$this->state = $status['state'];\r