mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-05 10:49:37 +02:00
When updating an remote catalog it will try to grab the images from the remote machine to the local database.
This commit is contained in:
parent
efa0fda4ff
commit
e415574302
3 changed files with 162 additions and 25 deletions
|
@ -31,7 +31,11 @@ define('NO_SESSION','1');
|
|||
require 'lib/init.php';
|
||||
|
||||
// Check to see if they've got an interface session or a valid API session, if not GTFO
|
||||
if (!vauth::session_exists('interface',$_COOKIE[Config::get('session_name')]) AND !vauth::session_exists('api',$_REQUEST['auth'])) {
|
||||
if ( !vauth::session_exists('interface',$_COOKIE[Config::get('session_name')])
|
||||
AND !vauth::session_exists('api',$_REQUEST['auth'])
|
||||
AND !vauth::session_exists('xml-rpc',$_REQUEST['auth'])
|
||||
)
|
||||
{
|
||||
debug_event('DENIED','Image Access, Checked Cookie Session and Auth:' . $_REQUEST['auth'],'1');
|
||||
exit;
|
||||
}
|
||||
|
|
|
@ -1299,7 +1299,13 @@ class Catalog {
|
|||
|
||||
echo "<p>" . _('Completed updating remote catalog(s)') . ".</p><hr />\n";
|
||||
flush();
|
||||
|
||||
|
||||
// Try to sync the album images from the remote catalog
|
||||
echo "<p>" . _('Starting synchronisation of album images') . ".</p><br />\n";
|
||||
$this->get_remote_album_images($client, $token);
|
||||
echo "<p>" . _('Completed synchronisation of album images') . ".</p><hr />\n";
|
||||
flush();
|
||||
|
||||
// Update the last update value
|
||||
$this->update_last_update();
|
||||
|
||||
|
@ -1345,6 +1351,39 @@ class Catalog {
|
|||
|
||||
} // get_remote_song
|
||||
|
||||
/**
|
||||
* get_album_images
|
||||
* This function retrieves the album information from the remote server
|
||||
*/
|
||||
public function get_remote_album_images($client,$token,$start,$end) {
|
||||
|
||||
$encoded_key = new XML_RPC_Value($token,'string');
|
||||
$query_array = array($encoded_key);
|
||||
$xmlrpc_message = new XML_RPC_Message('xmlrpcserver.get_album_images',$query_array);
|
||||
|
||||
/* Depending upon the size of the target catalog this can be a very slow/long process */
|
||||
set_time_limit(0);
|
||||
|
||||
// Sixty Second time out per chunk
|
||||
$response = $client->send($xmlrpc_message,60);
|
||||
$value = $response->value();
|
||||
|
||||
if ( !$response->faultCode() ) {
|
||||
$data = XML_RPC_Decode($value);
|
||||
$total = $this->update_remote_album_images($data, $client->server, $token);
|
||||
echo _('images synchronized: ') . ' ' . $total . "<br />";
|
||||
flush();
|
||||
}
|
||||
else {
|
||||
$error_msg = _('Error connecting to') . " " . $server . " " . _("Code") . ": " . $response->faultCode() . " " . _("Reason") . ": " . $response->faultString();
|
||||
debug_event('XMLCLIENT',$error_msg,'1');
|
||||
echo "<p class=\"error\">$error_msg</p>";
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
} // get_album_images
|
||||
|
||||
/**
|
||||
* update_remote_catalog
|
||||
* actually updates from the remote data, takes an array of songs that are base64 encoded and parses them
|
||||
|
@ -1382,6 +1421,63 @@ class Catalog {
|
|||
|
||||
} // update_remote_catalog
|
||||
|
||||
/*
|
||||
* update_remote_album_images
|
||||
* actually synchronize the album images
|
||||
* @package XMLRPC
|
||||
* @catagory Client
|
||||
*/
|
||||
function update_remote_album_images($data, $remote_server, $auth) {
|
||||
$label = "catalog.class.php::update_remote_album_images";
|
||||
|
||||
$total_updated = 0;
|
||||
|
||||
/*
|
||||
* We need to check the incomming albums to see which needs to receive an image
|
||||
*/
|
||||
foreach ($data as $serialized_album) {
|
||||
|
||||
// Prevent a timeout
|
||||
set_time_limit(0);
|
||||
|
||||
// Load the remote album
|
||||
$remote_album = new Album();
|
||||
$remote_album = unserialize($serialized_album);
|
||||
$remote_album->format(); //this will set the fullname
|
||||
|
||||
$debug_text = "remote_album id, name, year: ";
|
||||
$debug_text.= $remote_album->id . ", " . $remote_album->name . ", " . $remote_album->year;
|
||||
debug_event($label, $debug_text, '4');
|
||||
|
||||
// check the album if it exists by checking the name and the year of the album
|
||||
$local_album_id = self::check_album($remote_album->name, $remote_album->year,"", true);
|
||||
debug_event($label, "local_album_id: " . $local_album_id, '4');
|
||||
|
||||
if ($local_album_id != 0) {
|
||||
// Local album found lets add the cover
|
||||
$server_path = "http://" . ltrim($remote_server, "http://");
|
||||
$server_path.= "/image.php?id=" . $remote_album->id;
|
||||
$server_path.= "&auth=" . $auth;
|
||||
debug_event($label, "image_url: " . $server_path,'4');
|
||||
$data['url'] = $server_path;
|
||||
|
||||
$local_album = new Album($local_album_id);
|
||||
$image_data = $local_album->get_image_from_source($data);
|
||||
|
||||
// If we got something back insert it
|
||||
if ($image_data) {
|
||||
$local_album->insert_art($image_data,"");
|
||||
$total_updated++;
|
||||
debug_event($label, "adding album image succes", '4');
|
||||
} else {
|
||||
debug_event($label, "adding album image failed ", '4');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $total_updated;
|
||||
|
||||
} // update_remote_album_images
|
||||
|
||||
/**
|
||||
* clean_catalog
|
||||
|
@ -1912,7 +2008,7 @@ class Catalog {
|
|||
}
|
||||
|
||||
/* Setup the Query */
|
||||
$sql = "SELECT `id` FROM `album` WHERE `name` = '$album'";
|
||||
$sql = "SELECT `id` FROM `album` WHERE trim(`name`) = '$album'";
|
||||
if ($album_year) { $sql .= " AND `year`='$album_year'"; }
|
||||
if ($album_disk) { $sql .= " AND `disk`='$album_disk'"; }
|
||||
if ($prefix) { $sql .= " AND `prefix`='" . Dba::escape($prefix) . "'"; }
|
||||
|
|
|
@ -68,6 +68,8 @@ class xmlRpcServer {
|
|||
return new XML_RPC_Response($encoded_array);
|
||||
} // get_catalogs
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* get_songs
|
||||
* This is a basic function to return all of the song data in a serialized format. It takes a start and end point
|
||||
|
@ -80,15 +82,15 @@ class xmlRpcServer {
|
|||
set_time_limit(0);
|
||||
|
||||
|
||||
// Pull out the key
|
||||
$variable = $xmlrpc_object->getParam(0);
|
||||
$key = $variable->scalarval();
|
||||
// Pull out the key
|
||||
$variable = $xmlrpc_object->getParam(0);
|
||||
$key = $variable->scalarval();
|
||||
|
||||
// Check it and make sure we're super green
|
||||
if (!vauth::session_exists('xml-rpc',$key)) {
|
||||
debug_event('XMLSERVER','Error ' . $_SERVER['REMOTE_ADDR'] . ' with key ' . $key . ' does not match any ACLs','1');
|
||||
return new XML_RPC_Response(0,'503','Key/IP Mis-match Access Denied');
|
||||
}
|
||||
// Check it and make sure we're super green
|
||||
if (!vauth::session_exists('xml-rpc',$key)) {
|
||||
debug_event('XMLSERVER','Error ' . $_SERVER['REMOTE_ADDR'] . ' with key ' . $key . ' does not match any ACLs','1');
|
||||
return new XML_RPC_Response(0,'503','Key/IP Mis-match Access Denied');
|
||||
}
|
||||
|
||||
// Now pull out the start and end
|
||||
$start = intval($xmlrpc_object->params['1']->me['int']);
|
||||
|
@ -125,21 +127,61 @@ class xmlRpcServer {
|
|||
|
||||
} // get_songs
|
||||
|
||||
/**
|
||||
* get_album_images
|
||||
* Returns the images information of the albums
|
||||
*/
|
||||
public static function get_album_images($xmlrpc_object) {
|
||||
// We're going to be here a while
|
||||
set_time_limit(0);
|
||||
|
||||
// Pull out the key
|
||||
$variable = $xmlrpc_object->getParam(0);
|
||||
$key = $variable->scalarval();
|
||||
|
||||
// Check it and make sure we're super green
|
||||
if (!vauth::session_exists('xml-rpc',$key)) {
|
||||
debug_event('XMLSERVER','Error ' . $_SERVER['REMOTE_ADDR'] . ' with key ' . $key . ' does not match any ACLs','1');
|
||||
return new XML_RPC_Response(0,'503','Key/IP Mis-match Access Denied');
|
||||
}
|
||||
|
||||
// Get Albums first
|
||||
$sql = "SELECT `album`.`id` FROM `album` ";
|
||||
$db_results = Dba::query($sql);
|
||||
|
||||
while ($row = Dba::fetch_assoc($db_results)) {
|
||||
// Load the current album
|
||||
$album = new Album($row['id']);
|
||||
$art = $album->get_db_art();
|
||||
|
||||
// Only return album ids with art
|
||||
if (count($art) != 0) {
|
||||
$output = serialize($album);
|
||||
$results[] = $output;
|
||||
}
|
||||
}
|
||||
|
||||
$encoded_array = XML_RPC_encode($results);
|
||||
debug_event('XMLSERVER','Encoded ' . count($results) . 'albums with art','5');
|
||||
|
||||
return new XML_RPC_Response($encoded_array);
|
||||
}
|
||||
|
||||
/**
|
||||
* create_stream_session
|
||||
* This creates a new stream session and returns the SID in question, this requires a TOKEN as generated by the handshake
|
||||
*/
|
||||
public static function create_stream_session($xmlrpc_object) {
|
||||
|
||||
// Pull out the key
|
||||
$variable = $xmlrpc_object->getParam(0);
|
||||
$key = $variable->scalarval();
|
||||
// Pull out the key
|
||||
$variable = $xmlrpc_object->getParam(0);
|
||||
$key = $variable->scalarval();
|
||||
|
||||
// Check it and make sure we're super green
|
||||
if (!vauth::session_exists('xml-rpc',$key)) {
|
||||
debug_event('XMLSERVER','Error ' . $_SERVER['REMOTE_ADDR'] . ' with key ' . $key . ' does not match any ACLs','1');
|
||||
return new XML_RPC_Response(0,'503','Key/IP Mis-match Access Denied');
|
||||
}
|
||||
// Check it and make sure we're super green
|
||||
if (!vauth::session_exists('xml-rpc',$key)) {
|
||||
debug_event('XMLSERVER','Error ' . $_SERVER['REMOTE_ADDR'] . ' with key ' . $key . ' does not match any ACLs','1');
|
||||
return new XML_RPC_Response(0,'503','Key/IP Mis-match Access Denied');
|
||||
}
|
||||
|
||||
if (!Stream::insert_session($key,'-1')) {
|
||||
debug_event('XMLSERVER','Failed to create stream session','1');
|
||||
|
@ -155,12 +197,7 @@ class xmlRpcServer {
|
|||
* used in all further communication
|
||||
*/
|
||||
public static function handshake($xmlrpc_object) {
|
||||
/*
|
||||
ob_start();
|
||||
print_r ($xmlrpc_object);
|
||||
$got = ob_get_clean();
|
||||
debug_event('XMLSERVER','handshake: ' . $got,'1');
|
||||
*/
|
||||
debug_event('XMLSERVER','handshake: ' . print_r ($xmlrpc_object, true),'5');
|
||||
|
||||
// Pull out the params
|
||||
$encoded_key = $xmlrpc_object->params['0']->me['string'];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue