diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2009-12-11 17:02:13 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2009-12-11 17:02:13 +0000 |
commit | dbf125ec1594c721ef6253baf9c340289fd586a8 (patch) | |
tree | 39c4f243fa5b0a20b76dd2c06a42a0e536e68338 | |
parent | f035080a1e6b57da59ff4b2320bd79b4bee96d71 (diff) | |
download | ampache-dbf125ec1594c721ef6253baf9c340289fd586a8.tar.gz ampache-dbf125ec1594c721ef6253baf9c340289fd586a8.tar.bz2 ampache-dbf125ec1594c721ef6253baf9c340289fd586a8.zip |
Fix Amazon album art search, requires new config options
-rw-r--r-- | config/ampache.cfg.php.dist | 7 | ||||
-rwxr-xr-x | docs/CHANGELOG | 2 | ||||
-rw-r--r-- | lib/class/album.class.php | 2 | ||||
-rw-r--r-- | modules/infotools/AmazonSearchEngine.class.php | 54 |
4 files changed, 47 insertions, 18 deletions
diff --git a/config/ampache.cfg.php.dist b/config/ampache.cfg.php.dist index 363f135f..99fbe786 100644 --- a/config/ampache.cfg.php.dist +++ b/config/ampache.cfg.php.dist @@ -299,9 +299,12 @@ album_art_order = "db,id3,folder,lastfm" show_album_art = "true" ; Amazon Developer Key -; This is needed in order to actually use the amazon album art +; These are needed in order to actually use the amazon album art +; Your public key is your 'Access Key ID' +; Your private key is your 'Secret Access Key' ; DEFAULT: false -;amazon_developer_key = "" +;amazon_developer_public_key = "" +;amazon_developer_private_key = "" ; Amazon base urls ; An array of Amazon sites to search. diff --git a/docs/CHANGELOG b/docs/CHANGELOG index 8d95ed36..457e63db 100755 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -4,6 +4,8 @@ -------------------------------------------------------------------------- v.3.6-Alpha1 + - Updated Amazon Album art search to current Amazone API specs + (Thx Vlet) - Fix typo that caused song count to not be set on tag xml response - Fix tag methods so that alpha_match and exact_match work - Fix limit and offset not working on search_songs API method diff --git a/lib/class/album.class.php b/lib/class/album.class.php index 5c32ef41..127bcdc8 100644 --- a/lib/class/album.class.php +++ b/lib/class/album.class.php @@ -762,7 +762,7 @@ class Album extends database_object { foreach ($amazon_base_urls AS $amazon_base) { // Create the Search Object - $amazon = new AmazonSearch(Config::get('amazon_developer_key'), $amazon_base); + $amazon = new AmazonSearch(Config::get('amazon_developer_public_key'), Config::get('amazon_developer_private_key'), $amazon_base); if(Config::get('proxy_host') AND Config::get('proxy_port')) { $proxyhost = Config::get('proxy_host'); $proxyport = Config::get('proxy_port'); diff --git a/modules/infotools/AmazonSearchEngine.class.php b/modules/infotools/AmazonSearchEngine.class.php index e94c5d09..e0650c02 100644 --- a/modules/infotools/AmazonSearchEngine.class.php +++ b/modules/infotools/AmazonSearchEngine.class.php @@ -30,8 +30,8 @@ */
class AmazonSearch {
- var $base_url_default = "http://webservices.amazon.com";
- var $url_suffix = "/onca/xml?";
+ var $base_url_default = "webservices.amazon.com";
+ var $url_suffix = "/onca/xml";
var $base_url;
var $search;
var $token;
@@ -54,12 +54,12 @@ class AmazonSearch { /* If we have a base url then use it */
if ($base_url_param != '') {
- $this->base_url = $base_url_param . $this->url_suffix;
+ $this->base_url = str_replace('http://', '', $base_url_param);
debug_event('amazon-search-results','Retrieving from ' . $base_url_param . $this->url_suffix,'5');
}
/* Default Operation */
else {
- $this->base_url=$this->base_url_default . $this->url_suffix;
+ $this->base_url=$this->base_url_default;
debug_event('amazon-search-results','Retrieving from DEFAULT','5');
}
@@ -140,21 +140,45 @@ class AmazonSearch { @discussion takes terms and a type
*/
function search($terms, $type='Music') {
-
- $url = $this->base_url . "Service=AWSECommerceService&SubscriptionId=" . $this->token .
- "&Operation=ItemSearch&Artist=" . urlencode($terms['artist']) . "&Title=" . urlencode($terms['album']) .
- "&Keywords=" . urlencode($terms['keywords']) . "&SearchIndex=" . $type;
+ $params = array();
+
+ $params['Service'] = 'AWSECommerceService';
+ $params['AWSAccessKeyId'] = $this->public_key;
+ $params['Timestamp'] = gmdate("Y-m-d\TH:i:s\Z");
+ $params['Version'] = '2009-03-31';
+ $params['Operation'] = 'ItemSearch';
+ $params['Artist'] = $terms['artist'];
+ $params['Title'] = $terms['album'];
+ $params['Keywords'] = $terms['keywords'];
+ $params['SearchIndex'] = $type;
+
+ ksort($params);
+
+ $canonicalized_query = array();
+
+ foreach ($params as $param => $value)
+ {
+ $param = str_replace("%7E", "~", rawurlencode($param));
+ $value = str_replace("%7E", "~", rawurlencode($value));
- debug_event('amazon-search-results',"_currentPage = " . $this->_currentPage,'3');
- if($this->_currentPage != 0){
- $url = $url . "&ItemPage=" . ($this->_currentPage+1);
- }
+ $canonicalized_query[] = $param."=".$value;
+ }
+
+ $canonicalized_query = implode('&', $canonicalized_query);
+
+ $string_to_sign = 'GET' . "\n" . $this->base_url . "\n" . $this->url_suffix . "\n" . $canonicalized_query;
+
+ $signature = base64_encode(hash_hmac("sha256", $string_to_sign, $this->private_key, True));
+
+ $signature = str_replace("%7E", "~", rawurlencode($signature));
+
+ $url = 'http://' . $this->base_url . $this->url_suffix . '?' . $canonicalized_query . '&Signature=' . $signature;
+
$this->run_search($url);
-
+
unset($this->results['ASIN']);
-
+
return $this->results;
-
} // search
/*!
|