diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2010-02-05 01:29:20 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2010-02-05 01:29:20 +0000 |
commit | 24761d3863f9d3bd93ca915cb665764ed041ebe4 (patch) | |
tree | 2ff1e79e2d26c8dc6b73638f507962196f26f251 | |
parent | 68aca7623155d1a8365e098e1fa738582dd0d1bc (diff) | |
download | ampache-24761d3863f9d3bd93ca915cb665764ed041ebe4.tar.gz ampache-24761d3863f9d3bd93ca915cb665764ed041ebe4.tar.bz2 ampache-24761d3863f9d3bd93ca915cb665764ed041ebe4.zip |
Removed dead xmlrpc files, started work migrating to LastFM v2.0 api
-rw-r--r-- | lib/class/album.class.php | 2 | ||||
-rw-r--r-- | lib/class/xmlrpcclient.class.php | 137 | ||||
-rw-r--r-- | lib/class/xmlrpcserver.class.php | 270 | ||||
-rw-r--r-- | modules/infotools/lastfm.class.php | 30 | ||||
-rw-r--r-- | server/xml.server.php | 4 | ||||
-rw-r--r-- | templates/show_login_form.inc.php | 2 |
6 files changed, 30 insertions, 415 deletions
diff --git a/lib/class/album.class.php b/lib/class/album.class.php index 20658a3d..6abd8412 100644 --- a/lib/class/album.class.php +++ b/lib/class/album.class.php @@ -385,7 +385,7 @@ class Album extends database_object { debug_event("lastfm", "set Proxy", "5"); $lastfm->setProxy($proxyhost, $proxyport, $proxyuser, $proxypass); } - $raw_data = $lastfm->search($artist,$album); + $raw_data = $lastfm->album_search($artist,$album); if (!count($raw_data)) { return array(); } diff --git a/lib/class/xmlrpcclient.class.php b/lib/class/xmlrpcclient.class.php deleted file mode 100644 index 49bf4439..00000000 --- a/lib/class/xmlrpcclient.class.php +++ /dev/null @@ -1,137 +0,0 @@ -<?php -/* - - Copyright (c) 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. - -*/ - -/** - * xmlRpcClient - * This is the other half of the xmlrpcserver class, it Holds the different calls that Ampache might - * make that are xmlrpc'ie this does not include the API responses. - */ - -class xmlRpcClient { - /** - * construtor - * not used - */ - private function __construct() { - - // Rien a faire - - } // constructor - - /** - * ampache_handshake - * This handshakes with ampache servers, this is used by the internal xml-rpc mojo - */ - public static function ampache_handshake($target_url,$key) { - - // Generate the client - $client = self::create_client($target_url); - - // 6 that's right, the secret level because if you do have debug on most likely you're - // going to just crash your browser... sorry folks - if (Config::get('debug') AND Config::get('debug_level') == '6') { $client->setDebug(1); } - - // Build our key - $timestamp = time(); - $handshake_key = hash('sha256',$timestamp . hash('sha256',$key)); - - $encoded_key = new XML_RPC_Value($handshake_key,'string'); - $timestamp = new XML_RPC_Value($timestamp,'int'); - $xmlrpc_message = new XML_RPC_Message('xmlrpcserver.handshake',array($encoded_key,$timestamp)); - - // Send it off - $response = $client->send($xmlrpc_message,10); - - if ($response->faultCode()) { - $error_msg = _('Error connecting to') . " " . $client->server . " " . _("Code") . ": " . $response->faultCode() . " " . _("Reason") . ": " . $response->faultString(); - debug_event('XMLCLIENT',$error_msg,'1'); - Error::add('general',$error_msg); - return; - } - - $token = XML_RPC_Decode($response->value()); - - debug_event('XML-RPC',$token . ' returned from ' . $client->server,'3'); - - return $token; - - } // ampache_handshake - - /** - * ampache_create_stream_session - * This generates a new stream session, it takes a target_url and a token as generated by - * a ampache_handshake action - */ - public static function ampache_create_stream_session($target_url,$token) { - - $client = self::create_client($target_url); - - // 6 that's right, the secret level because if you do have debug on most likely you're - // going to just crash your browser... sorry folks - if (Config::get('debug') AND Config::get('debug_level') == '6') { $client->setDebug(1); } - - $encoded_key = new XML_RPC_Value($token,'string'); - $xmlrpc_message = new XML_RPC_Message('xmlrpcserver.create_stream_session',array($encoded_key)); - - $response = $client->send($xmlrpc_message,4); - - if ($response->faultCode() ) { - $error_msg = _("Error connecting to") . " " . $client->server . " " . _("Code") . ": " . $response->faultCode() . " " . - debug_event('XMLCLIENT',$error_msg,'1'); - return false; - } - - $sid = XML_RPC_Decode($response->value()); - - debug_event('XML-RPC', $sid . ' stream session ID returned from ' . $client->server,'3'); - - return $sid; - - } // ampache_create_stream_session - - /** - * create_client - * This creates the xmlrpc client object from a URL - */ - public static function create_client($target_url) { - - // Figure out the host etc - preg_match("/http:\/\/([^\/\:]+):?(\d*)\/*(.*)/", $target_url, $match); - $server = $match['1']; - $port = $match['2'] ? intval($match['2']) : '80'; - $path = $match['3']; - if(Config::get('proxy_host') AND Config::get('proxy_port')) { - $proxy_host = Config::get('proxy_host'); - $proxy_port = Config::get('proxy_port'); - $proxy_user = Config::get('proxy_user'); - $proxy_pass = Config::get('proxy_pass'); - } - - $full_url = "/" . ltrim($path . "/server/xmlrpc.server.php",'/'); - - $client = new XML_RPC_Client($full_url,$server,$port,$proxy_host,$proxy_port,$proxy_user,$proxy_pass); - - return $client; - - } // create_client - -} // xmlRpcClient -?> diff --git a/lib/class/xmlrpcserver.class.php b/lib/class/xmlrpcserver.class.php deleted file mode 100644 index 49ca7e50..00000000 --- a/lib/class/xmlrpcserver.class.php +++ /dev/null @@ -1,270 +0,0 @@ -<?php -/* - - Copyright (c) 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. - -*/ - -/** - * xmlRpcServer - * This class contains all the methods that the /server/xmlrpc.server.php will respond to - * to add a new method, just define a new public static function in here and it will be automagicaly - * populated to xmlrpcserver.<FUNCTION> in /server/xmlrpc.server.php - */ - -class xmlRpcServer { - - /** - * get_catalogs - * This returns a list of the current non-remote catalogs hosted on this Ampache instance - * It requires a key be passed as the first element - * //FIXME: USE TOKEN! - */ - public static function get_catalogs($xmlrpc_object) { - - // 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'); - } - - // Go ahead and gather up the information they are legit - $results = array(); - - $sql = "SELECT `catalog`.`name`,COUNT(`song`.`id`) AS `count`,`catalog`.`id` AS `catalog_id` FROM `catalog` ". - "LEFT JOIN `song` ON `catalog`.`id`=`song`.`catalog` WHERE `catalog`.`catalog_type`='local' " . - "GROUP BY `catalog`.`id`"; - $db_results = Dba::read($sql); - - while ($row = Dba::fetch_assoc($db_results)) { - $results[] = $row; - } - - // We need to set time limit at this point as who know how long this data is going to take - // to return to the client - set_time_limit(0); - - $encoded_array = XML_RPC_encode($results); - debug_event('XMLSERVER','Returning data about ' . count($results) . ' catalogs to ' . $_SERVER['REMOTE_ADDR'],'5'); - - 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 - * as well as the TOKEN for auth mojo - * //FIXME: USE TOKEN! - */ - public static function get_songs($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'); - } - - // Now pull out the start and end - $start = intval($xmlrpc_object->params['1']->me['int']); - $end = intval($xmlrpc_object->params['2']->me['int']); - - // Get Catalogs first - $sql = "SELECT `catalog`.`id` FROM `catalog` WHERE `catalog`.`catalog_type`='local'"; - $db_results = Dba::read($sql); - - while ($row = Dba::fetch_assoc($db_results)) { - $where_sql .= "`song`.`catalog`='" . $row['id'] . "' OR"; - } - - $where_sql = rtrim($where_sql,'OR'); - - $sql = "SELECT `song`.`id` FROM `song` WHERE `song`.`enabled`='1' AND ($where_sql) LIMIT $start,$end"; - $db_results = Dba::read($sql); - - while ($row = Dba::fetch_assoc($db_results)) { - $song = new Song($row['id']); - $song->fill_ext_info(); - $song->album = $song->get_album_name(); - $song->artist = $song->get_artist_name(); - //$song->genre = $song->get_genre_name(); // TODO: Needs to be implemented - - $output = serialize($song); - $results[] = $output ; - } // end while - - $encoded_array = XML_RPC_encode($results); - debug_event('XMLSERVER','Encoded ' . count($results) . ' songs (' . $start . ',' . $end . ')','5'); - - return new XML_RPC_Response($encoded_array); - - } // 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::read($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(); - - // 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'); - return new XML_RPC_Response(0,'503','Failed to Create Stream Session','1'); - } - - return new XML_RPC_Response(XML_RPC_encode($key)); - } // create_stream_session - - /** - * check_song - * This checks remote catalog - */ - public static function check_song($xmlrpc_object) { - - // Pull out the key - $variable = $xmlrpc_object->getParam(1); - $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'); - } - - $var = $xmlrpc_object->params['0']->me['int']; - $sql = "SELECT `song`.`id` FROM `song` WHERE `id`='" . Dba::escape($var) ."'"; - $db_results = Dba::read($sql); - if(Dba::num_rows($db_results) == '0') { - $return = 0; - } else { - $return = 1; - } - - return new XML_RPC_Response(XML_RPC_encode($return)); - - } - - /** - * handshake - * This should be run before any other XMLRPC actions, it checks the KEY encoded with a timestamp then returns a valid TOKEN to be - * used in all further communication - */ - public static function handshake($xmlrpc_object) { - debug_event('XMLSERVER','handshake: ' . print_r ($xmlrpc_object, true),'5'); - - // Pull out the params - $encoded_key = $xmlrpc_object->params['0']->me['string']; - $timestamp = $xmlrpc_object->params['1']->me['int']; - - // Check the timestamp make sure it's recent - if ($timestamp < (time() - 14400)) { - debug_event('XMLSERVER','Handshake failure, timestamp too old','1'); - return new XML_RPC_Response(0,'503','Handshake failure, timestamp too old'); - } - - // Log the attempt - debug_event('XMLSERVER','Login Attempt, IP: ' . $_SERVER['REMOTE_ADDR'] . ' Time: ' . $timestamp . ' Hash:' . $encoded_key,'1'); - - // Convert the IP Address to an int - $ip = Dba::escape(inet_pton($_SERVER['REMOTE_ADDR'])); - - // Run the query and return the key's for ACLs of type RPC that would match this IP - $sql = "SELECT * FROM `access_list` WHERE `type`='rpc' AND `start` <= '$ip' AND `end` >= '$ip'"; - $db_results = Dba::read($sql); - - while ($row = Dba::fetch_assoc($db_results)) { - - // Build our encoded passphrase - $sha256pass = hash('sha256',$timestamp . hash('sha256',$row['key'])); - if ($sha256pass == $encoded_key) { - $data['type'] = 'xml-rpc'; - $data['username'] = 'System'; - $data['value'] = 'Handshake'; - $token = vauth::session_create($data); - - return new XML_RPC_Response(XML_RPC_encode($token)); - } - - } // end while rows - - return new XML_RPC_Response(0,'503', 'Handshake failure, Key/IP Incorrect'); - - } // handshake - -} // xmlRpcServer -?> diff --git a/modules/infotools/lastfm.class.php b/modules/infotools/lastfm.class.php index cc6f84a1..35cb0881 100644 --- a/modules/infotools/lastfm.class.php +++ b/modules/infotools/lastfm.class.php @@ -23,6 +23,8 @@ class LastFMSearch {
protected $base_url = "http://ws.audioscrobbler.com/1.0/album";
+ protected $base_url_v2 = "http://ws.audioscrobbler.com/2.0/";
+ protected $api_key = "d5df942424c71b754e54ce1832505ae2";
public $results=array(); // Array of results
private $_parser; // The XML parser
protected $_grabtags = array('coverart','large','medium','small');
@@ -113,20 +115,40 @@ class LastFMSearch { } // run_search
/**
- * search
+ * album_search
* takes terms and a type
*/
- public function search($artist,$album) {
+ public function album_search($artist,$album) {
$url = $this->base_url . '/' . urlencode($artist) . '/' . urlencode($album) . '/info.xml';
- debug_event('lastfm','Searching: ' . $url,'3');
+ debug_event('LastFM','Album Search: ' . $url,'3');
$this->run_search($url);
return $this->results;
- } // search
+ } // album_search
+
+ /**
+ * artist_search
+ * Search for an artists information!
+ * This uses v2 of the API, need to update the rest of this class to use v2
+ */
+ public function artist_search($artist) {
+
+ $url = $this->base_url_v2 . '/?method=artist.getImages&artist=' . urlencode($artist) . '&limit=10';
+
+ //FIXME: This should be done by run_search
+ $url .= '&api=' . urlencode($this->api_key);
+
+ debug_event('LastFM','Album Search: ' . $url,'3');
+
+ $this->run_search($url);
+
+ return $this->results;
+
+ } // artist_search
/**
* start_element
diff --git a/server/xml.server.php b/server/xml.server.php index 81153a69..cc7a68cf 100644 --- a/server/xml.server.php +++ b/server/xml.server.php @@ -81,8 +81,8 @@ foreach ($methods as $method) { // If the method is the same as the action being called // Then let's call this function! - if ($_REQUEST['action'] == $method) { - call_user_func(array('api',$method),$_REQUEST); + if ($_GET['action'] == $method) { + call_user_func(array('api',$method),$_GET); // We only allow a single function to be called, and we assume it's cleaned up! exit; } diff --git a/templates/show_login_form.inc.php b/templates/show_login_form.inc.php index d195faad..d9f89b74 100644 --- a/templates/show_login_form.inc.php +++ b/templates/show_login_form.inc.php @@ -96,7 +96,7 @@ if (@is_readable(Config::get('prefix') . '/config/motd.php')) { <?php } ?> <div id="footer"> <a href="http://www.ampache.org/index.php">Ampache v.<?php echo Config::get('version'); ?></a><br /> - Copyright (c) 2001 - 2009 Ampache.org + Copyright (c) 2001 - 2010 Ampache.org <?php echo _('Queries:'); ?><?php echo Dba::$stats['query']; ?> <?php echo _('Cache Hits:'); ?><?php echo database_object::$cache_hit; ?> </div> </body> |