diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2007-09-20 07:39:45 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2007-09-20 07:39:45 +0000 |
commit | 1dfdf2afab8da95da8c814e3838b3393d88ae53c (patch) | |
tree | f97be5925ed2dbef028d0902861771ea0a3ec473 /modules | |
parent | 649c44446a2368ac004ffa5778704f7213cf54ad (diff) | |
download | ampache-1dfdf2afab8da95da8c814e3838b3393d88ae53c.tar.gz ampache-1dfdf2afab8da95da8c814e3838b3393d88ae53c.tar.bz2 ampache-1dfdf2afab8da95da8c814e3838b3393d88ae53c.zip |
made localplay technically work, lots of work to still do
Diffstat (limited to 'modules')
-rw-r--r-- | modules/localplay/mpd.controller.php | 45 | ||||
-rw-r--r-- | modules/mpd/mpd.class.php | 47 |
2 files changed, 56 insertions, 36 deletions
diff --git a/modules/localplay/mpd.controller.php b/modules/localplay/mpd.controller.php index b212b38c..afdd4442 100644 --- a/modules/localplay/mpd.controller.php +++ b/modules/localplay/mpd.controller.php @@ -178,6 +178,23 @@ class AmpacheMpd extends localplay_controller { } // get_instances /** + * get_instance + * This returns the specified instance and all it's pretty variables + */ + private function get_instance($instance) { + + $instance = Dba::escape($instance); + + $sql = "SELECT * FROM `localplay_mpd` WHERE `id`='$instance'"; + $db_results = Dba::query($sql); + + $row = Dba::fetch_assoc($db_results); + + return $row; + + } // get_instance + + /** * instance_fields * This returns a key'd array of [NAME]=>array([DESCRIPTION]=>VALUE,[TYPE]=>VALUE) for the * fields so that we can on-the-fly generate a form @@ -224,24 +241,22 @@ class AmpacheMpd extends localplay_controller { /** * add - * This must take an array of URL's from Ampache - * and then add them to MPD + * This takes a single object and adds it in, it uses the built in + * functions to generate the URL it needs */ - public function add($objects) { - + public function add($object) { + if (is_null($this->_mpd->ClearPLIfStopped())) { debug_event('mpd_add', 'Error: Unable to clear the MPD playlist ' . $this->_mpd->errStr,'1'); } - foreach ($songs as $song_id) { - $song = new Song($song_id); - $url = $song->get_url(0,1); - if (is_null($this->_mpd->PlAdd($url))) { - debug_event('mpd_add','Error: Unable to add $url to MPD ' . $this->_mpd->errStr,'1'); - } - - } // end foreach + $url = $this->get_url($object); + if (is_null($this->_mpd->PlAdd($url))) { + debug_event('mpd_add',"Error: Unable to add $url to MPD " . $this->_mpd->errStr,'1'); + return false; + } + return true; } // add_songs @@ -505,8 +520,10 @@ class AmpacheMpd extends localplay_controller { * is stored in this class */ public function connect() { - - $this->_mpd = new mpd(conf('localplay_mpd_hostname'),conf('localplay_mpd_port'),conf('localplay_mpd_password')); + + // Look at the current instance and pull the options for said instance + $options = self::get_instance($GLOBALS['user']->prefs['mpd_active']); + $this->_mpd = new mpd($options['host'],$options['port'],$options['password']); if ($this->_mpd->connected) { return true; } diff --git a/modules/mpd/mpd.class.php b/modules/mpd/mpd.class.php index ca853936..505425b1 100644 --- a/modules/mpd/mpd.class.php +++ b/modules/mpd/mpd.class.php @@ -128,29 +128,32 @@ class mpd { $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; - $this->errStr = "Password supplied is incorrect or Invalid Command"; - return; // bad password or command - } + + list ( $this->mpd_version ) = sscanf($resp, OK . " MPD %s\n"); + + if ( ! empty($pwd) ) { + if ( is_null($this->SendCommand(MPD_CMD_PASSWORD,$pwd)) ) { + $this->connected = FALSE; + $this->errStr = "Password supplied is incorrect or Invalid Command"; + 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;
- } - } + 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;
+ }
+ } // if password + 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; + } } - } + return true; + + } // constructor /* Connect() * @@ -185,7 +188,7 @@ class mpd { if (function_exists('socket_get_status')) { $status = socket_get_status($this->mpd_sock); } - if (strncmp(MPD_RESPONSE_OK,$response,strlen(MPD_RESPONSE_OK)) == 0) { + if (strstr($response,"OK")) { $this->connected = TRUE; return $response; break; |