diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2006-12-22 19:27:33 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2006-12-22 19:27:33 +0000 |
commit | 2f2aff930ae0b590d0460e783ec090114b15f04f (patch) | |
tree | 6fcf3836966ff7b0e92c1a7c157bfc1c033b8a92 | |
parent | 2d06bf58a22f52e3ca3a3d046a48862da1790a40 (diff) | |
download | ampache-2f2aff930ae0b590d0460e783ec090114b15f04f.tar.gz ampache-2f2aff930ae0b590d0460e783ec090114b15f04f.tar.bz2 ampache-2f2aff930ae0b590d0460e783ec090114b15f04f.zip |
new httpq localplay method, fixes for preferences and mpd controller
-rw-r--r-- | bin/write_tags.php.inc | 3 | ||||
-rwxr-xr-x | docs/CHANGELOG | 3 | ||||
-rw-r--r-- | lib/class/user.class.php | 2 | ||||
-rw-r--r-- | lib/init.php | 2 | ||||
-rw-r--r-- | modules/httpq/httpqplayer.class.php | 305 | ||||
-rw-r--r-- | modules/localplay/httpq.controller.php | 414 | ||||
-rw-r--r-- | modules/localplay/mpd.controller.php | 2 | ||||
-rw-r--r-- | templates/show_preferences.inc | 12 |
8 files changed, 686 insertions, 57 deletions
diff --git a/bin/write_tags.php.inc b/bin/write_tags.php.inc index cbf592de..8f9279da 100644 --- a/bin/write_tags.php.inc +++ b/bin/write_tags.php.inc @@ -68,9 +68,6 @@ foreach($flaggedIds as $flagged){ $tagData['date'][] = $song->year; $tagData['year'][] = $song->year; $tagData['comment'][] = $song->comment; - $tagData['bitrate'][] = $song->bitrate; - $tagData['rate'][] = $song->rate; - $tagData['mode'][] = $song->mode; $tagData['size'][] = $song->size; $tagData['time'][] = $song->time; $tagData['album'][] = $song->get_album_name(); diff --git a/docs/CHANGELOG b/docs/CHANGELOG index 16a92c27..678e1a09 100755 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -4,6 +4,9 @@ -------------------------------------------------------------------------- v.3.3.3-Beta3 + - Fixed Preferences page, preferences now ordered semi-logically + - Fixed MPD controller so it displays track numbers correctly + - Added HttpQ Localplay Module. - Added 'Best Guess' option to Duplicate Song Disabled that checks the shortest, lowest bitrate, smallest of a duplicate set - Removed unused templates and documents diff --git a/lib/class/user.class.php b/lib/class/user.class.php index b84b4e89..f4a00387 100644 --- a/lib/class/user.class.php +++ b/lib/class/user.class.php @@ -123,7 +123,7 @@ class User { $sql = "SELECT preferences.name, preferences.description, preferences.catagory, user_preference.value FROM preferences,user_preference " . - "WHERE user_preference.user='$user_id' AND user_preference.preference=preferences.id $user_limit"; + "WHERE user_preference.user='$user_id' AND user_preference.preference=preferences.id $user_limit ORDER BY id"; $db_results = mysql_query($sql, dbh()); /* Ok this is crapy, need to clean this up or improve the code FIXME */ diff --git a/lib/init.php b/lib/init.php index a1096b01..a3c9e98d 100644 --- a/lib/init.php +++ b/lib/init.php @@ -67,7 +67,7 @@ if (!$results = read_config($configfile,0)) { } /** This is the version.... fluf nothing more... **/ -$results['version'] = '3.3.3-Beta3 (Build 002)'; +$results['version'] = '3.3.3-Beta3 (Build 003)'; $results['raw_web_path'] = $results['web_path']; $results['web_path'] = $http_type . $_SERVER['HTTP_HOST'] . $results['web_path']; diff --git a/modules/httpq/httpqplayer.class.php b/modules/httpq/httpqplayer.class.php index 8efaf6e4..857a7de6 100644 --- a/modules/httpq/httpqplayer.class.php +++ b/modules/httpq/httpqplayer.class.php @@ -5,9 +5,8 @@ All rights reserved.
This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
+ modify it under the terms of the GNU General Public License v2
+ as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -22,39 +21,80 @@ */
-
+/**
+ * HttpQPlayer
+ * This player controls an instance of HttpQ
+ * which in turn controls WinAmp all functions
+ * return null on failure
+ */
class HttpQPlayer {
var $host;
var $port;
var $password;
-
+
+ /**
+ * HttpQPlayer
+ * This is the constructor, it defaults to localhost
+ * with port 4800
+ */
function HttpQPlayer($h = "localhost", $pw = "", $p = 4800) {
+
$this->host = $h;
$this->port = $p;
$this->password = $pw;
+
} // HttpQPlayer
- /*!
- @function add
- @discussion append a song to the playlist
- @param $name Name to be shown in the playlist
- @param $url URL of the song
+ /**
+ * add
+ * append a song to the playlist
+ * $name Name to be shown in the playlist
+ * $url URL of the song
*/
function add($name, $url) {
+
$args["name"] = $name;
- $args["url"] = str_replace("&","%26",$url);;
- $this->sendCommand("playurl", $args);
- }
+ $args["url"] = str_replace("&","%26",$url);
+ $results = $this->sendCommand("playurl", $args);
- /*!
- @function clear
- @discussion clear the playlist
+ if ($results == '0') { $results = null; }
+
+ return $results;
+
+ } // add
+
+ /**
+ * version
+ * This gets the version of winamp currently
+ * running, use this to test for a valid connection
+ */
+ function version() {
+
+ $args = array();
+ $results = $this->sendCommand('getversion',$args);
+
+ // a return of 0 is a bad value
+ if ($results == '0') { $results = null; }
+
+
+ return $results;
+
+ } // version
+
+ /**
+ * clear
+ * clear the playlist
*/
function clear() {
$args = array();
- $this->sendCommand("delete", $args);
- }
+ $results = $this->sendCommand("delete", $args);
+
+ if ($results == '0') { $results = null; }
+
+ return $results;
+
+ } // clear
/*!
@function next
@@ -74,51 +114,226 @@ class HttpQPlayer { $this->sendCommand("prev", $args);
}
- /*!
- @function play
- @discussion play the current song
+ /**
+ * play
+ * play the current song
*/
function play() {
+
$args = array();
- $this->sendCommand("play", $args);
- }
+ $results = $this->sendCommand("play", $args);
+
+ if ($results == '0') { $results = null; }
+
+ return $results;
+
+ } // play
- /*!
- @function pause
- @discussion toggle pause mode on current song
+ /**
+ * pause
+ * toggle pause mode on current song
*/
function pause() {
+
$args = array();
- $this->sendCommand("pause", $args);
- }
+ $results = $this->sendCommand("pause", $args);
+
+ if ($results == '0') { $results = null; }
+
+ return $results;
+
+ } // pause
- /*!
- @function stop
- @discussion stop the current song
+ /**
+ * stop
+ * stops the current song amazing!
*/
function stop() {
+
$args = array();
- $this->sendCommand("stop", $args);
- }
+ $results = $this->sendCommand('fadeoutandstop', $args);
+
+ if ($results == '0') { $results = null; }
+
+ return $results;
+
+ } // stop
+
+ /**
+ * repeat
+ * This toggles the repeat state of HttpQ
+ */
+ function repeat($value) {
+
+ $args = array('enable'=>$value);
+ $results = $this->sendCommand('repeat',$args);
+
+ if ($results == '0') { $results = null; }
+
+ return $results;
+
+ } // repeat
+
+ /**
+ * random
+ * this toggles the random state of HttpQ
+ */
+ function random($value) {
+
+ $args = array('enable'=>$value);
+ $results = $this->sendCommand('shuffle',$args);
+
+ if ($results == '0') { $results = null; }
+
+ return $results;
+
+ } // random
+
+ /**
+ * delete_pos
+ * This deletes a specific track
+ */
+ function delete_pos($track) {
+
+ $args = array('index'=>$track);
+ $results = $this->sendCommand('deletepos',$args);
+
+ if ($results == '0') { $results = null; }
+
+ return $results;
+
+ } // delete_pos
+
+ /**
+ * state
+ * This returns the current state of the httpQ player
+ */
+ function state() {
+
+ $args = array();
+ $results = $this->sendCommand('isplaying',$args);
+
+ if ($results == '1') { $state = 'play'; }
+ if ($results == '0') { $state = 'stop'; }
+ if ($results == '3') { $state = 'pause'; }
+
+ return $state;
+
+ } // state
+
+ /**
+ * get_volume
+ * This returns the current volume
+ */
+ function get_volume() {
+
+ $args = array();
+ $results = $this->sendCommand('getvolume',$args);
+
+ if ($results == '0') { $results = null; }
+ else {
+ /* Need to make this out of 100 */
+ $results = ($results / 255) * 100;
+ }
+
+ return $results;
+
+ } // get_volume
+
+ /**
+ * get_repeat
+ * This returns the current state of the repeat
+ */
+ function get_repeat() {
+
+ $args = array();
+ $results = $this->sendCommand('repeat_status',$args);
+
+ return $results;
+
+ } // get_repeat
+
+ /**
+ * get_random
+ * This returns the current state of shuffle
+ */
+ function get_random() {
+
+ $args = array();
+ $results = $this->sendCommand('shuffle_status',$args);
+
+ return $results;
+
+ } // get_random
+
+ /**
+ * get_now_playing
+ * This returns the file information for the currently
+ * playing song
+ */
+ function get_now_playing() {
+
+ // First get the current POS
+ $pos = $this->sendCommand('getlistpos',array());
+
+ // Now get the filename
+ $file = $this->sendCommand('getplaylistfile',array('index'=>$post));
+
+ return $file;
+
+ } // get_now_playing
+
+ /**
+ * get_tracks
+ * This returns a delimiated string of all of the filenames
+ * current in your playlist
+ */
+ function get_tracks() {
+
+ // Pull a delimited list of all tracks
+ $results = $this->sendCommand('getplaylistfile',array('delim'=>':'));
+
+ if ($results == '0') { $results = null; }
+ return $results;
+
+ } // get_tracks
+
+ /**
+ * sendCommand
+ * This is the core of this library it takes care of sending the HTTP
+ * request to the HttpQ server and getting the response
+ */
function sendCommand($cmd, $args) {
+
$fp = fsockopen($this->host, $this->port, &$errno, &$errstr);
+
if(!$fp) {
debug_event('httpq',"HttpQPlayer: $errstr ($errno)",'1');
+ return null;
}
- else {
- $msg = "GET /$cmd?p=$this->password";
- foreach ($args AS $key => $val) {
- $msg = $msg . "&$key=$val";
- }
- $msg = $msg . " HTTP/1.0\r\n\r\n";
- fputs($fp, $msg);
- while(!feof($fp)) {
- fgets($fp);
- }
+
+ // Define the base message
+ $msg = "GET /$cmd?p=$this->password";
+
+ // Foreach our arguments
+ foreach ($args AS $key => $val) {
+ $msg = $msg . "&$key=$val";
+ }
+
+ $msg = $msg . " HTTP/1.0\r\n\r\n";
+ fputs($fp, $msg);
+
+ $data = '';
+
+ while(!feof($fp)) {
+ $data .= fgets($fp);
+ }
fclose($fp);
- }
- }
+
+ return $data;
+
+ } // sendCommand
} // End HttpQPlayer Class
diff --git a/modules/localplay/httpq.controller.php b/modules/localplay/httpq.controller.php new file mode 100644 index 00000000..57b9d5af --- /dev/null +++ b/modules/localplay/httpq.controller.php @@ -0,0 +1,414 @@ +<?php +/* + + Copyright 2001 - 2006 Ampache.org + All Rights Reserved + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License v2 + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +/** + * AmpacheHttpQ Class + * This is the class for the HttpQ localplay method to remote control + * a WinAmp Instance + */ +class AmpacheHttpq { + + /* Variables */ + + + /* Constructed variables */ + var $_httpq; + + /** + * Constructor + * This returns the array map for the localplay object + * REQUIRED for Localplay + */ + function AmpacheHttpq() { + + /* Do a Require Once On the needed Libraries */ + require_once(conf('prefix') . '/modules/httpq/httpqplayer.class.php'); + + } // AmpacheHttpq + + + /** + * function_map + * This function returns a named array of the functions + * that this player supports and their names in this local + * class. This is a REQUIRED function + */ + function function_map() { + + $map = array(); + + /* Required Functions */ + $map['add'] = 'add_songs'; + $map['delete'] = 'delete_songs'; + $map['play'] = 'play'; + $map['stop'] = 'stop'; + $map['get'] = 'get_songs'; + $map['status'] = 'get_status'; + $map['connect'] = 'connect'; + + /* Recommended Functions */ + //$map['skip'] = 'skip'; + //$map['next'] = 'next'; + //$map['prev'] = 'prev'; + $map['pause'] = 'pause'; + //$map['volume_up'] = 'volume_up'; + //$map['volume_down'] = 'volume_down'; + $map['random'] = 'random'; + $map['repeat'] = 'loop'; + + /* Optional Functions */ + //$map['move'] = 'move'; + //$map['delete_all'] = 'clear_playlist'; + $map['add_url'] = 'add_url'; + + return $map; + + } // function_map + + /** + * preference + * This function returns an array of the preferences and their + * information for Ampache to use All preferences will get a + * localplay_mpd_ appended to their name to avoid conflicts + * however this controller does not need to take that into acount + * REQUIRE for Locaplay + */ + function preferences() { + + $preferences = array(); + + $preferences[] = array('name'=>'hostname','default'=>'localhost','type'=>'string','description'=>'HttpQ Hostname'); + $preferences[] = array('name'=>'port','default'=>'4800','type'=>'integer','description'=>'HttpQ Port'); + $preferences[] = array('name'=>'password','default'=>'','type'=>'string','description'=>'HttpQ Password'); + + return $preferences; + + } // preferences + + + /** + * add_songs + * This must take an array of URL's from Ampache + * and then add them to HttpQ + */ + function add_songs($songs) { + + foreach ($songs as $song_id) { + $song = new Song($song_id); + $url = $song->get_url(0,1); + if (is_null($this->_httpq->add($song->title,$url))) { + debug_event('httpq_add','Error: Unable to add $url to Httpq','1'); + } + + } // end foreach + + return true; + + } // add_songs + + /** + * add_url + * This adds urls directly to the playlist, recieves an array of urls + */ + function add_url($urls) { + + foreach ($urls as $url) { + if (is_null($this->_httpq->add('URL',$url))) { + debug_event('httpq_add','Error: Unable to add $url to Httpq ','1'); + } + + } // end foreach + + return true; + + } // add_url + + /** + * delete_songs + * This must take an array of ID's (as passed by get function) from Ampache + * and delete them from Httpq + */ + function delete_songs($songs) { + + /* Default to true */ + $return = true; + + /* This should be an array of UID's as returned by + * the get function so that we can just call the class based + * functions to remove them or if there isn't a uid for + * the songs, then however ya'll have stored them + * in this controller + */ + foreach ($songs as $uid) { + + if (is_null($this->_httpq->delete_pos($uid))) { $return = false; } + + } // foreach of songs + + return $return; + + } // delete_songs + + /** + * clear_playlist + * This deletes the entire Httpq playlist... nuff said + */ + function clear_playlist() { + + if (is_null($this->_httpq->clear())) { return false; } + + return true; + + } // clear_playlist + + /** + * play + * This just tells HttpQ to start playing, it does not + * take any arguments + */ + function play() { + + if (is_null($this->_httpq->play())) { return false; } + return true; + + } // play + + /** + * stop + * This just tells HttpQ to stop playing, it does not take + * any arguments + */ + function stop() { + + if (is_null($this->_httpq->stop())) { return false; } + return true; + + } // stop + + /** + * skip + * This tells MPD to skip to the specified song + */ + function skip($song) { + + if (is_null($this->_mpd->SkipTo($song))) { return false; } + return true; + + } // skip + + /** + * This tells MPD to increase the volume by 5 + */ + function volume_up() { + + if (is_null($this->_mpd->AdjustVolume('5'))) { return false; } + return true; + + } // volume_up + + /** + * This tells MPD to decrese the volume by 5 + */ + function volume_down() { + + if (is_null($this->_mpd->AdjustVolume('-5'))) { return false; } + return true; + + } // volume_down + + /** + * next + * This just tells MPD to skip to the next song + */ + function next() { + + if (is_null($this->_mpd->Next())) { return false; } + return true; + + } // next + + /** + * prev + * This just tells MPD to skip to the prev song + */ + function prev() { + + if (is_null($this->_mpd->Previous())) { return false; } + return true; + + } // prev + + /** + * pause + * This tells MPD to pause the current song + */ + function pause() { + + if (is_null($this->_httpq->pause())) { return false; } + return true; + + } // pause + + /** + * volume + * This tells MPD to set the volume to the parameter + */ + function volume($volume) { + + if (is_null($this->_mpd->SetVolume($volume))) { return false; } + return true; + + } // volume + + /** + * loop + * This tells MPD to set the repeating the playlist (i.e. loop) to either on or off + */ + function loop($state) { + + if (is_null($this->_httpq->repeat($state))) { return false; } + return true; + + } // loop + + + /** + * random + * This tells MPD to turn on or off the playing of songs from the playlist in random order + */ + function random($onoff) { + + if (is_null($this->_httpq->random($onoff))) { return false; } + return true; + + } // random + + /** + * move + * This tells MPD to move song from SrcPos to DestPos + */ + function move($SrcPos, $DestPos) { + + if (is_null($this->_mpd->PLMoveTrack($SrcPos, $DestPos))) { return false; } + + return true; + } // move + + /** + * get_songs + * This functions returns an array containing information about + * The songs that MPD currently has in it's playlist. This must be + * done in a standardized fashion + */ + function get_songs() { + + /* Get the Current Playlist */ + $list = $this->_httpq->get_tracks(); + + $songs = explode(":",$list); + + foreach ($songs as $key=>$song) { + $data = array(); + + /* Required Elements */ + $data['id'] = $key; + $data['raw'] = $entry['file']; + + /* Parse out the song ID and then create the song object */ + preg_match("/song=(\d+)\&/",$entry['file'],$matches); + + /* Attempt to build the new song */ + $song = new Song($matches['1']); + + /* If we don't know it, look up by filename */ + if (!$song->title) { + $filename = sql_escape($entry['file']); + $sql = "SELECT id FROM song WHERE file = '$filename'"; + $db_results = mysql_query($sql, dbh()); + if ($results = mysql_fetch_assoc($db_results)) { + $song = new Song($results['id']); + } + else { + $song->title = _('Unknown'); + } + } + + /* Make the name pretty */ + $song->format_song(); + $data['name'] = $song->f_title . ' - ' . $song->f_album . ' - ' . $song->f_artist; + + /* Optional Elements */ + $data['link'] = ''; + $data['track'] = $key+1; + + $results[] = $data; + + } // foreach playlist items + + return $results; + + } // get_songs + + /** + * get_status + * This returns bool/int values for features, loop, repeat and any other features + * That this localplay method supports. required function + */ + function get_status() { + + /* Construct the Array */ + $array['state'] = $this->_httpq->state(); + $array['volume'] = $this->_httpq->get_volume(); + $array['repeat'] = $this->_httpq->get_repeat(); + $array['random'] = $this->_httpq->get_random(); + $array['track'] = $this->_httpq->get_now_playing(); + + preg_match("/song=(\d+)\&/",$array['track'],$matches); + $song_id = $matches['1']; + $song = new Song($song_id); + $array['track_title'] = $song->title; + $array['track_artist'] = $song->get_artist_name(); + $array['track_album'] = $song->get_album_name(); + + return $array; + + } // get_status + + /** + * connect + * This functions creates the connection to HttpQ and returns + * a boolean value for the status, to save time this handle + * is stored in this class + */ + function connect() { + + $this->_httpq = new HttpQPlayer(conf('localplay_httpq_hostname'),conf('localplay_httpq_password'),conf('localplay_httpq_port')); + + // Test our connection by retriving the version + if (!is_null($this->_httpq->version())) { return true; } + + return false; + + } // connect + +} //end of AmpacheHttpq + +?> diff --git a/modules/localplay/mpd.controller.php b/modules/localplay/mpd.controller.php index b782b17c..9875b72e 100644 --- a/modules/localplay/mpd.controller.php +++ b/modules/localplay/mpd.controller.php @@ -361,7 +361,7 @@ class AmpacheMpd { /* Optional Elements */ $data['link'] = ''; - $data['track'] = $entry['Pos']; + $data['track'] = $entry['Pos']+1; $results[] = $data; diff --git a/templates/show_preferences.inc b/templates/show_preferences.inc index 714381d0..bba6b3ff 100644 --- a/templates/show_preferences.inc +++ b/templates/show_preferences.inc @@ -58,24 +58,24 @@ if (($GLOBALS['user']->has_access(100)) AND ($user_id == '-1' AND conf('use_auth <div id="tabcontainer"> <ul id="tablist"> <li <?php echo $tab_interface; ?>> - <a href="<?php echo $link; ?>?tab=interface&user_id=<?php echo $user_id; ?>" <?php echo $a_interface; ?>>Interface</a> + <a href="<?php echo $link; ?>?tab=interface&user_id=<?php echo $user_id; ?>" <?php echo $a_interface; ?>><?php echo _('Interface'); ?></a> </li> <li <?php echo $tab_streaming; ?>> - <a href="<?php echo $link; ?>?tab=streaming&user_id=<?php echo $user_id; ?>" <?php echo $a_streaming; ?>>Streaming</a> + <a href="<?php echo $link; ?>?tab=streaming&user_id=<?php echo $user_id; ?>" <?php echo $a_streaming; ?>><?php echo _('Streaming'); ?></a> </li> <li <?php echo $tab_options; ?>> - <a href="<?php echo $link; ?>?tab=options&user_id=<?php echo $user_id; ?>" <?php echo $a_options; ?>>Options</a> + <a href="<?php echo $link; ?>?tab=options&user_id=<?php echo $user_id; ?>" <?php echo $a_options; ?>><?php echo _('Options'); ?></a> </li> <?php if ($user_id != '-1' && $_SESSION['userdata']['type'] == 'mysql') { ?> <li <?php echo $tab_account; ?>> - <a href="<?php echo $link; ?>?tab=account&user_id=<?php echo $user_id; ?>" <?php echo $a_account; ?>>Account</a> + <a href="<?php echo $link; ?>?tab=account&user_id=<?php echo $user_id; ?>" <?php echo $a_account; ?>><?php echo _('Account'); ?></a> </li> <?php } elseif ($_SESSION['userdata']['type'] == 'mysql' || $user_id == '-1') { ?> <li <?php echo $tab_system; ?>> - <a href="<?php echo $link; ?>?tab=system&user_id=<?php echo $user_id; ?>" <?php echo $a_system; ?>>System</a> + <a href="<?php echo $link; ?>?tab=system&user_id=<?php echo $user_id; ?>" <?php echo $a_system; ?>><?php echo _('System'); ?></a> </li> <li <?php echo $tab_modules; ?>> - <a href="<?php echo $link; ?>?tab=modules&user_id=<?php echo $user_id; ?>" <?php echo $a_modules; ?>>Modules</a> + <a href="<?php echo $link; ?>?tab=modules&user_id=<?php echo $user_id; ?>" <?php echo $a_modules; ?>><?php echo _('Modules'); ?></a> </li> <?php } ?> |