From 75e2078309389c03d7baa25c2f597b4b42367894 Mon Sep 17 00:00:00 2001 From: Roman Bazalevsky Date: Thu, 29 Sep 2016 09:56:29 +0300 Subject: [PATCH 1/1] =?utf8?q?=D0=A1=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D0=B5?= =?utf8?q?=D0=BD=D0=B8=D0=B5=20=D1=81=D0=BF=D0=B8=D1=81=D0=BA=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- ajax/mpd.js | 18 + ajax/mpd.js~ | 263 +++++++ ajax/save.php | 16 + ajax/save.php~ | 16 + images/save.png | Bin 0 -> 10992 bytes model/tracklist.php~ | 104 +++ system/mpd_class.php | 2 +- system/mpd_class.php~ | 1021 +++++++++++++++++++++++++++ view/default/tmpl/playlistmenu.php | 1 + view/default/tmpl/playlistmenu.php~ | 10 + 10 files changed, 1450 insertions(+), 1 deletion(-) create mode 100644 ajax/mpd.js~ create mode 100644 ajax/save.php create mode 100644 ajax/save.php~ create mode 100644 images/save.png create mode 100644 model/tracklist.php~ create mode 100644 system/mpd_class.php~ create mode 100644 view/default/tmpl/playlistmenu.php~ diff --git a/ajax/mpd.js b/ajax/mpd.js index fec89c6..c762fe2 100644 --- a/ajax/mpd.js +++ b/ajax/mpd.js @@ -130,6 +130,24 @@ req.send(); } +function SavePlayList() { + +var name=window.prompt('Имя списка',''); + +var req = new XMLHttpRequest(); + +req.onreadystatechange = function () { + if (this.readyState != 4 || this.status != 200) return; + if (this.responseText != 'OK') { + window.alert(this.responseText); + } +}; + +req.open("GET", "ajax/save.php?item="+name, true); +req.send(); + +} + function RefreshPageContent() { RefreshPageStatus(); diff --git a/ajax/mpd.js~ b/ajax/mpd.js~ new file mode 100644 index 0000000..fec89c6 --- /dev/null +++ b/ajax/mpd.js~ @@ -0,0 +1,263 @@ + +function RefreshNowPlaying() { + +var req = new XMLHttpRequest(); + +req.onreadystatechange = function () { + if (this.readyState != 4 || this.status != 200) return; + document.getElementById('nowplaying_content').innerHTML=this.responseText; +}; + +req.open("GET", "ajax/trackinfo.php", true); +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(); + +req.onreadystatechange = function () { + if (this.readyState != 4 || this.status != 200) return; + if (this.responseText=="play") { + document.getElementById('playpausebutton').innerHTML=""; + } else { + document.getElementById('playpausebutton').innerHTML=""; + } +}; + +req.open("GET", "ajax/playerstate.php", true); +req.send(); + +} + +function RefreshRepeatState() { + +var req = new XMLHttpRequest(); + +req.onreadystatechange = function () { + if (this.readyState != 4 || this.status != 200) return; + if (this.responseText=="1") { + document.getElementById('repeatstate').innerHTML=""; + } else { + document.getElementById('repeatstate').innerHTML=""; + } +}; + +req.open("GET", "ajax/repeatstate.php", true); +req.send(); + +} + +function RefreshVolume() { + +var req = new XMLHttpRequest(); + +req.onreadystatechange = function () { + if (this.readyState != 4 || this.status != 200) return; + document.getElementById('volume_total').innerHTML="
"; +}; + +req.open("GET", "ajax/volume.php", true); +req.send(); + +} + +function RefreshPageStatus() { + + RefreshTitle(); + RefreshNowPlaying(); + RefreshPlayerState(); + RefreshRepeatState(); + RefreshVolume(); + +} + +function RefreshPlaylist() { + +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/playlist.php", true); +req.send(); + +} + +function EditPlayList(dir) { + +var req = new XMLHttpRequest(); + +req.onreadystatechange = function () { + if (this.readyState != 4 || this.status != 200) return; + document.getElementById('playlist').innerHTML=this.responseText; +}; + +if (!dir) { dir = ''; }; + +req.open("GET", "ajax/editplaylist.php?dir="+dir, true); +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(); + RefreshPlaylist(); + +} + +function Command(cmd) { + +var req = new XMLHttpRequest(); + +req.onreadystatechange = function () { + if (this.readyState != 4 || this.status != 200) return; + RefreshPageStatus(); +}; + +req.open("GET", "ajax/command.php?task="+cmd, true); +req.send(); + +} + +function PlaylistCommand(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 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(); + +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 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) { + +var req = new XMLHttpRequest(); + +var selected = [].filter.call(document.getElementsByName('itemlist[]'), function(c) { + return c.checked; +}).map(function(c) { + return c.value; +}); + +req.onreadystatechange = function () { + if (this.readyState != 4 || this.status != 200) return; + RefreshPageContent(); +}; + +params=selected.map(function(el) { + //Map each field into a name=value string, make sure to properly escape! + return 'itemlist[]=' + encodeURIComponent(el); + }).join('&'); + +req.open("POST", "ajax/playlist-command.php?task="+cmd, true); +req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); +req.send(params); + +} + +function PlaylistEditItemsCommand(cmd,dir) { + +var req = new XMLHttpRequest(); + +var selected = [].filter.call(document.getElementsByName('itemlist[]'), function(c) { + return c.checked; +}).map(function(c) { + return c.value; +}); + +params=selected.map(function(el) { + //Map each field into a name=value string, make sure to properly escape! + return 'itemlist[]=' + encodeURIComponent(el); + }).join('&'); + +req.onreadystatechange = function () { + if (this.readyState != 4 || this.status != 200) return; + RefreshPageStatus(); +}; + +req.open("POST", "ajax/playlist-command.php?dir="+dir+"&task="+cmd, true); +req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); +req.send(params); + +} + +setInterval(RefreshPageStatus, 10000); diff --git a/ajax/save.php b/ajax/save.php new file mode 100644 index 0000000..c78feb2 --- /dev/null +++ b/ajax/save.php @@ -0,0 +1,16 @@ +PLSave($item); + +if ($mpd->errStr) { + echo 'ERROR: '.$mpd->errStr; +} else { + echo 'OK'; +} + +?> diff --git a/ajax/save.php~ b/ajax/save.php~ new file mode 100644 index 0000000..5dd0518 --- /dev/null +++ b/ajax/save.php~ @@ -0,0 +1,16 @@ +PLSave($item); + +if ($mpd->errStr) { + echo 'ERROR: '.$errSTR; +} else { + echo 'OK'; +} + +?> diff --git a/images/save.png b/images/save.png new file mode 100644 index 0000000000000000000000000000000000000000..37ec0864dd8726fa9535e0a5c610ff002c955fd5 GIT binary patch literal 10992 zcmeHsRZv~e`sKmhHNg)~u!Fn1yF+l-gS!NGcXyZI9talP<=_eK76?B1-MRIjmwCAl z^DtF+@9HgIuU`A>Rozu<*B7OtB#nmr5g7mgpvlTesQtZ@{?icQ|6ci7>x%&Zk`f;c z9XB--PjY9llckNl1-YBIvjw?@myIO=;03A6(e|L?PLzCaiq?hh(M3PwZT_PBwh^I_ zUEW0XyXWG<1eZm3$+o_L66@3Ig!hbr9XY&MEM)=1b#0G>f zyB|Ckwr+i1?s+cXi#Fu_NMCL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$fd6)Tj-u`*BmBU7o)L5N%MZnnp^x*(f$}qf@bb# zyWg+IbZ3k!!U!1E(2n+BAe%N2>P4-tt8MxOV2DMYd#k_bj>TiOJpl6>!^cp@K5B0o ze+%aWcWk*F9T2EandphM1}zZl;eLlgSdx3UgD37o+pfu*fchQJToDh2heNc`3j>Is zY>0B@UEF7NXZ=;k884UiZI0i%Ct+zN?e5i0Wf(*%9V>KMA58Cj65;i|^f^%$cDYBr zOiSz*;C#kxzSsD0ZwqiTnc=V%7qyQtmp6wVy%gmeUFUYy^q9RtZHueU$>VJby13@5 zU(rt1IlG;j3pm^Jzau+ZXcf@cPH5=^1#t+7>@33ApW~Ewrd#@1$Fu6+4If9mn!dqs YR`&GJMx{gk?gfCXq>@Cvm~qJe0uGetDir($current); + for($i=0;$iPLAdd($files[$i]['name']); + } + + } + } +} + +switch($task) { + + case("remove"): + if($item != null) + $mpd->PLRemove($item); + break; + + + case("clear"): + $mpd->PLClear(); + break; + + case("playitem"): + if($item != null){ + $mpd->SkipTo($item); + } + break; + + case("addfile"): + $mpd->PLAdd($item); + break; + + case("load"): + $mpd->PLLoad($item); + break; + + case("adddir"): + addDir($item,$mpd); + break; + + + case("moveup"): + if($item !=0) { + $mpd->Move($item,$item-1); + } + break; + + case("movedown"): + if($item !=count($mpd->playlist)-1) { + $mpd->Move($item,$item+1); + } + break; + + + case("removeselected"): + $items=$_POST['itemlist']; + for($i=0;$iPLRemove($items[$i]-$i); + } + break; + + + case("addselected"): + $items=$_POST['itemlist']; + $dir=$_REQUEST['dir']; + $files = $mpd->GetDir($dir); + for($i=0;$iPLAdd($files[$items[$i]]['name']); + } + } + break; + + case("addall"): + $dir=$_REQUEST['item']; + $files = $mpd->GetDir($dir); + for($i=0;$iPLAdd($files[$i]['name']); + } + } + break; + + + +} + + +?> diff --git a/system/mpd_class.php b/system/mpd_class.php index 38769e3..5cbf0fa 100644 --- a/system/mpd_class.php +++ b/system/mpd_class.php @@ -106,7 +106,7 @@ class mpd { // Misc Other Vars var $mpd_class_version = "1.2"; - var $debugging = FALSE; // Set to TRUE to turn extended debugging on. + var $debugging = TRUE; // Set to TRUE to turn extended debugging on. var $errStr = ""; // Used for maintaining information about the last error message var $command_queue; // The list of commands for bulk command sending diff --git a/system/mpd_class.php~ b/system/mpd_class.php~ new file mode 100644 index 0000000..5cbf0fa --- /dev/null +++ b/system/mpd_class.php~ @@ -0,0 +1,1021 @@ +host = $srv; + $this->port = $port; + $this->password = $pwd; + + $resp = $this->Connect(); + if ( is_null($resp) ) { + $this->errStr = "Could not connect"; + return; + } else { + list ( $this->mpd_version ) = sscanf($resp, MPD_RESPONSE_OK . " MPD %s\n"); + if ( ! is_null($pwd) ) { + if ( is_null($this->SendCommand(MPD_CMD_PASSWORD,$pwd)) ) { + $this->connected = FALSE; + return; // bad password or command + } + if ( is_null($this->RefreshInfo()) ) { // no read access -- might as well be disconnected! + $this->connected = FALSE; + $this->errStr = "Password supplied does not have read access"; + return; + } + } else { + if ( is_null($this->RefreshInfo()) ) { // no read access -- might as well be disconnected! + $this->connected = FALSE; + $this->errStr = "Password required to access server"; + return; + } + } + } + } + + /* Connect() + * + * Connects to the MPD server. + * + * NOTE: This is called automatically upon object instantiation; you should not need to call this directly. + */ + function Connect() { + if ( $this->debugging ) echo "mpd->Connect() / host: ".$this->host.", port: ".$this->port."\n"; + $this->mpd_sock = fsockopen($this->host,$this->port,$errNo,$errStr,10); + if (!$this->mpd_sock) { + $this->errStr = "Socket Error: $errStr ($errNo)"; + return NULL; + } else { + while(!feof($this->mpd_sock)) { + $response = fgets($this->mpd_sock,1024); + if (strncmp(MPD_RESPONSE_OK,$response,strlen(MPD_RESPONSE_OK)) == 0) { + $this->connected = TRUE; + return $response; + break; + } + if (strncmp(MPD_RESPONSE_ERR,$response,strlen(MPD_RESPONSE_ERR)) == 0) { + $this->errStr = "Server responded with: $response"; + return NULL; + } + } + // Generic response + $this->errStr = "Connection not available"; + return NULL; + } + } + + /* SendCommand() + * + * Sends a generic command to the MPD server. Several command constants are pre-defined for + * use (see MPD_CMD_* constant definitions above). + */ + function SendCommand($cmdStr,$arg1 = "",$arg2 = "") { + if ( $this->debugging ) echo "mpd->SendCommand() / cmd: ".$cmdStr.", args: ".$arg1." ".$arg2."\n"; + + if ( ! $this->connected ) { + echo "mpd->SendCommand() / Error: Not connected\n"; + } else { + // Clear out the error String + $this->errStr = ""; + $respStr = ""; + + // Check the command compatibility: + if ( ! $this->_checkCompatibility($cmdStr) ) { + echo "Not compatible command!"; + return NULL; + } + + if (strlen($arg1) > 0) $cmdStr .= " \"$arg1\""; + + if (strlen($arg2) > 0) $cmdStr .= " \"$arg2\""; + if ( $this->debugging ) echo "mpd-> ".$cmdStr."\n"; + fputs($this->mpd_sock,"$cmdStr\n"); + while(!feof($this->mpd_sock)) { + $response = fgets($this->mpd_sock,1024); + if ( $this->debugging ) echo "mpd.response-> ".$response."\n"; + + // An OK signals the end of transmission -- we'll ignore it + if (strncmp(MPD_RESPONSE_OK,$response,strlen(MPD_RESPONSE_OK)) == 0) { + break; + } + + // An ERR signals the end of transmission with an error! Let's grab the single-line message. + if (strncmp(MPD_RESPONSE_ERR,$response,strlen(MPD_RESPONSE_ERR)) == 0) { + list ( $junk, $errTmp ) = explode(MPD_RESPONSE_ERR . " ",$response ); + $this->errStr = strtok($errTmp,"\n"); + } + + if ( strlen($this->errStr) > 0 ) { + return NULL; + } + + // Build the response string + $respStr .= $response; + } + if ( $this->debugging ) echo "mpd->SendCommand() / response: '".$respStr."'\n"; + } + return $respStr; + } + + /* QueueCommand() + * + * Queues a generic command for later sending to the MPD server. The CommandQueue can hold + * as many commands as needed, and are sent all at once, in the order they are queued, using + * the SendCommandQueue() method. The syntax for queueing commands is identical to SendCommand(). + */ + function QueueCommand($cmdStr,$arg1 = "",$arg2 = "") { + if ( $this->debugging ) echo "mpd->QueueCommand() / cmd: ".$cmdStr.", args: ".$arg1." ".$arg2."\n"; + if ( ! $this->connected ) { + echo "mpd->QueueCommand() / Error: Not connected\n"; + return NULL; + } else { + if ( strlen($this->command_queue) == 0 ) { + $this->command_queue = MPD_CMD_START_BULK . "\n"; + } + if (strlen($arg1) > 0) $cmdStr .= " \"$arg1\""; + if (strlen($arg2) > 0) $cmdStr .= " \"$arg2\""; + + $this->command_queue .= $cmdStr ."\n"; + + if ( $this->debugging ) echo "mpd->QueueCommand() / return\n"; + } + return TRUE; + } + + /* SendCommandQueue() + * + * Sends all commands in the Command Queue to the MPD server. See also QueueCommand(). + */ + function SendCommandQueue() { + if ( $this->debugging ) echo "mpd->SendCommandQueue()\n"; + if ( ! $this->connected ) { + echo "mpd->SendCommandQueue() / Error: Not connected\n"; + return NULL; + } else { + $this->command_queue .= MPD_CMD_END_BULK . "\n"; + if ( is_null($respStr = $this->SendCommand($this->command_queue)) ) { + return NULL; + } else { + $this->command_queue = NULL; + if ( $this->debugging ) echo "mpd->SendCommandQueue() / response: '".$respStr."'\n"; + } + } + return $respStr; + } + + /* AdjustVolume() + * + * Adjusts the mixer volume on the MPD by , which can be a positive (volume increase), + * or negative (volume decrease) value. + */ + function AdjustVolume($modifier) { + if ( $this->debugging ) echo "mpd->AdjustVolume()\n"; + if ( ! is_numeric($modifier) ) { + $this->errStr = "AdjustVolume() : argument 1 must be a numeric value"; + return NULL; + } + + $this->RefreshInfo(); + $newVol = $this->volume + $modifier; + $ret = $this->SetVolume($newVol); + + if ( $this->debugging ) echo "mpd->AdjustVolume() / return\n"; + return $ret; + } + + /* SetVolume() + * + * Sets the mixer volume to , which should be between 1 - 100. + */ + function SetVolume($newVol) { + if ( $this->debugging ) echo "mpd->SetVolume()\n"; + if ( ! is_numeric($newVol) ) { + $this->errStr = "SetVolume() : argument 1 must be a numeric value"; + return NULL; + } + + // Forcibly prevent out of range errors + if ( $newVol < 0 ) $newVol = 0; + if ( $newVol > 100 ) $newVol = 100; + + // If we're not compatible with SETVOL, we'll try adjusting using VOLUME + if ( $this->_checkCompatibility(MPD_CMD_SETVOL) ) { + if ( ! is_null($ret = $this->SendCommand(MPD_CMD_SETVOL,$newVol))) $this->volume = $newVol; + } else { + $this->RefreshInfo(); // Get the latest volume + if ( is_null($this->volume) ) { + return NULL; + } else { + $modifier = ( $newVol - $this->volume ); + if ( ! is_null($ret = $this->SendCommand(MPD_CMD_VOLUME,$modifier))) $this->volume = $newVol; + } + } + + if ( $this->debugging ) echo "mpd->SetVolume() / return\n"; + return $ret; + } + + /* GetDir() + * + * Retrieves a database directory listing of the directory and places the results into + * a multidimensional array. If no directory is specified, the directory listing is at the + * base of the MPD music path. + */ + function GetDir($dir = "") { + if ( $this->debugging ) echo "mpd->GetDir()\n"; + $resp = $this->SendCommand(MPD_CMD_LSDIR,$dir); + $dirlist = $this->_parseFileListResponse($resp); + if ( $this->debugging ) echo "mpd->GetDir() / return ".print_r($dirlist)."\n"; + return $dirlist; + } + + /* PLAdd() + * + * Adds each track listed in a single-dimensional , which contains filenames + * of tracks to add, to the end of the playlist. This is used to add many, many tracks to + * the playlist in one swoop. + */ + function PLAddBulk($trackArray) { + if ( $this->debugging ) echo "mpd->PLAddBulk()\n"; + $num_files = count($trackArray); + for ( $i = 0; $i < $num_files; $i++ ) { + $this->QueueCommand(MPD_CMD_PLADD,$trackArray[$i]); + } + $resp = $this->SendCommandQueue(); + $this->RefreshInfo(); + if ( $this->debugging ) echo "mpd->PLAddBulk() / return\n"; + return $resp; + } + + /* PLAdd() + * + * Adds the file to the end of the playlist. must be a track in the MPD database. + */ + function PLAdd($fileName) { + if ( $this->debugging ) echo "mpd->PLAdd()\n"; + if ( ! is_null($resp = $this->SendCommand(MPD_CMD_PLADD,$fileName))) $this->RefreshInfo(); + if ( $this->debugging ) echo "mpd->PLAdd() / return\n"; + return $resp; + } + + /* PLMoveTrack() + * + * Moves track number to position in the playlist. This is used to reorder + * the songs in the playlist. + */ + function PLMoveTrack($origPos, $newPos) { + if ( $this->debugging ) echo "mpd->PLMoveTrack()\n"; + if ( ! is_numeric($origPos) ) { + $this->errStr = "PLMoveTrack(): argument 1 must be numeric"; + return NULL; + } + if ( $origPos < 0 or $origPos > $this->playlist_count ) { + $this->errStr = "PLMoveTrack(): argument 1 out of range"; + return NULL; + } + if ( $newPos < 0 ) $newPos = 0; + if ( $newPos > $this->playlist_count ) $newPos = $this->playlist_count; + + if ( ! is_null($resp = $this->SendCommand(MPD_CMD_PLMOVETRACK,$origPos,$newPos))) $this->RefreshInfo(); + if ( $this->debugging ) echo "mpd->PLMoveTrack() / return\n"; + return $resp; + } + + /* PLShuffle() + * + * Randomly reorders the songs in the playlist. + */ + function PLShuffle() { + if ( $this->debugging ) echo "mpd->PLShuffle()\n"; + if ( ! is_null($resp = $this->SendCommand(MPD_CMD_PLSHUFFLE))) $this->RefreshInfo(); + if ( $this->debugging ) echo "mpd->PLShuffle() / return\n"; + return $resp; + } + + /* PLLoad() + * + * Retrieves the playlist from .m3u and loads it into the current playlist. + */ + function PLLoad($file) { + if ( $this->debugging ) echo "mpd->PLLoad()\n"; + if ( ! is_null($resp = $this->SendCommand(MPD_CMD_PLLOAD,$file))) $this->RefreshInfo(); + if ( $this->debugging ) echo "mpd->PLLoad() / return\n"; + 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 + * directory. + */ + function PLSave($file) { + if ( $this->debugging ) echo "mpd->PLSave()\n"; + $resp = $this->SendCommand(MPD_CMD_PLSAVE,$file); + if ( $this->debugging ) echo "mpd->PLSave() / return\n"; + return $resp; + } + + /* PLClear() + * + * Empties the playlist. + */ + function PLClear() { + if ( $this->debugging ) echo "mpd->PLClear()\n"; + if ( ! is_null($resp = $this->SendCommand(MPD_CMD_PLCLEAR))) $this->RefreshInfo(); + if ( $this->debugging ) echo "mpd->PLClear() / return\n"; + return $resp; + } + + + /* PLMove() + * + * Move song from pos to the other + */ + function Move ($from,$to) { + if ( ! is_null($resp = $this->SendCommand(MPD_CMD_PLMOVETRACK,$from,$to))) $this->RefreshInfo(); + //die(print_r($resp)); + + } + + + /* PLRemove() + * + * Removes track from the playlist. + */ + function PLRemove($id) { + if ( $this->debugging ) echo "mpd->PLRemove()\n"; + if ( ! is_numeric($id) ) { + $this->errStr = "PLRemove() : argument 1 must be a numeric value"; + return NULL; + } + if ( ! is_null($resp = $this->SendCommand(MPD_CMD_PLREMOVE,$id))) $this->RefreshInfo(); + if ( $this->debugging ) echo "mpd->PLRemove() / return\n"; + return $resp; + } + + /* SetRepeat() + * + * Enables 'loop' mode -- tells MPD continually loop the playlist. The parameter + * is either 1 (on) or 0 (off). + */ + function SetRepeat($repVal) { + if ( $this->debugging ) echo "mpd->SetRepeat()\n"; + $rpt = $this->SendCommand(MPD_CMD_REPEAT,$repVal); + $this->repeat = $repVal; + if ( $this->debugging ) echo "mpd->SetRepeat() / return\n"; + return $rpt; + } + + /* SetRandom() + * + * Enables 'randomize' mode -- tells MPD to play songs in the playlist in random order. The + * parameter is either 1 (on) or 0 (off). + */ + function SetRandom($rndVal) { + if ( $this->debugging ) echo "mpd->SetRandom()\n"; + $resp = $this->SendCommand(MPD_CMD_RANDOM,$rndVal); + $this->random = $rndVal; + if ( $this->debugging ) echo "mpd->SetRandom() / return\n"; + return $resp; + } + + /* Shutdown() + * + * Shuts down the MPD server (aka sends the KILL command). This closes the current connection, + * and prevents future communication with the server. + */ + function Shutdown() { + if ( $this->debugging ) echo "mpd->Shutdown()\n"; + $resp = $this->SendCommand(MPD_CMD_SHUTDOWN); + + $this->connected = FALSE; + unset($this->mpd_version); + unset($this->errStr); + unset($this->mpd_sock); + + if ( $this->debugging ) echo "mpd->Shutdown() / return\n"; + return $resp; + } + + /* DBRefresh() + * + * Tells MPD to rescan the music directory for new tracks, and to refresh the Database. Tracks + * cannot be played unless they are in the MPD database. + */ + function DBRefresh() { + if ( $this->debugging ) echo "mpd->DBRefresh()\n"; + $resp = $this->SendCommand(MPD_CMD_REFRESH); + + // Update local variables + $this->RefreshInfo(); + + if ( $this->debugging ) echo "mpd->DBRefresh() / return\n"; + return $resp; + } + + /* Play() + * + * Begins playing the songs in the MPD playlist. + */ + function Play() { + if ( $this->debugging ) echo "mpd->Play()\n"; + if ( ! is_null($rpt = $this->SendCommand(MPD_CMD_PLAY) )) $this->RefreshInfo(); + if ( $this->debugging ) echo "mpd->Play() / return\n"; + return $rpt; + } + + /* Stop() + * + * Stops playing the MPD. + */ + function Stop() { + if ( $this->debugging ) echo "mpd->Stop()\n"; + if ( ! is_null($rpt = $this->SendCommand(MPD_CMD_STOP) )) $this->RefreshInfo(); + if ( $this->debugging ) echo "mpd->Stop() / return\n"; + return $rpt; + } + + /* Pause() + * + * Toggles pausing on the MPD. Calling it once will pause the player, calling it again + * will unpause. + */ + function Pause() { + if ( $this->debugging ) echo "mpd->Pause()\n"; + if ( ! is_null($rpt = $this->SendCommand(MPD_CMD_PAUSE) )) $this->RefreshInfo(); + if ( $this->debugging ) echo "mpd->Pause() / return\n"; + return $rpt; + } + + /* SeekTo() + * + * Skips directly to the song in the MPD playlist. + */ + function SkipTo($idx) { + if ( $this->debugging ) echo "mpd->SkipTo()\n"; + if ( ! is_numeric($idx) ) { + $this->errStr = "SkipTo() : argument 1 must be a numeric value"; + return NULL; + } + if ( ! is_null($rpt = $this->SendCommand(MPD_CMD_PLAY,$idx))) $this->RefreshInfo(); + if ( $this->debugging ) echo "mpd->SkipTo() / return\n"; + return $idx; + } + + /* SeekTo() + * + * Skips directly to a given position within a track in the MPD playlist. The argument, + * given in seconds, is the track position to locate. The argument, if supplied is + * the track number in the playlist. If is not specified, the current track is assumed. + */ + function SeekTo($pos, $track = -1) { + if ( $this->debugging ) echo "mpd->SeekTo()\n"; + if ( ! is_numeric($pos) ) { + $this->errStr = "SeekTo() : argument 1 must be a numeric value"; + return NULL; + } + if ( ! is_numeric($track) ) { + $this->errStr = "SeekTo() : argument 2 must be a numeric value"; + return NULL; + } + if ( $track == -1 ) { + $track = $this->current_track_id; + } + + if ( ! is_null($rpt = $this->SendCommand(MPD_CMD_SEEK,$track,$pos))) $this->RefreshInfo(); + if ( $this->debugging ) echo "mpd->SeekTo() / return\n"; + return $pos; + } + + /* Next() + * + * Skips to the next song in the MPD playlist. If not playing, returns an error. + */ + function Next() { + if ( $this->debugging ) echo "mpd->Next()\n"; + if ( ! is_null($rpt = $this->SendCommand(MPD_CMD_NEXT))) $this->RefreshInfo(); + if ( $this->debugging ) echo "mpd->Next() / return\n"; + return $rpt; + } + + /* Previous() + * + * Skips to the previous song in the MPD playlist. If not playing, returns an error. + */ + function Previous() { + if ( $this->debugging ) echo "mpd->Previous()\n"; + if ( ! is_null($rpt = $this->SendCommand(MPD_CMD_PREV))) $this->RefreshInfo(); + if ( $this->debugging ) echo "mpd->Previous() / return\n"; + return $rpt; + } + + /* Search() + * + * Searches the MPD database. The search should be one of the following: + * MPD_SEARCH_ARTIST, MPD_SEARCH_TITLE, MPD_SEARCH_ALBUM + * The search is a case-insensitive locator string. Anything that contains + * will be returned in the results. + */ + function Search($type,$string) { + if ( $this->debugging ) echo "mpd->Search()\n"; + if ( $type != MPD_SEARCH_ARTIST and + $type != MPD_SEARCH_ALBUM and + $type != MPD_SEARCH_TITLE ) { + $this->errStr = "mpd->Search(): invalid search type"; + return NULL; + } else { + if ( is_null($resp = $this->SendCommand(MPD_CMD_SEARCH,$type,$string))) return NULL; + $searchlist = $this->_parseFileListResponse($resp); + } + if ( $this->debugging ) echo "mpd->Search() / return ".print_r($searchlist)."\n"; + return $searchlist; + } + + /* Find() + * + * Find() looks for exact matches in the MPD database. The find should be one of + * the following: + * MPD_SEARCH_ARTIST, MPD_SEARCH_TITLE, MPD_SEARCH_ALBUM + * The find is a case-insensitive locator string. Anything that exactly matches + * will be returned in the results. + */ + function Find($type,$string) { + if ( $this->debugging ) echo "mpd->Find()\n"; + if ( $type != MPD_SEARCH_ARTIST and + $type != MPD_SEARCH_ALBUM and + $type != MPD_SEARCH_TITLE ) { + $this->errStr = "mpd->Find(): invalid find type"; + return NULL; + } else { + if ( is_null($resp = $this->SendCommand(MPD_CMD_FIND,$type,$string))) return NULL; + $searchlist = $this->_parseFileListResponse($resp); + } + if ( $this->debugging ) echo "mpd->Find() / return ".print_r($searchlist)."\n"; + return $searchlist; + } + + /* Disconnect() + * + * Closes the connection to the MPD server. + */ + function Disconnect() { + if ( $this->debugging ) echo "mpd->Disconnect()\n"; + fclose($this->mpd_sock); + + $this->connected = FALSE; + unset($this->mpd_version); + unset($this->errStr); + unset($this->mpd_sock); + } + + /* GetArtists() + * + * Returns the list of artists in the database in an associative array. + */ + function GetArtists() { + if ( $this->debugging ) echo "mpd->GetArtists()\n"; + if ( is_null($resp = $this->SendCommand(MPD_CMD_TABLE, MPD_TBL_ARTIST))) return NULL; + $arArray = array(); + + $arLine = strtok($resp,"\n"); + $arName = ""; + $arCounter = -1; + while ( $arLine ) { + list ( $element, $value ) = explode(": ",$arLine); + if ( $element == "Artist" ) { + $arCounter++; + $arName = $value; + $arArray[$arCounter] = $arName; + } + + $arLine = strtok("\n"); + } + if ( $this->debugging ) echo "mpd->GetArtists()\n"; + return $arArray; + } + + /* GetAlbums() + * + * Returns the list of albums in the database in an associative array. Optional parameter + * is an artist Name which will list all albums by a particular artist. + */ + function GetAlbums( $ar = NULL) { + if ( $this->debugging ) echo "mpd->GetAlbums()\n"; + if ( is_null($resp = $this->SendCommand(MPD_CMD_TABLE, MPD_TBL_ALBUM, $ar ))) return NULL; + $alArray = array(); + + $alLine = strtok($resp,"\n"); + $alName = ""; + $alCounter = -1; + while ( $alLine ) { + list ( $element, $value ) = explode(": ",$alLine); + if ( $element == "Album" ) { + $alCounter++; + $alName = $value; + $alArray[$alCounter] = $alName; + } + + $alLine = strtok("\n"); + } + if ( $this->debugging ) echo "mpd->GetAlbums()\n"; + return $alArray; + } + + //*******************************************************************************// + //***************************** INTERNAL FUNCTIONS ******************************// + //*******************************************************************************// + + /* _computeVersionValue() + * + * Computes a compatibility value from a version string + * + */ + function _computeVersionValue($verStr) { + list ($ver_maj, $ver_min, $ver_rel ) = explode("\.",$verStr); + return ( 100 * $ver_maj ) + ( 10 * $ver_min ) + ( $ver_rel ); + } + + /* _checkCompatibility() + * + * Check MPD command compatibility against our internal table. If there is no version + * listed in the table, allow it by default. + */ + function _checkCompatibility($cmd) { + // Check minimum compatibility + $req_ver_low = $this->COMPATIBILITY_MIN_TBL[$cmd]; + $req_ver_hi = $this->COMPATIBILITY_MAX_TBL[$cmd]; + + $mpd_ver = $this->_computeVersionValue($this->mpd_version); + + if ( $req_ver_low ) { + $req_ver = $this->_computeVersionValue($req_ver_low); + + if ( $mpd_ver < $req_ver ) { + $this->errStr = "Command '$cmd' is not compatible with this version of MPD, version ".$req_ver_low." required"; + return FALSE; + } + } + + // Check maxmum compatibility -- this will check for deprecations + if ( $req_ver_hi ) { + $req_ver = $this->_computeVersionValue($req_ver_hi); + + if ( $mpd_ver > $req_ver ) { + $this->errStr = "Command '$cmd' has been deprecated in this version of MPD."; + return FALSE; + } + } + + return TRUE; + } + + /* _parseFileListResponse() + * + * Builds a multidimensional array with MPD response lists. + * + * NOTE: This function is used internally within the class. It should not be used. + */ + function _parseFileListResponse($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 == "file" || $element=="directory") { + $plCounter++; + $plistArray[$plCounter]['name']=$value; + $plistArray[$plCounter]['type']=$element; + $plistArray[$plCounter]['title']=$value; + } + if($element == "Name") { + $plistArray[$plCounter]['title']=$value; + } + $plistLine = strtok("\n"); + } + } + 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. + * + * NOTE: This function is automatically called upon Connect() as of v1.1. + */ + function RefreshInfo() { + // Get the Server Statistics + $statStr = $this->SendCommand(MPD_CMD_STATISTICS); + if ( !$statStr ) { + return NULL; + } else { + $stats = array(); + $statLine = strtok($statStr,"\n"); + while ( $statLine ) { + list ( $element, $value ) = explode(": ",$statLine); + $stats[$element] = $value; + $statLine = strtok("\n"); + } + } + + // Get the Server Status + $statusStr = $this->SendCommand(MPD_CMD_STATUS); + if ( ! $statusStr ) { + return NULL; + } else { + $status = array(); + $statusLine = strtok($statusStr,"\n"); + while ( $statusLine ) { + list ( $element, $value ) = explode(": ",$statusLine); + $status[$element] = $value; + $statusLine = strtok("\n"); + } + } + + // 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); + + // Set Misc Other Variables + $this->state = $status['state']; + if ( ($this->state == MPD_STATE_PLAYING) || ($this->state == MPD_STATE_PAUSED) ) { + $this->current_track_id = $status['song']; + list ($this->current_track_position, $this->current_track_length ) = explode(":",$status['time']); + } else { + $this->current_track_id = -1; + $this->current_track_position = -1; + $this->current_track_length = -1; + } + + $this->repeat = $status['repeat']; + $this->random = $status['random']; + + $this->db_last_refreshed = $stats['db_update']; + + $this->volume = $status['volume']; + $this->uptime = $stats['uptime']; + $this->playtime = $stats['playtime']; + $this->num_songs_played = $stats['songs_played']; + $this->num_artists = $stats['num_artists']; + $this->num_songs = $stats['num_songs']; + $this->num_albums = $stats['num_albums']; + return TRUE; + } + + /* ------------------ DEPRECATED METHODS -------------------*/ + /* GetStatistics() + * + * Retrieves the 'statistics' variables from the server and tosses them into an array. + * + * NOTE: This function really should not be used. Instead, use $this->[variable]. The function + * will most likely be deprecated in future releases. + */ + function GetStatistics() { + if ( $this->debugging ) echo "mpd->GetStatistics()\n"; + $stats = $this->SendCommand(MPD_CMD_STATISTICS); + if ( !$stats ) { + return NULL; + } else { + $statsArray = array(); + $statsLine = strtok($stats,"\n"); + while ( $statsLine ) { + list ( $element, $value ) = explode(": ",$statsLine); + $statsArray[$element] = $value; + $statsLine = strtok("\n"); + } + } + if ( $this->debugging ) echo "mpd->GetStatistics() / return: " . print_r($statsArray) ."\n"; + return $statsArray; + } + + /* GetStatus() + * + * Retrieves the 'status' variables from the server and tosses them into an array. + * + * NOTE: This function really should not be used. Instead, use $this->[variable]. The function + * will most likely be deprecated in future releases. + */ + function GetStatus() { + if ( $this->debugging ) echo "mpd->GetStatus()\n"; + $status = $this->SendCommand(MPD_CMD_STATUS); + if ( ! $status ) { + return NULL; + } else { + $statusArray = array(); + $statusLine = strtok($status,"\n"); + while ( $statusLine ) { + list ( $element, $value ) = explode(": ",$statusLine); + $statusArray[$element] = $value; + $statusLine = strtok("\n"); + } + } + if ( $this->debugging ) echo "mpd->GetStatus() / return: " . print_r($statusArray) ."\n"; + return $statusArray; + } + + /* GetVolume() + * + * Retrieves the mixer volume from the server. + * + * NOTE: This function really should not be used. Instead, use $this->volume. The function + * will most likely be deprecated in future releases. + */ + function GetVolume() { + if ( $this->debugging ) echo "mpd->GetVolume()\n"; + $volLine = $this->SendCommand(MPD_CMD_STATUS); + if ( ! $volLine ) { + return NULL; + } else { + list ($vol) = sscanf($volLine,"volume: %d"); + } + if ( $this->debugging ) echo "mpd->GetVolume() / return: $vol\n"; + return $vol; + } + + /* GetPlaylist() + * + * Retrieves the playlist from the server and tosses it into a multidimensional array. + * + * NOTE: This function really should not be used. Instead, use $this->playlist. The function + * will most likely be deprecated in future releases. + */ + function GetPlaylist() { + if ( $this->debugging ) echo "mpd->GetPlaylist()\n"; + $resp = $this->SendCommand(MPD_CMD_PLLIST); + $playlist = $this->_parseFileListResponse($resp); + if ( $this->debugging ) echo "mpd->GetPlaylist() / return ".print_r($playlist)."\n"; + return $playlist; + } + + /* ----------------- Command compatibility tables --------------------- */ + var $COMPATIBILITY_MIN_TBL = array( + ); + + var $COMPATIBILITY_MAX_TBL = array( + ); + +} // ---------------------------- end of class ------------------------------ +?> diff --git a/view/default/tmpl/playlistmenu.php b/view/default/tmpl/playlistmenu.php index 7c34930..45c8857 100644 --- a/view/default/tmpl/playlistmenu.php +++ b/view/default/tmpl/playlistmenu.php @@ -3,6 +3,7 @@ + diff --git a/view/default/tmpl/playlistmenu.php~ b/view/default/tmpl/playlistmenu.php~ new file mode 100644 index 0000000..7c34930 --- /dev/null +++ b/view/default/tmpl/playlistmenu.php~ @@ -0,0 +1,10 @@ +
+ + + +
+ + + +
+
-- 2.34.1