Загрузка плейлистов.
authorRoman Bazalevsky <rvb@rvb.name>
Wed, 28 Sep 2016 19:35:19 +0000 (22:35 +0300)
committerRoman Bazalevsky <rvb@rvb.name>
Wed, 28 Sep 2016 19:35:19 +0000 (22:35 +0300)
ajax/editplaylist.php
ajax/mpd.js
ajax/playlist.php
ajax/playlists.php [new file with mode: 0644]
ajax/trackname.php [new file with mode: 0644]
images/lists.png [new file with mode: 0644]
model/tracklist.php
system/mpd_class.php
view/default/tmpl/playlistmenu.php

index 28a6d3a6246b9e631dd2d619f28bf46e9f638133..a4764c9be23b4cb60e7e0d9d13ef4ea7cc8a4ec3 100644 (file)
@@ -26,7 +26,7 @@ $dir = $_REQUEST['dir'];
   <div id="items">
     <table>
     <tr id="items_heading">
   <div id="items">
     <table>
     <tr id="items_heading">
-       <td></td><td>Title</td><th colspan="2">Control</th>
+       <td></td><td>Название</td><th colspan="2">Управление</th>
     </tr>
     <?php
       $dirs=$mpd->GetDir($dir);
     </tr>
     <?php
       $dirs=$mpd->GetDir($dir);
index 1fe1a829a2d24d79ad1382ff509e130e12a4816e..fec89c6fcae9fcd79c28c7ccb6fad82591983baf 100644 (file)
@@ -6,7 +6,6 @@ var req = new XMLHttpRequest();
 req.onreadystatechange = function () {
   if (this.readyState != 4 || this.status != 200) return;
   document.getElementById('nowplaying_content').innerHTML=this.responseText;
 req.onreadystatechange = function () {
   if (this.readyState != 4 || this.status != 200) return;
   document.getElementById('nowplaying_content').innerHTML=this.responseText;
-  document.title='MPD Player: '+this.responseText;
 };
 
 req.open("GET", "ajax/trackinfo.php", true);
 };
 
 req.open("GET", "ajax/trackinfo.php", true);
@@ -14,6 +13,19 @@ req.send();
 
 }
 
 
 }
 
+function RefreshTitle() {
+
+var req = new XMLHttpRequest();
+
+req.onreadystatechange = function () {
+  if (this.readyState != 4 || this.status != 200) return;
+  document.title='MPD Player: '+this.responseText;
+};
+
+req.open("GET", "ajax/trackname.php", true);
+req.send();
+}
+
 function RefreshPlayerState() {
 
 var req = new XMLHttpRequest();
 function RefreshPlayerState() {
 
 var req = new XMLHttpRequest();
@@ -66,6 +78,7 @@ req.send();
 
 function RefreshPageStatus() {
 
 
 function RefreshPageStatus() {
 
+  RefreshTitle();
   RefreshNowPlaying();
   RefreshPlayerState();
   RefreshRepeatState();
   RefreshNowPlaying();
   RefreshPlayerState();
   RefreshRepeatState();
@@ -103,6 +116,20 @@ req.send();
 
 }
 
 
 }
 
+function LoadPlayList() {
+
+var req = new XMLHttpRequest();
+
+req.onreadystatechange = function () {
+  if (this.readyState != 4 || this.status != 200) return;
+  document.getElementById('playlist').innerHTML=this.responseText;
+};
+
+req.open("GET", "ajax/playlists.php", true);
+req.send();
+
+}
+
 function RefreshPageContent() {
 
   RefreshPageStatus();
 function RefreshPageContent() {
 
   RefreshPageStatus();
@@ -138,6 +165,20 @@ req.send();
 
 }
 
 
 }
 
+function PlaylistCommandRefStatus(cmd,item) {
+
+var req = new XMLHttpRequest();
+
+req.onreadystatechange = function () {
+  if (this.readyState != 4 || this.status != 200) return;
+  RefreshPageStatus();
+};
+
+req.open("GET", "ajax/playlist-command.php?item="+item+"&task="+cmd, true);
+req.send();
+
+}
+
 function PlaylistEditCommand(cmd,item) {
 
 var req = new XMLHttpRequest();
 function PlaylistEditCommand(cmd,item) {
 
 var req = new XMLHttpRequest();
@@ -152,6 +193,20 @@ req.send();
 
 }
 
 
 }
 
+function PlaylistEditCommandRefFull(cmd,item) {
+
+var req = new XMLHttpRequest();
+
+req.onreadystatechange = function () {
+  if (this.readyState != 4 || this.status != 200) return;
+  RefreshPageContent();
+};
+
+req.open("GET", "ajax/playlist-command.php?item="+item+"&task="+cmd, true);
+req.send();
+
+}
+
 
 function PlaylistItemsCommand(cmd) {
 
 
 function PlaylistItemsCommand(cmd) {
 
index 78fe8ada3ea8030668007c3351594344a4e3de28..8050bbaa7c31b316762d8a35f8c4b37a7c9af2d0 100644 (file)
@@ -5,12 +5,11 @@ include('mpd.php');
 $cur_track= $mpd->current_track_id;
 $playlist= $mpd->playlist;
 ?>
 $cur_track= $mpd->current_track_id;
 $playlist= $mpd->playlist;
 ?>
-<div id="playlist">
 <?php include("../view/default/tmpl/playlistmenu.php"); ?>
 <div id="items">
     <table>
     <tr id="items_heading">
 <?php include("../view/default/tmpl/playlistmenu.php"); ?>
 <div id="items">
     <table>
     <tr id="items_heading">
-       <td></td><td>Title</td><th colspan="4">Controls</th>
+       <td></td><td>Название</td><th colspan="4">Управление</th>
     </tr>
     <?php
       for($i=0;$i<count($playlist);$i++) {
     </tr>
     <?php
       for($i=0;$i<count($playlist);$i++) {
@@ -47,4 +46,3 @@ $playlist= $mpd->playlist;
     </table>
 </div>
 <?php include("../view/default/tmpl/playlistmenu.php"); ?>
     </table>
 </div>
 <?php include("../view/default/tmpl/playlistmenu.php"); ?>
-</div>
diff --git a/ajax/playlists.php b/ajax/playlists.php
new file mode 100644 (file)
index 0000000..eaf4415
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+
+include('mpd.php');
+?>
+
+<div id="playlist_menu">
+  <table>
+    <tr>
+      <td><span class="button" onclick="RefreshPlaylist()"><img width="20" src="images/playlist.png"></span><td>
+      <td><span class="button" onclick="confirm('Очистить список. Вы уверены?') ? PlaylistCommandRefStatus('clear') : false;" ><img width="20" src="images/removeall.png"></span><td>
+    </tr>
+  </table>
+</div>
+
+<div id="items">
+  <table>
+    <tr id="items_heading">
+      <td></td><td>Название</td>
+    </tr>
+<?
+
+$playlists = $mpd->playlists;
+
+for($i=0;$i<count($playlists);$i++) {
+
+?>
+    <tr id="item<?php if($i%2==0) { echo "Even";}else{echo "Odd";}?>">
+      <td id="track_number"><a name="<?php echo $i;?>"></a></td>
+      <td id="file"><span class="button" onclick="PlaylistEditCommandRefFull('load','<?php echo $playlists[$i]['name'];?>')"><? echo $playlists[$i]['name'];?></td></td>
+    </tr>  
+<?php
+}
+?>
+
+  </table>
+</div>
+
+<div id="playlist_menu">
+  <table>
+    <tr>
+      <td><span class="button" onclick="RefreshPlaylist()"><img width="20" src="images/playlist.png"></span><td>
+      <td><span class="button" onclick="return confirm('Очистить список. Вы уверены?') ? PlaylistCommand('clear') : false;" ><img width="20" src="images/removeall.png"></span><td>
+    </tr>
+  </table>
+</div>
diff --git a/ajax/trackname.php b/ajax/trackname.php
new file mode 100644 (file)
index 0000000..49cc01d
--- /dev/null
@@ -0,0 +1,24 @@
+<?php
+
+include('mpd.php');
+
+$cur_track = $mpd->current_track_id;
+$playlist = $mpd->playlist;
+
+$playlist_count = $mpd->playlist_count;
+
+if($cur_track !=-1) {
+
+    $trackno=$cur_track+1;
+
+    if ($playlist[$cur_track]['name']==$playlist[$cur_track]['title']) {
+        echo htmlentities(cut_file($playlist[$cur_track]['name']));
+    } else {
+        echo htmlentities($playlist[$cur_track]['title']);
+    }
+    
+} else {
+    echo "Трек не выбран";
+}
+
+?>
diff --git a/images/lists.png b/images/lists.png
new file mode 100644 (file)
index 0000000..cbae301
Binary files /dev/null and b/images/lists.png differ
index 798ca01269d12111d52c87d1506911d31f13294a..234cc9459d13b5871f03b2df32735d9ce069d0ba 100644 (file)
@@ -41,6 +41,10 @@ switch($task) {
       $mpd->PLAdd($item);
       break;
 
       $mpd->PLAdd($item);
       break;
 
+   case("load"):
+      $mpd->PLLoad($item);
+      break;
+
    case("adddir"):
       addDir($item,$mpd);
       break;
    case("adddir"):
       addDir($item,$mpd);
       break;
index 6f9f1acee54e5307d6f8da8be764c4153b5fd1e0..38769e38a5297b82e80a3824020e2c8bc6a203b2 100644 (file)
@@ -51,6 +51,7 @@ 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
 \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 +418,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
@@ -814,6 +826,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 +890,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
index cb8113a7bb3c754cdafbbce4ab2f11461736337f..7c34930071a98200f2d17f7a8ca298bdc14d11e5 100644 (file)
@@ -2,6 +2,7 @@
         <table>
                 <tr>
                        <td><span class="button" onclick="EditPlayList()"><img width="20" src="images/songs.png"></span><td>
         <table>
                 <tr>
                        <td><span class="button" onclick="EditPlayList()"><img width="20" src="images/songs.png"></span><td>
+                       <td><span class="button" onclick="LoadPlayList()"><img width="20" src="images/lists.png"></span><td>
                        <td><span class="button" onclick="return confirm('Очистить список. Вы уверены?') ? PlaylistCommand('clear') : false;" ><img width="20" src="images/removeall.png"></span><td>
                        <td><span class="button" onclick="PlaylistItemsCommand('removeselected')"><img width="20" src="images/removeselected.png"></span><td>
                </tr>
                        <td><span class="button" onclick="return confirm('Очистить список. Вы уверены?') ? PlaylistCommand('clear') : false;" ><img width="20" src="images/removeall.png"></span><td>
                        <td><span class="button" onclick="PlaylistItemsCommand('removeselected')"><img width="20" src="images/removeselected.png"></span><td>
                </tr>