diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2006-01-09 09:08:30 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2006-01-09 09:08:30 +0000 |
commit | 883cd9e478cf740f7b6bdd5fa089c4eefda97b7a (patch) | |
tree | a5cb56cfe02fab83d2c458dc3ad2d227a11605ee | |
parent | 53e05bc90da0864e19eabdea083d32080dbaa283 (diff) | |
download | ampache-883cd9e478cf740f7b6bdd5fa089c4eefda97b7a.tar.gz ampache-883cd9e478cf740f7b6bdd5fa089c4eefda97b7a.tar.bz2 ampache-883cd9e478cf740f7b6bdd5fa089c4eefda97b7a.zip |
added nhorlocs amazon mojo
-rw-r--r-- | config/ampache.cfg.php.dist | 28 | ||||
-rwxr-xr-x | docs/CHANGELOG | 5 | ||||
-rw-r--r-- | lib/class/album.class.php | 47 | ||||
-rw-r--r-- | modules/amazon/AmazonSearchEngine.class.php | 47 |
4 files changed, 107 insertions, 20 deletions
diff --git a/config/ampache.cfg.php.dist b/config/ampache.cfg.php.dist index 85ea7db0..331a57bb 100644 --- a/config/ampache.cfg.php.dist +++ b/config/ampache.cfg.php.dist @@ -204,6 +204,30 @@ play_album_art = "true" # DEFAULT: false #amazon_developer_key = "" +# Amazon base urls +# An array of Amazon sites to search. +# NOTE: This will search each of these sites in turn so don't expect it +# to be lightening fast! +# It is strongly recommended that only one of these is selected at any +# one time +# Default: Just the US (.com) +amazon_base_urls = "http://webservices.amazon.com" +#amazon_base_urls = "http://webservices.amazon.co.uk" +#amazon_base_urls = "http://webservices.amazon.de" +#amazon_base_urls = "http://webservices.amazon.co.jp" +#amazon_base_urls = "http://webservices.amazon.fr" +#amazon_base_urls = "http://webservices.amazon.ca" + +# max_amazon_results_pages +# The maximum number of results pages to pull from EACH amazon site +# NOTE: The art search pages through the results returned by your search +# up to this number of pages. As with the base_urls above, this is going +# to take more time, the more pages you ask it to process. +# Of course a good search will return only a few matches anyway. +# It is strongly recommended that you do _not_ change this value +# DEFAULT: 1 page (10 items) +max_amazon_results_pages = 1 + # Debug # If this is enabled Ampache will get really chatty # warning this can crash browser during catalog builds due to @@ -317,7 +341,7 @@ allow_stream_playback = true ####################################################### # These options control the dynamic downsampling based -* on current useage +# on current useage # *Note* Downsampling must be enabled and working ####################################################### @@ -405,7 +429,7 @@ stream_cmd_m4a = faad -f 2 -w "%FILE%" | lame -r -b %SAMPLE% -S - - # %URL% = url to the song # %AMOUNT% = amount to increase or decrese the volume by (optional) # -# HACK altert - run moosicd as www-data user, and +# HACK alert - run moosicd as www-data user, and # then set the HOME env var so moosic client # can find the folder it needs b4 every call... # Commenting this all out, unless you uncomment it... diff --git a/docs/CHANGELOG b/docs/CHANGELOG index 982599bf..d88c588f 100755 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -3,6 +3,11 @@ -------------------------------------------------------------------------- -------------------------------------------------------------------------- + v.3.3.2-Beta2 + - Added ability to search from non-us amazon webservices website + and retrive more then one page (Thx nhorloc) + +-------------------------------------------------------------------------- v.3.3.2-Beta1 01/08/2006 - Fixed lack of Access List check on download - Fixed Access List so that you can edit existing records diff --git a/lib/class/album.class.php b/lib/class/album.class.php index e6354bd4..22abcfda 100644 --- a/lib/class/album.class.php +++ b/lib/class/album.class.php @@ -407,12 +407,8 @@ class Album { @function find_art @discussion searches amazon or a url for the album art - //FIXME: Rename this POS - - // csammis: To facilitate solution of https://ampache.bountysource.com/Task.View?task_id=86, - // added $artist and $albumname parameters to the method, and reworked the guts of the amazon - // search a little; replaced $this->name with $albumname and $this->artist with $artist. - // See /albums.php, ~line 80, for where these values are coming from. + @patch Added Keyword Support (csammis) + @patch Added Variable Root Amazon Search (nhorloc) */ function find_art($coverurl = '', $keywords = '') { @@ -432,11 +428,40 @@ class Album { /* If this isn't a various album combine with artist name */ if ($this->artist_count == '1') { $keywords .= ' ' . $this->artist; } } + /* Create Base Vars */ + $amazon_base_urls = array(); + + /* Attempt to retrive the album art order */ + $config_value = conf('amazon_base_urls'); + + /* If it's not set */ + if (empty($config_value)) { + /* do nothing for now */ + } + elseif (!is_array($config_value)) { + array_push($amazon_base_urls,$config_value); + } + else { + $amazon_base_urls = array_merge($amazon_base_urls, conf('amazon_base_urls')); + } + + /* Foreach through the base urls that we should check */ + foreach ($amazon_base_urls AS $amazon_base) { // Create the Search Object - $amazon = new AmazonSearch(conf('amazon_developer_key')); - - $search_results = $amazon->search(array('artist' => $artist, 'album' => $albumname, 'keywords' => $keywords)); + $amazon = new AmazonSearch(conf('amazon_developer_key'), $amazon_base); + + /* Setup the needed variables */ + $max_pages_to_search = max(conf('max_amazon_results_pages'),$amazon->_default_results_pages); + $pages_to_search = $max_pages_to_search; //init to max until we know better. + do { + $search_results = array_merge($search_results, $amazon->search(array('artist' => $artist, 'album' => $albumname, 'keywords' => $keywords))); + $pages_to_search = min($max_pages_to_search, $amazon->_maxPage); + if(conf('debug')){ + log_event($GLOBALS['user']->username,'amazon-xml', "Searched results page " . ($amazon->_currentPage+1) . "/" . $pages_to_search); + } + $amazon->_currentPage++; + } while($amazon->_currentPage < $pages_to_search); // Only do the second search if the first actually returns something if (count($search_results)) { @@ -447,12 +472,12 @@ class Album { if (conf('debug')) { log_event($GLOBALS['user']->username,'amazon-xml',"Searched using $keywords with " . conf('amazon_developer_key') . " as key " . count($final_results) . " results found"); } - + } // end foreach } // if no cover // If we've specified a coverurl, create a fake Amazon array with it else { - $final_results = array(array('LargeImage' => $coverurl)); + $final_results = array_merge($final_results, array(array('LargeImage' => $coverurl))); } /* Foreach through what we've found */ diff --git a/modules/amazon/AmazonSearchEngine.class.php b/modules/amazon/AmazonSearchEngine.class.php index 691d8b85..a7701555 100644 --- a/modules/amazon/AmazonSearchEngine.class.php +++ b/modules/amazon/AmazonSearchEngine.class.php @@ -30,7 +30,9 @@ */
class AmazonSearch {
- var $base_url = "http://webservices.amazon.com/onca/xml?";
+ var $base_url_default = "http://webservices.amazon.com";
+ var $url_suffix = "/onca/xml?";
+ var $base_url;
var $search;
var $token;
var $results=array(); // Array of results
@@ -40,9 +42,23 @@ class AmazonSearch { var $_subTag; // Stupid hack to make things come our right
var $_currentTag; // Stupid hack to make things come out right
var $_currentTagContents;
+ var $_currentPage=0;
+ var $_maxPage=1;
+ var $_default_results_pages=1;
- function AmazonSearch($token, $associates_id = 'none') {
-
+ function AmazonSearch($token, $base_url_param = '', $associates_id = 'none') {
+ // log_event($GLOBALS['user']->username,'amazon-search-results',"base_url_param='$base_url_param'");
+
+ if($base_url_param != ''){$this->base_url = $base_url_param . $this->url_suffix;
+ if (conf('debug')) {
+ log_event($GLOBALS['user']->username,'amazon-search-results',"Retrieving from " . $base_url_param . $this->url_suffix);
+ }
+ }
+ else{ $this->base_url=$this->base_url_default . $this->url_suffix;
+ if (conf('debug')) {
+ log_event($GLOBALS['user']->username,'amazon-search-results',"Retrieving from DEFAULT");
+ }
+ };
$this->token = $token;
$this->associates_id = $associates_id;
@@ -84,7 +100,10 @@ class AmazonSearch { $snoopy->fetch($url);
$contents = $snoopy->results;
-
+ if (conf('debug')) {
+ log_event($GLOBALS['user']->username,'amazon-search-results',"Retrieved $contents");
+ }
+
if (!xml_parse($this->_parser, $contents)) {
die(sprintf('XML error: %s at line %d',xml_error_string(xml_get_error_code($this->_parser)),xml_get_current_line_number($this->_parser)));
}
@@ -103,6 +122,10 @@ class AmazonSearch { "&Operation=ItemSearch&Artist=" . urlencode($terms['artist']) . "&Title=" . urlencode($terms['album']) .
"&Keywords=" . urlencode($terms['keywords']) . "&SearchIndex=" . $type;
+ log_event($GLOBALS['user']->username,'amazon-search-results',"_currentPage = " . $this->_currentPage);
+ if($this->_currentPage != 0){
+ $url = $url . "&ItemPage=" . ($this->_currentPage+1);
+ }
$this->run_search($url);
unset($this->results['ASIN']);
@@ -152,9 +175,13 @@ class AmazonSearch { $this->_currentTag = $tag;
}
else {
+ if($tag != "TotalPages"){
$this->_currentTag = '';
- }
-
+ }else{
+ $this->_currentTag = $tag;
+
+ }
+ }
} // start_element
@@ -171,9 +198,15 @@ class AmazonSearch { case 'ASIN':
$this->_sourceTag = trim($cdata);
break;
+ case 'TotalPages':
+ if(conf('debug')){
+ log_event($GLOBALS['user']->username,'amazon-search-results',"TotalPages= ". trim($cdata));
+ }
+ $this->_maxPage = trim($cdata);
+ break;
default:
if (strlen($tag)) {
- $this->results[$source][$tag] = trim($cdata);
+ $this->results[$source][$tag] = trim($cdata);
}
break;
} // end switch
|