summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordipsol <dipsol@ampache>2008-12-11 15:21:07 +0000
committerdipsol <dipsol@ampache>2008-12-11 15:21:07 +0000
commite415574302f507405c85daf96e050e07ce54d5cc (patch)
treecca1097a9497a4da505766b8fba23784b326b878
parentefa0fda4ff3133e15c79489e49258247182e3c50 (diff)
downloadampache-e415574302f507405c85daf96e050e07ce54d5cc.tar.gz
ampache-e415574302f507405c85daf96e050e07ce54d5cc.tar.bz2
ampache-e415574302f507405c85daf96e050e07ce54d5cc.zip
When updating an remote catalog it will try to grab the images from the remote machine to the local database.
-rw-r--r--image.php6
-rw-r--r--lib/class/catalog.class.php100
-rw-r--r--lib/class/xmlrpcserver.class.php83
3 files changed, 163 insertions, 26 deletions
diff --git a/image.php b/image.php
index 077133b8..53ff786d 100644
--- a/image.php
+++ b/image.php
@@ -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;
}
diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php
index 14e661e8..7dd65a2b 100644
--- a/lib/class/catalog.class.php
+++ b/lib/class/catalog.class.php
@@ -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();
@@ -1346,6 +1352,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
* @package XMLRPC
@@ -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) . "'"; }
diff --git a/lib/class/xmlrpcserver.class.php b/lib/class/xmlrpcserver.class.php
index a5687c21..1d66dfd2 100644
--- a/lib/class/xmlrpcserver.class.php
+++ b/lib/class/xmlrpcserver.class.php
@@ -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();
-
- // 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');
- }
+ // 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');
+ }
// Now pull out the start and end
$start = intval($xmlrpc_object->params['1']->me['int']);
@@ -126,20 +128,60 @@ 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'];