X-Git-Url: https://git.rvb.name/mpd-web.git/blobdiff_plain/e05325ceb8b812fc40b7c3475c59602dde9efdae..refs/heads/master:/system/mpd_class.php?ds=sidebyside

diff --git a/system/mpd_class.php b/system/mpd_class.php
index 8ffddcd..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 <file>.m3u for later retrieval. The file is saved in the MPD playlist
@@ -429,6 +442,17 @@ class mpd {
 		return $resp;
 	}
 
+	/* PLDel() 
+	 * 
+	 * Deletes playlist  <file>.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,10 +902,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'];