From: Roman Bazalevsky Date: Wed, 28 Sep 2016 19:35:19 +0000 (+0300) Subject: Загрузка плейлистов. X-Git-Url: https://git.rvb.name/mpd-web.git/commitdiff_plain/585224f5dbe2565ed04c97b054e8d8354c21dc5e?hp=1f9cd46f82e950d6849000bb2cd64b51cfa99ffb Загрузка плейлистов. --- diff --git a/ajax/editplaylist.php b/ajax/editplaylist.php index 28a6d3a..a4764c9 100644 --- a/ajax/editplaylist.php +++ b/ajax/editplaylist.php @@ -26,7 +26,7 @@ $dir = $_REQUEST['dir'];
- + GetDir($dir); diff --git a/ajax/mpd.js b/ajax/mpd.js index 1fe1a82..fec89c6 100644 --- a/ajax/mpd.js +++ b/ajax/mpd.js @@ -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; - document.title='MPD Player: '+this.responseText; }; 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(); @@ -66,6 +78,7 @@ req.send(); function RefreshPageStatus() { + RefreshTitle(); 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(); @@ -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(); @@ -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) { diff --git a/ajax/playlist.php b/ajax/playlist.php index 78fe8ad..8050bba 100644 --- a/ajax/playlist.php +++ b/ajax/playlist.php @@ -5,12 +5,11 @@ include('mpd.php'); $cur_track= $mpd->current_track_id; $playlist= $mpd->playlist; ?> -
TitleControlНазваниеУправление
- + playlist;
TitleControlsНазваниеУправление
- diff --git a/ajax/playlists.php b/ajax/playlists.php new file mode 100644 index 0000000..eaf4415 --- /dev/null +++ b/ajax/playlists.php @@ -0,0 +1,45 @@ + + +
+ + + +
+ +
+
+ +
+ + + + +playlists; + +for($i=0;$i + "> + + + + + +
Название
+
+ +
+ + + +
+ +
+
diff --git a/ajax/trackname.php b/ajax/trackname.php new file mode 100644 index 0000000..49cc01d --- /dev/null +++ b/ajax/trackname.php @@ -0,0 +1,24 @@ +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 index 0000000..cbae301 Binary files /dev/null and b/images/lists.png differ diff --git a/model/tracklist.php b/model/tracklist.php index 798ca01..234cc94 100644 --- a/model/tracklist.php +++ b/model/tracklist.php @@ -41,6 +41,10 @@ switch($task) { $mpd->PLAdd($item); break; + case("load"): + $mpd->PLLoad($item); + break; + case("adddir"): addDir($item,$mpd); break; diff --git a/system/mpd_class.php b/system/mpd_class.php index 6f9f1ac..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,6 +890,10 @@ 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); diff --git a/view/default/tmpl/playlistmenu.php b/view/default/tmpl/playlistmenu.php index cb8113a..7c34930 100644 --- a/view/default/tmpl/playlistmenu.php +++ b/view/default/tmpl/playlistmenu.php @@ -2,6 +2,7 @@
+