Удаление списков.
[mpd-web.git] / system / mpd_class.php
index 6f9f1acee54e5307d6f8da8be764c4153b5fd1e0..d32748d69ee16278d27e806a3d9d182a6ecdeb12 100644 (file)
@@ -51,6 +51,8 @@ define("MPD_CMD_PLSWAPTRACK", "swap");
 define("MPD_CMD_PLMOVETRACK", "move");\r
 define("MPD_CMD_PASSWORD",    "password");\r
 define("MPD_CMD_TABLE",       "list");\r
 define("MPD_CMD_PLMOVETRACK", "move");\r
 define("MPD_CMD_PASSWORD",    "password");\r
 define("MPD_CMD_TABLE",       "list");\r
+define("MPD_CMD_LISTS",       "listplaylists");\r
+define("MPD_CMD_DELLIST",     "rm");\r
 \r
 // Predefined MPD Response messages\r
 define("MPD_RESPONSE_ERR", "ACK");\r
 \r
 // Predefined MPD Response messages\r
 define("MPD_RESPONSE_ERR", "ACK");\r
@@ -417,6 +419,17 @@ class mpd {
                return $resp;\r
        }\r
 \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
        /* PLSave() \r
         * \r
         * Saves the playlist to <file>.m3u for later retrieval. The file is saved in the MPD playlist\r
@@ -429,6 +442,17 @@ class mpd {
                return $resp;\r
        }\r
 \r
                return $resp;\r
        }\r
 \r
+       /* PLDel() \r
+        * \r
+        * Deletes playlist  <file>.m3u in the MPD playlist directory.\r
+        */\r
+       function PLDel($file) {\r
+               if ( $this->debugging ) echo "mpd->PLDel()\n";\r
+               $resp = $this->SendCommand(MPD_CMD_DELLIST,$file);\r
+               if ( $this->debugging ) echo "mpd->PLDel() / return\n";\r
+               return $resp;\r
+       }\r
+\r
        /* PLClear() \r
         * \r
         * Empties the playlist.\r
        /* PLClear() \r
         * \r
         * Empties the playlist.\r
@@ -814,6 +838,35 @@ class mpd {
                return $plistArray;\r
        }\r
 \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
        /* RefreshInfo() \r
         * \r
         * Updates all class properties with the values from the MPD server.\r
@@ -849,6 +902,10 @@ class mpd {
                        }\r
                }\r
 \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
         // Get the Playlist\r
                $plStr = $this->SendCommand(MPD_CMD_PLLIST);\r
                $this->playlist = $this->_parseFileListResponse($plStr);\r