mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-04 02:09:23 +02:00
made localplay technically work, lots of work to still do
This commit is contained in:
parent
649c44446a
commit
1dfdf2afab
9 changed files with 113 additions and 85 deletions
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
--------------------------------------------------------------------------
|
--------------------------------------------------------------------------
|
||||||
v.3.4-Alpha3
|
v.3.4-Alpha3
|
||||||
|
- Based MPD Support Restored
|
||||||
- Moved catalog stats off to statistics page
|
- Moved catalog stats off to statistics page
|
||||||
- Added basic sorting to all browse pages
|
- Added basic sorting to all browse pages
|
||||||
- Tweaked the Playback to try to fix some issues with WMP
|
- Tweaked the Playback to try to fix some issues with WMP
|
||||||
|
|
|
@ -50,8 +50,21 @@ abstract class localplay_controller {
|
||||||
* get_url
|
* get_url
|
||||||
* This returns the URL for the passed object
|
* This returns the URL for the passed object
|
||||||
*/
|
*/
|
||||||
private function get_url($object) {
|
public function get_url($object) {
|
||||||
|
|
||||||
|
// This can get a little complicated
|
||||||
|
switch ($object_type) {
|
||||||
|
case 'random':
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 'radio':
|
||||||
|
case 'song':
|
||||||
|
default:
|
||||||
|
$url = $object->get_url(Stream::$session);
|
||||||
|
break;
|
||||||
|
} // end switch on objecttype
|
||||||
|
|
||||||
|
return $url;
|
||||||
|
|
||||||
} // get_url
|
} // get_url
|
||||||
|
|
||||||
|
@ -60,7 +73,7 @@ abstract class localplay_controller {
|
||||||
* This returns the Filename for the passed object, not
|
* This returns the Filename for the passed object, not
|
||||||
* always possible
|
* always possible
|
||||||
*/
|
*/
|
||||||
private function get_file($object) {
|
public function get_file($object) {
|
||||||
|
|
||||||
|
|
||||||
} // get_file
|
} // get_file
|
||||||
|
|
|
@ -224,14 +224,7 @@ class Localplay {
|
||||||
*/
|
*/
|
||||||
public function connect() {
|
public function connect() {
|
||||||
|
|
||||||
$function = $this->_function_map['connect'];
|
if (!$this->_player->connect()) {
|
||||||
|
|
||||||
/* This is very bad, that means they don't even
|
|
||||||
* have a connection function defined
|
|
||||||
*/
|
|
||||||
if (!$function) { return false; }
|
|
||||||
|
|
||||||
if (!$this->_player->$function()) {
|
|
||||||
debug_event('localplay','Error Unable to connect, check ' . $this->type . ' controller','1');
|
debug_event('localplay','Error Unable to connect, check ' . $this->type . ' controller','1');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -247,9 +240,7 @@ class Localplay {
|
||||||
*/
|
*/
|
||||||
public function play() {
|
public function play() {
|
||||||
|
|
||||||
$function = $this->_function_map['play'];
|
if (!$this->_player->play()) {
|
||||||
|
|
||||||
if (!$this->_player->$function()) {
|
|
||||||
debug_event('localplay','Error Unable to start playback, check ' . $this->type . ' controller','1');
|
debug_event('localplay','Error Unable to start playback, check ' . $this->type . ' controller','1');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -278,20 +269,15 @@ class Localplay {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* add
|
* add
|
||||||
* This function takes an array of song_ids and then passes the full URL
|
* This function takes a single object and then passes it to
|
||||||
* to the player, this is a required function.
|
* to the player, this is a required function.
|
||||||
*/
|
*/
|
||||||
public function add($songs) {
|
public function add($object) {
|
||||||
|
|
||||||
|
if (!$this->_player->add($object)) {
|
||||||
/* Call the Function Specified in the Function Map */
|
|
||||||
$function = $this->_function_map['add'];
|
|
||||||
|
|
||||||
if (!$this->_player->$function($songs)) {
|
|
||||||
debug_event('localplay','Error Unable to add songs, check ' . $this->type . ' controller','1');
|
debug_event('localplay','Error Unable to add songs, check ' . $this->type . ' controller','1');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,16 @@ class Radio {
|
||||||
|
|
||||||
} // format
|
} // format
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get_url
|
||||||
|
* This returns the URL for this live stream
|
||||||
|
*/
|
||||||
|
public function get_url() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // get_url
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* update
|
* update
|
||||||
* This is a static function that takes a key'd array for input
|
* This is a static function that takes a key'd array for input
|
||||||
|
|
|
@ -799,10 +799,6 @@ class Song {
|
||||||
|
|
||||||
$type = $this->type;
|
$type = $this->type;
|
||||||
|
|
||||||
if ($GLOBALS['user']->prefs['play_type'] == 'downsample') {
|
|
||||||
$ds_string = "&ds=" . $GLOBALS['user']->prefs['sample_rate'];
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Account for retarded players */
|
/* Account for retarded players */
|
||||||
if ($this->type == 'flac') { $type = 'ogg'; }
|
if ($this->type == 'flac') { $type = 'ogg'; }
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,9 @@ class Stream {
|
||||||
public $sess;
|
public $sess;
|
||||||
public $user_id;
|
public $user_id;
|
||||||
|
|
||||||
|
// Generate once an object is constructed
|
||||||
|
public static $session;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for the stream class takes a type and an array
|
* Constructor for the stream class takes a type and an array
|
||||||
* of song ids
|
* of song ids
|
||||||
|
@ -52,7 +55,7 @@ class Stream {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate the session ID
|
// Generate the session ID
|
||||||
$this->session = md5(uniqid(rand(), true));;
|
self::$session = md5(uniqid(rand(), true));;
|
||||||
|
|
||||||
} // Constructor
|
} // Constructor
|
||||||
|
|
||||||
|
@ -109,7 +112,7 @@ class Stream {
|
||||||
$expire = time() + Config::get('stream_length');
|
$expire = time() + Config::get('stream_length');
|
||||||
|
|
||||||
$sql = "INSERT INTO `session_stream` (`id`,`expire`,`user`) " .
|
$sql = "INSERT INTO `session_stream` (`id`,`expire`,`user`) " .
|
||||||
"VALUES('$this->session','$expire','$this->user_id')";
|
"VALUES('" . self::$session . "','$expire','$this->user_id')";
|
||||||
$db_results = Dba::query($sql);
|
$db_results = Dba::query($sql);
|
||||||
|
|
||||||
if (!$db_results) { return false; }
|
if (!$db_results) { return false; }
|
||||||
|
@ -204,7 +207,7 @@ class Stream {
|
||||||
if ($GLOBALS['user']->prefs['play_type'] == 'downsample') {
|
if ($GLOBALS['user']->prefs['play_type'] == 'downsample') {
|
||||||
$ds = $GLOBALS['user']->prefs['sample_rate'];
|
$ds = $GLOBALS['user']->prefs['sample_rate'];
|
||||||
}
|
}
|
||||||
echo $song->get_url($this->session);
|
echo $song->get_url(self::$session);
|
||||||
} // end foreach
|
} // end foreach
|
||||||
|
|
||||||
/* Foreach the additional URLs */
|
/* Foreach the additional URLs */
|
||||||
|
@ -241,7 +244,7 @@ class Stream {
|
||||||
$song->format();
|
$song->format();
|
||||||
|
|
||||||
echo "#EXTINF:$song->time," . $song->f_artist_full . " - " . $song->title . "\n";
|
echo "#EXTINF:$song->time," . $song->f_artist_full . " - " . $song->title . "\n";
|
||||||
echo $song->get_url($this->session) . "\n";
|
echo $song->get_url(self::$session) . "\n";
|
||||||
} // end foreach
|
} // end foreach
|
||||||
|
|
||||||
/* Foreach URLS */
|
/* Foreach URLS */
|
||||||
|
@ -272,7 +275,7 @@ class Stream {
|
||||||
$song = new Song($song_id);
|
$song = new Song($song_id);
|
||||||
$song->format();
|
$song->format();
|
||||||
$song_name = $song->f_artist_full . " - " . $song->title . "." . $song->type;
|
$song_name = $song->f_artist_full . " - " . $song->title . "." . $song->type;
|
||||||
$song_url = $song->get_url($this->session);
|
$song_url = $song->get_url(self::$session);
|
||||||
echo "File" . $i . "=$song_url\n";
|
echo "File" . $i . "=$song_url\n";
|
||||||
echo "Title" . $i . "=$song_name\n";
|
echo "Title" . $i . "=$song_name\n";
|
||||||
echo "Length" . $i . "=$song->time\n";
|
echo "Length" . $i . "=$song->time\n";
|
||||||
|
@ -306,7 +309,7 @@ class Stream {
|
||||||
foreach ($this->songs as $song_id) {
|
foreach ($this->songs as $song_id) {
|
||||||
$song = new Song($song_id);
|
$song = new Song($song_id);
|
||||||
$song->format();
|
$song->format();
|
||||||
$url = $song->get_url($this->session);
|
$url = $song->get_url(self::$session);
|
||||||
$song_name = $song->f_artist_full . " - " . $song->title . "." . $song->type;
|
$song_name = $song->f_artist_full . " - " . $song->title . "." . $song->type;
|
||||||
|
|
||||||
echo "<ENTRY>\n";
|
echo "<ENTRY>\n";
|
||||||
|
@ -350,7 +353,7 @@ class Stream {
|
||||||
$song->format();
|
$song->format();
|
||||||
|
|
||||||
$xml = array();
|
$xml = array();
|
||||||
$xml['track']['location'] = $song->get_url($this->session) . $flash_hack;
|
$xml['track']['location'] = $song->get_url(self::$session) . $flash_hack;
|
||||||
$xml['track']['identifier'] = $xml['track']['location'];
|
$xml['track']['identifier'] = $xml['track']['location'];
|
||||||
$xml['track']['title'] = $song->title;
|
$xml['track']['title'] = $song->title;
|
||||||
$xml['track']['creator'] = $song->f_artist_full;
|
$xml['track']['creator'] = $song->f_artist_full;
|
||||||
|
@ -428,23 +431,19 @@ class Stream {
|
||||||
*/
|
*/
|
||||||
function create_localplay() {
|
function create_localplay() {
|
||||||
|
|
||||||
if (!$localplay = new Localplay($GLOBALS['user']->prefs['localplay_controller'])) {
|
// First figure out what their current one is and create the object
|
||||||
debug_event('localplay','Player failed to init on song add','3');
|
$localplay = new Localplay($GLOBALS['user']->prefs['localplay_controller']);
|
||||||
echo "Error: Localplay Init Failed check config";
|
$localplay->connect();
|
||||||
return false;
|
|
||||||
|
//HACK!!!
|
||||||
|
// Yea.. you know the baby jesus... he's crying right meow
|
||||||
|
foreach ($this->songs as $song_id) {
|
||||||
|
$this->objects[] = new Song($song_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$localplay->connect()) {
|
// Foreach the stuff we've got and add it
|
||||||
debug_event('localplay','Localplay Player Connect failed','3');
|
foreach ($this->objects as $object) {
|
||||||
echo "Error: Localplay connect failed check config";
|
$localplay->add($object,self::$session);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$localplay->add($this->songs);
|
|
||||||
|
|
||||||
/* Check for Support */
|
|
||||||
if ($localplay->has_function('add_url')) {
|
|
||||||
$localplay->add_url($this->urls);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$localplay->play();
|
$localplay->play();
|
||||||
|
@ -475,7 +474,7 @@ class Stream {
|
||||||
// Build up our object
|
// Build up our object
|
||||||
$song_id = $this->songs['0'];
|
$song_id = $this->songs['0'];
|
||||||
$song = new Song($song_id);
|
$song = new Song($song_id);
|
||||||
$url = $song->get_url($this->session);
|
$url = $song->get_url(self::$session);
|
||||||
|
|
||||||
// Append the fact we are downloading
|
// Append the fact we are downloading
|
||||||
$url .= '&action=download';
|
$url .= '&action=download';
|
||||||
|
@ -497,7 +496,7 @@ class Stream {
|
||||||
header("Content-Type: audio/x-pn-realaudio ram;");
|
header("Content-Type: audio/x-pn-realaudio ram;");
|
||||||
foreach ($this->songs as $song_id) {
|
foreach ($this->songs as $song_id) {
|
||||||
$song = new Song($song_id);
|
$song = new Song($song_id);
|
||||||
echo $song->get_url($this->session);
|
echo $song->get_url(self::$session);
|
||||||
} // foreach songs
|
} // foreach songs
|
||||||
|
|
||||||
} // create_ram
|
} // create_ram
|
||||||
|
|
|
@ -177,6 +177,23 @@ class AmpacheMpd extends localplay_controller {
|
||||||
|
|
||||||
} // get_instances
|
} // 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
|
* instance_fields
|
||||||
* This returns a key'd array of [NAME]=>array([DESCRIPTION]=>VALUE,[TYPE]=>VALUE) for the
|
* This returns a key'd array of [NAME]=>array([DESCRIPTION]=>VALUE,[TYPE]=>VALUE) for the
|
||||||
|
@ -224,24 +241,22 @@ class AmpacheMpd extends localplay_controller {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* add
|
* add
|
||||||
* This must take an array of URL's from Ampache
|
* This takes a single object and adds it in, it uses the built in
|
||||||
* and then add them to MPD
|
* functions to generate the URL it needs
|
||||||
*/
|
*/
|
||||||
public function add($objects) {
|
public function add($object) {
|
||||||
|
|
||||||
if (is_null($this->_mpd->ClearPLIfStopped())) {
|
if (is_null($this->_mpd->ClearPLIfStopped())) {
|
||||||
debug_event('mpd_add', 'Error: Unable to clear the MPD playlist ' . $this->_mpd->errStr,'1');
|
debug_event('mpd_add', 'Error: Unable to clear the MPD playlist ' . $this->_mpd->errStr,'1');
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($songs as $song_id) {
|
$url = $this->get_url($object);
|
||||||
$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
|
|
||||||
|
|
||||||
|
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;
|
return true;
|
||||||
|
|
||||||
} // add_songs
|
} // add_songs
|
||||||
|
@ -505,8 +520,10 @@ class AmpacheMpd extends localplay_controller {
|
||||||
* is stored in this class
|
* is stored in this class
|
||||||
*/
|
*/
|
||||||
public function connect() {
|
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; }
|
if ($this->_mpd->connected) { return true; }
|
||||||
|
|
||||||
|
|
|
@ -128,29 +128,32 @@ class mpd {
|
||||||
$this->errStr = "Could not connect";
|
$this->errStr = "Could not connect";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else { list ( $this->mpd_version ) = sscanf($resp, MPD_RESPONSE_OK . " MPD %s\n");
|
|
||||||
|
list ( $this->mpd_version ) = sscanf($resp, OK . " MPD %s\n");
|
||||||
if ( ! is_null($pwd) ) {
|
|
||||||
if ( is_null($this->SendCommand(MPD_CMD_PASSWORD,$pwd)) ) {
|
if ( ! empty($pwd) ) {
|
||||||
$this->connected = FALSE;
|
if ( is_null($this->SendCommand(MPD_CMD_PASSWORD,$pwd)) ) {
|
||||||
$this->errStr = "Password supplied is incorrect or Invalid Command";
|
$this->connected = FALSE;
|
||||||
return; // bad password or command
|
$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!
|
if ( is_null($this->RefreshInfo()) ) { // no read access -- might as well be disconnected!
|
||||||
$this->connected = FALSE;
|
$this->connected = FALSE;
|
||||||
$this->errStr = "Password supplied does not have read access";
|
$this->errStr = "Password supplied does not have read access";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} // if password
|
||||||
if ( is_null($this->RefreshInfo()) ) { // no read access -- might as well be disconnected!
|
else {
|
||||||
$this->connected = FALSE;
|
if ( is_null($this->RefreshInfo()) ) { // no read access -- might as well be disconnected!
|
||||||
$this->errStr = "Password required to access server";
|
$this->connected = FALSE;
|
||||||
return;
|
$this->errStr = "Password required to access server";
|
||||||
}
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
return true;
|
||||||
|
|
||||||
|
} // constructor
|
||||||
|
|
||||||
/* Connect()
|
/* Connect()
|
||||||
*
|
*
|
||||||
|
@ -185,7 +188,7 @@ class mpd {
|
||||||
if (function_exists('socket_get_status')) {
|
if (function_exists('socket_get_status')) {
|
||||||
$status = socket_get_status($this->mpd_sock);
|
$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;
|
$this->connected = TRUE;
|
||||||
return $response;
|
return $response;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -29,7 +29,10 @@ switch ($_REQUEST['action']) {
|
||||||
// Make sure they they are allowed to do this
|
// Make sure they they are allowed to do this
|
||||||
//... ok I don't really know what that means yet
|
//... ok I don't really know what that means yet
|
||||||
|
|
||||||
|
$type = $_REQUEST['instance'] ? 'localplay' : 'stream';
|
||||||
|
|
||||||
Preference::update('mpd_active',$GLOBALS['user']->id,$_REQUEST['instance']);
|
Preference::update('mpd_active',$GLOBALS['user']->id,$_REQUEST['instance']);
|
||||||
|
Preference::update('play_type',$GLOBALS['user']->id,$type);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue