mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-03 01:39:28 +02:00
some fixes for the localplay, you can now install the MPD controller, and add instances, just not actually play to it... realized I need to think on how to do that a little...
This commit is contained in:
parent
f2f82cae31
commit
d1dcfcbc90
13 changed files with 157 additions and 130 deletions
|
@ -32,32 +32,16 @@ if (!$GLOBALS['user']->has_access(100)) {
|
|||
show_header();
|
||||
|
||||
switch ($_REQUEST['action']) {
|
||||
case 'insert_localplay_preferences':
|
||||
$type = scrub_in($_REQUEST['type']);
|
||||
insert_localplay_preferences($type);
|
||||
$url = conf('web_path') . '/admin/preferences.php?tab=modules';
|
||||
$title = _('Module Activated');
|
||||
$body = '';
|
||||
show_confirmation($title,$body,$url);
|
||||
break;
|
||||
case 'confirm_remove_localplay_preferences':
|
||||
$type = scrub_in($_REQUEST['type']);
|
||||
$url = conf('web_path') . '/admin/modules.php?action=remove_localplay_preferences&type=' . $type;
|
||||
$title = _('Are you sure you want to remove this module?');
|
||||
$body = '';
|
||||
show_confirmation($title,$body,$url,1);
|
||||
break;
|
||||
case 'remove_localplay_preferences':
|
||||
$type = scrub_in($_REQUEST['type']);
|
||||
remove_localplay_preferences($type);
|
||||
$url = conf('web_path') . '/admin/preferences.php?tab=modules';
|
||||
$title = _('Module Deactivated');
|
||||
$body = '';
|
||||
show_confirmation($title,$body,$url);
|
||||
break;
|
||||
case 'install_localplay':
|
||||
|
||||
|
||||
$localplay = new Localplay($_REQUEST['type']);
|
||||
if (!$localplay->player_loaded()) {
|
||||
Error::add('general',_('Install Failed, Controller Error'));
|
||||
Error::display('general');
|
||||
break;
|
||||
}
|
||||
// Install it!
|
||||
$localplay->install();
|
||||
header("Location:" . Config::get('web_path') . '/admin/modules.php?action=show_localplay');
|
||||
break;
|
||||
case 'confirm_uninstall_localplay':
|
||||
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
|
||||
--------------------------------------------------------------------------
|
||||
v.3.4-Alpha3
|
||||
- Tweaked the Playback to try to fix some issues with WMP
|
||||
- Reduced the timeout on the LastFM Plugin to reduce delay
|
||||
when scrobbling is down
|
||||
- Added Add buttons to single playlist view, and put the delete
|
||||
link back for catalogs
|
||||
- Fixed Playlist Play links
|
||||
|
|
|
@ -115,8 +115,6 @@ class Localplay {
|
|||
unset($this->_player);
|
||||
return false;
|
||||
}
|
||||
$function_map = $this->_player->function_map();
|
||||
$this->_map_functions($function_map);
|
||||
}
|
||||
|
||||
} // _load_player
|
||||
|
@ -157,48 +155,6 @@ class Localplay {
|
|||
|
||||
} // format_name
|
||||
|
||||
/**
|
||||
* _map_functions
|
||||
* This takes the results from the loaded from the target player
|
||||
* and maps them to the defined functions that Ampache currently
|
||||
* supports, this is broken into require and optional componets
|
||||
* Failure of required componets will cause log entry and gui
|
||||
* warning. The value of the elements in the $data array should
|
||||
* be function names that are called on the action in question
|
||||
*/
|
||||
private function _map_functions($data) {
|
||||
|
||||
/* Required Functions */
|
||||
$this->_function_map['add'] = $data['add'];
|
||||
$this->_function_map['delete'] = $data['delete'];
|
||||
$this->_function_map['play'] = $data['play'];
|
||||
$this->_function_map['stop'] = $data['stop'];
|
||||
$this->_function_map['get'] = $data['get'];
|
||||
$this->_function_map['connect'] = $data['connect'];
|
||||
$this->_function_map['status'] = $data['status'];
|
||||
|
||||
/* Recommended Functions */
|
||||
$this->_function_map['pause'] = $data['pause'];
|
||||
$this->_function_map['next'] = $data['next'];
|
||||
$this->_function_map['prev'] = $data['prev'];
|
||||
$this->_function_map['skip'] = $data['skip'];
|
||||
$this->_function_map['get_playlist'] = $data['get_playlist'];
|
||||
$this->_function_map['get_playing'] = $data['get_playing'];
|
||||
$this->_function_map['repeat'] = $data['repeat'];
|
||||
$this->_function_map['random'] = $data['random'];
|
||||
$this->_function_map['loop'] = $data['loop'];
|
||||
|
||||
/* Optional Functions */
|
||||
$this->_function_map['volume_set'] = $data['volume_set'];
|
||||
$this->_function_map['volume_up'] = $data['volume_up'];
|
||||
$this->_function_map['volume_down'] = $data['volume_down'];
|
||||
$this->_function_map['delete_all'] = $data['delete_all'];
|
||||
$this->_function_map['randomize'] = $data['randomize'];
|
||||
$this->_function_map['move'] = $data['move'];
|
||||
$this->_function_map['add_url'] = $data['add_url'];
|
||||
|
||||
} // _map_functions
|
||||
|
||||
/**
|
||||
* get_controllers
|
||||
* This returns the controllers that are currently loaded into this instance
|
||||
|
@ -247,6 +203,20 @@ class Localplay {
|
|||
|
||||
} // is_enabled
|
||||
|
||||
/**
|
||||
* install
|
||||
* This runs the install for the localplay controller we've
|
||||
* currently got pimped out
|
||||
*/
|
||||
public function install() {
|
||||
|
||||
// Run the player's installer
|
||||
$installed = $this->_player->install();
|
||||
|
||||
return $installed;
|
||||
|
||||
} // install
|
||||
|
||||
/**
|
||||
* connect
|
||||
* This function attempts to connect to the localplay
|
||||
|
@ -576,17 +546,26 @@ class Localplay {
|
|||
} // pause
|
||||
|
||||
/**
|
||||
* get_preferences
|
||||
* This functions returns an array of the preferences that the localplay
|
||||
* controller needs in order to actually work
|
||||
* get_instances
|
||||
* This returns the instances of the current type
|
||||
*/
|
||||
public function get_preferences() {
|
||||
public function get_instances() {
|
||||
|
||||
$preferences = $this->_player->get_preferences();
|
||||
$instances = $this->_player->get_instances();
|
||||
|
||||
return $preferences;
|
||||
return $instances;
|
||||
|
||||
} // get_preferences
|
||||
} // get_instances
|
||||
|
||||
/**
|
||||
* add_instance
|
||||
* This adds a new instance for the current controller type
|
||||
*/
|
||||
public function add_instance($data) {
|
||||
|
||||
$this->_player->add_instance($data);
|
||||
|
||||
} // add_instance
|
||||
|
||||
/**
|
||||
* delete
|
||||
|
@ -625,6 +604,19 @@ class Localplay {
|
|||
|
||||
} // delete_all
|
||||
|
||||
/**
|
||||
* get_instance_fields
|
||||
* This loads the fields from the localplay
|
||||
* player and returns them
|
||||
*/
|
||||
public function get_instance_fields() {
|
||||
|
||||
$fields = $this->_player->instance_fields();
|
||||
|
||||
return $fields;
|
||||
|
||||
} // get_instance_fields
|
||||
|
||||
/**
|
||||
* get_user_state
|
||||
* This function returns a user friendly version
|
||||
|
|
|
@ -73,7 +73,7 @@ class scrobbler {
|
|||
*/
|
||||
public function handshake() {
|
||||
|
||||
$as_socket = @fsockopen('post.audioscrobbler.com', 80, $errno, $errstr, 5);
|
||||
$as_socket = fsockopen('post.audioscrobbler.com', 80, $errno, $errstr, 2);
|
||||
if(!$as_socket) {
|
||||
$this->error_msg = $errstr;
|
||||
return false;
|
||||
|
@ -186,7 +186,7 @@ class scrobbler {
|
|||
return false;
|
||||
}
|
||||
|
||||
$as_socket = @fsockopen($this->submit_host, intval($this->submit_port), $errno, $errstr, 5);
|
||||
$as_socket = fsockopen($this->submit_host, intval($this->submit_port), $errno, $errstr, 2);
|
||||
|
||||
if(!$as_socket) {
|
||||
$this->error_msg = $errstr;
|
||||
|
|
|
@ -428,7 +428,7 @@ class Stream {
|
|||
*/
|
||||
function create_localplay() {
|
||||
|
||||
if (!$localplay = init_localplay()) {
|
||||
if (!$localplay = new Localplay($GLOBALS['user']->prefs['localplay_controller'])) {
|
||||
debug_event('localplay','Player failed to init on song add','3');
|
||||
echo "Error: Localplay Init Failed check config";
|
||||
return false;
|
||||
|
@ -449,8 +449,6 @@ class Stream {
|
|||
|
||||
$localplay->play();
|
||||
|
||||
header("Location: " . return_referer());
|
||||
|
||||
} // create_localplay
|
||||
|
||||
/**
|
||||
|
|
|
@ -23,12 +23,29 @@ require 'lib/init.php';
|
|||
|
||||
show_header();
|
||||
|
||||
// Check to see if we've got the rights to be here
|
||||
if (!Config::get('allow_localplay_playback') || !$GLOBALS['user']->has_access('25')) {
|
||||
access_denied();
|
||||
}
|
||||
|
||||
|
||||
switch ($_REQUEST['action']) {
|
||||
case 'show_add_instance':
|
||||
// This requires 50 or better
|
||||
if (!$GLOBALS['user']->has_access('50')) { access_denied(); break; }
|
||||
|
||||
// Get the current localplay fields
|
||||
$localplay = new Localplay($GLOBALS['user']->prefs['localplay_controller']);
|
||||
$fields = $localplay->get_instance_fields();
|
||||
require_once Config::get('prefix') . '/templates/show_localplay_add_instance.inc.php';
|
||||
break;
|
||||
case 'add_instance':
|
||||
// This requires 50 or better!
|
||||
if (!$GLOBALS['user']->has_access('50')) { access_denied(); break; }
|
||||
|
||||
// Setup the object
|
||||
$localplay = new Localplay($GLOBALS['user']->prefs['localplay_controller']);
|
||||
$localplay->add_instance($_POST);
|
||||
break;
|
||||
case 'delete_song':
|
||||
$song_id = scrub_in($_REQUEST['song_id']);
|
||||
|
|
|
@ -65,44 +65,6 @@ class AmpacheMpd extends localplay_controller {
|
|||
|
||||
} // get_version
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public 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
|
||||
|
||||
/**
|
||||
* is_installed
|
||||
* This returns true or false if MPD controller is installed
|
||||
|
@ -129,12 +91,13 @@ class AmpacheMpd extends localplay_controller {
|
|||
"`host` VARCHAR( 255 ) NOT NULL , " .
|
||||
"`port` INT( 11 ) UNSIGNED NOT NULL DEFAULT '6600', " .
|
||||
"`password` VARCHAR( 255 ) NOT NULL , " .
|
||||
"`access` SMALLINT( 4 ) UNSIGNED NOT NULL DEFAULT '0', " .
|
||||
"`access` SMALLINT( 4 ) UNSIGNED NOT NULL DEFAULT '0'" .
|
||||
") ENGINE = MYISAM";
|
||||
$db_results = Dba::query($sql);
|
||||
|
||||
// Add an internal preference for the users current active instance
|
||||
Preference::insert('mpd_active','MPD Active Instance','0','25','integer','internal');
|
||||
User::rebuild_all_preferences();
|
||||
|
||||
return true;
|
||||
|
||||
|
@ -149,6 +112,8 @@ class AmpacheMpd extends localplay_controller {
|
|||
$sql = "DROP TABLE `localplay_mpd`";
|
||||
$db_results = Dba::query($sql);
|
||||
|
||||
Preference::delete('mpd_active');
|
||||
|
||||
return true;
|
||||
|
||||
} // uninstall
|
||||
|
@ -159,7 +124,27 @@ class AmpacheMpd extends localplay_controller {
|
|||
*/
|
||||
public function add_instance($data) {
|
||||
|
||||
foreach ($data as $key=>$value) {
|
||||
switch ($key) {
|
||||
case 'name':
|
||||
case 'hostname':
|
||||
case 'port':
|
||||
case 'password':
|
||||
${$key} = Dba::escape($value);
|
||||
break;
|
||||
default:
|
||||
|
||||
break;
|
||||
} // end switch
|
||||
} // end foreach
|
||||
|
||||
$user_id = Dba::escape($GLOBALS['user']->id);
|
||||
|
||||
$sql = "INSERT INTO `localplay_mpd` (`name`,`host`,`port`,`password`,`owner`) " .
|
||||
"VALUES ('$name','$hostname','$port','$password','$user_id')";
|
||||
$db_results = Dba::query($sql);
|
||||
|
||||
return $db_results;
|
||||
|
||||
} // add_instance
|
||||
|
||||
|
@ -179,6 +164,16 @@ class AmpacheMpd extends localplay_controller {
|
|||
*/
|
||||
public function get_instances() {
|
||||
|
||||
$sql = "SELECT * FROM `localplay_mpd`";
|
||||
$db_results = Dba::query($sql);
|
||||
|
||||
$results = array();
|
||||
|
||||
while ($row = Dba::fetch_assoc($db_results)) {
|
||||
$results[$row['id']] = $row['name'];
|
||||
}
|
||||
|
||||
return $results;
|
||||
|
||||
} // get_instances
|
||||
|
||||
|
@ -189,7 +184,12 @@ class AmpacheMpd extends localplay_controller {
|
|||
*/
|
||||
public function instance_fields() {
|
||||
|
||||
$fields['name'] = array('description'=>_('Instance Name'),'type'=>'textbox');
|
||||
$fields['hostname'] = array('description'=>_('Hostname'),'type'=>'textbox');
|
||||
$fields['port'] = array('description'=>_('Port'),'type'=>'textbox');
|
||||
$fields['password'] = array('description'=>_('Password'),'type'=>'textbox');
|
||||
|
||||
return $fields;
|
||||
|
||||
} // instance_fields
|
||||
|
||||
|
|
|
@ -266,10 +266,10 @@ else {
|
|||
} // else not downsampling
|
||||
|
||||
// We need to check to see if they are rate limited
|
||||
$chunk_size = '4096';
|
||||
$chunk_size = '2084';
|
||||
|
||||
// Attempted fix, pimp up the size a bit
|
||||
$song->size = $song->size + ($chunk_size*2);
|
||||
$song->size = $song->size;
|
||||
|
||||
// Put this song in the now_playing table
|
||||
insert_now_playing($song->id,$uid,$song->time,$sid);
|
||||
|
@ -299,11 +299,11 @@ $bytesStreamed = 0;
|
|||
$minBytesStreamed = $song->size / 2;
|
||||
|
||||
// Actually do the streaming
|
||||
while (!feof($fp) && (connection_status() == 0)) {
|
||||
do {
|
||||
$buf = fread($fp, $chunk_size);
|
||||
print($buf);
|
||||
$bytesStreamed += $chunk_size;
|
||||
}
|
||||
} while (!feof($fp) && (connection_status() == 0));
|
||||
|
||||
// Make sure that a good chunk of the song has been played
|
||||
if ($bytesStreamed > $minBytesStreamed) {
|
||||
|
|
|
@ -26,6 +26,10 @@ if (AJAX_INCLUDE != '1') { exit; }
|
|||
|
||||
switch ($_REQUEST['action']) {
|
||||
case 'set_instance':
|
||||
// Make sure they they are allowed to do this
|
||||
//... ok I don't really know what that means yet
|
||||
|
||||
Preference::update('mpd_active',$GLOBALS['user']->id,$_REQUEST['instance']);
|
||||
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -22,5 +22,19 @@
|
|||
|
||||
?>
|
||||
<?php show_box_top(_('Add Localplay Instance')); ?>
|
||||
|
||||
<form method="post" action="<?php echo Config::get('web_path'); ?>/localplay.php?action=add_instance">
|
||||
<table border="0" cellpadding="3" cellspacing="0" class="table-data">
|
||||
<?php foreach ($fields as $key=>$field) { ?>
|
||||
<tr>
|
||||
<td><?php echo $field['description']; ?></td>
|
||||
<td><input type="textbox" name="<?php echo $key; ?>" /></td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<input type="submit" value="<?php echo _('Add Instance'); ?>" />
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
<?php show_box_bottom(); ?>
|
||||
|
|
|
@ -33,7 +33,7 @@ foreach ($controllers as $controller) {
|
|||
$localplay = new Localplay($controller);
|
||||
if (!$localplay->player_loaded()) { continue; }
|
||||
$localplay->format();
|
||||
if ($localplay->is_enabled()) {
|
||||
if (Localplay::is_enabled($controller)) {
|
||||
$action = 'confirm_uninstall_localplay';
|
||||
$action_txt = _('Disable');
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ foreach ($controllers as $controller) {
|
|||
<td><?php echo scrub_out($localplay->f_name); ?></td>
|
||||
<td><?php echo scrub_out($localplay->f_description); ?></td>
|
||||
<td><?php echo scrub_out($localplay->f_version); ?></td>
|
||||
<td><a href="<?php echo $web_path; ?>/admin/modules.php?action=<?php echo $action; ?>&type="<?php urlencode($localplay->type); ?>"><?php echo $action_txt; ?></a></td>
|
||||
<td><a href="<?php echo $web_path; ?>/admin/modules.php?action=<?php echo $action; ?>&type=<?php echo urlencode($controller); ?>"><?php echo $action_txt; ?></a></td>
|
||||
</tr>
|
||||
<?php } if (!count($controllers)) { ?>
|
||||
<tr class="<?php echo flip_class(); ?>">
|
||||
|
|
|
@ -1,12 +1,26 @@
|
|||
<ul class="sb2" id="sb_localplay">
|
||||
<?php if (Config::get('allow_localplay_playback')) { ?>
|
||||
<?php if ($GLOBALS['user']->has_access('50')) { ?>
|
||||
<li><h4><?php echo _('Localplay'); ?></h4>
|
||||
<ul class="sb3" id="sb_localplay_info">
|
||||
<li id="sb_localplay_info_add_instance"><a href="<?php echo $web_path; ?>/localplay.php?action=show_add_instance"><?php echo _('Add Instance'); ?></a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<?php } ?>
|
||||
<li><h4><?php echo _('Active Instance'); ?></h4>
|
||||
<ul class="sb3" id="sb_localplay_instances">
|
||||
<li id="sb_localplay_instances_none"><?php echo Ajax::text('?page=localplay&action=set_instance&instance=0',_('None'),'localplay_instance_none'); ?></li>
|
||||
<?php
|
||||
// Requires a little work.. :(
|
||||
$localplay = new Localplay($GLOBALS['user']->prefs['localplay_controller']);
|
||||
$instances = $localplay->get_instances();
|
||||
foreach ($instances as $uid=>$name) {
|
||||
?>
|
||||
<li id="sb_localplay_instances_<?php echo $uid; ?>"><?php echo Ajax::text('?page=localplay&action=set_instance&instance=' . $uid,$name,'localplay_instance_' . $uid); ?></li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
</li>
|
||||
<?php } else { ?>
|
||||
<li><h4><?php echo _('Localplay Disabled'); ?></h4></li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
|
|
|
@ -15,6 +15,7 @@ $catagories = Preference::get_catagories();
|
|||
?>
|
||||
<li id="sb_preferences_sections_<?php echo $f_name; ?>"><a href="<?php echo $web_path; ?>/preferences.php?tab=<?php echo $name; ?>"><?php echo _($f_name); ?></a></li>
|
||||
<?php } ?>
|
||||
<li id="sb_preferences_sections_account"><a href="<?php echo $web_path; ?>/preferences.php?tab=account"><?php echo _('Account'); ?></a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<?php if ($GLOBALS['user']->has_access('100')) { ?>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue