summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPaul 'flowerysong' Arthur <flowerysong00@yahoo.com>2010-05-04 05:32:16 +0000
committerPaul 'flowerysong' Arthur <flowerysong00@yahoo.com>2010-05-04 05:32:16 +0000
commit82780455c4bc68d39963819a02bd499a612861e1 (patch)
tree9902d836ebd3ee5ba04e6b96c8b2adf4d07ae11e /lib
parent1dedf65f0f191ab25434f26c4b7c9d046ce55c89 (diff)
downloadampache-82780455c4bc68d39963819a02bd499a612861e1.tar.gz
ampache-82780455c4bc68d39963819a02bd499a612861e1.tar.bz2
ampache-82780455c4bc68d39963819a02bd499a612861e1.zip
Cosmetics: use tabs for indentation.
Diffstat (limited to 'lib')
-rw-r--r--lib/class/art.class.php920
1 files changed, 460 insertions, 460 deletions
diff --git a/lib/class/art.class.php b/lib/class/art.class.php
index 0284d470..10d1abaa 100644
--- a/lib/class/art.class.php
+++ b/lib/class/art.class.php
@@ -318,71 +318,71 @@ class Art extends database_object {
/**
* get_from_source
- * This gets an image for the album art from a source as
- * defined in the passed array. Because we don't know where
- * its comming from we are a passed an array that can look like
- * ['url'] = URL *** OPTIONAL ***
- * ['file'] = FILENAME *** OPTIONAL ***
- * ['raw'] = Actual Image data, already captured
- */
+ * This gets an image for the album art from a source as
+ * defined in the passed array. Because we don't know where
+ * its comming from we are a passed an array that can look like
+ * ['url'] = URL *** OPTIONAL ***
+ * ['file'] = FILENAME *** OPTIONAL ***
+ * ['raw'] = Actual Image data, already captured
+ */
public function get_from_source($data) {
- // Already have the data, this often comes from id3tags
- if (isset($data['raw'])) {
- return $data['raw'];
- }
+ // Already have the data, this often comes from id3tags
+ if (isset($data['raw'])) {
+ return $data['raw'];
+ }
- // If it came from the database
- if (isset($data['db'])) {
- // Repull it
- $uid = Dba::escape($data['db']);
+ // If it came from the database
+ if (isset($data['db'])) {
+ // Repull it
+ $uid = Dba::escape($data['db']);
$type = Dba::escape($this->type);
- $sql = "SELECT * FROM `" . $type . "_data` WHERE `" . $type . "_id`='$uid'";
- $db_results = Dba::read($sql);
- $row = Dba::fetch_assoc($db_results);
- return $row['art'];
- } // came from the db
-
- // Check to see if it's a URL
- if (isset($data['url'])) {
- $snoopy = new Snoopy();
- if(Config::get('proxy_host') AND Config::get('proxy_port')) {
- $snoopy->proxy_user = Config::get('proxy_host');
- $snoopy->proxy_port = Config::get('proxy_port');
- $snoopy->proxy_user = Config::get('proxy_user');
- $snoopy->proxy_pass = Config::get('proxy_pass');
- }
- $snoopy->fetch($data['url']);
- return $snoopy->results;
- }
-
- // Check to see if it's a FILE
- if (isset($data['file'])) {
- $handle = fopen($data['file'],'rb');
- $image_data = fread($handle,filesize($data['file']));
- fclose($handle);
- return $image_data;
- }
-
- // Check to see if it is embedded in id3 of a song
- if (isset($data['song'])) {
- // If we find a good one, stop looking
- $getID3 = new getID3();
- $id3 = $getID3->analyze($data['song']);
-
- if ($id3['format_name'] == "WMA") {
- return $id3['asf']['extended_content_description_object']['content_descriptors']['13']['data'];
- }
- elseif (isset($id3['id3v2']['APIC'])) {
- // Foreach incase they have more then one
- foreach ($id3['id3v2']['APIC'] as $image) {
- return $image['data'];
- }
- }
- } // if data song
-
- return false;
+ $sql = "SELECT * FROM `" . $type . "_data` WHERE `" . $type . "_id`='$uid'";
+ $db_results = Dba::read($sql);
+ $row = Dba::fetch_assoc($db_results);
+ return $row['art'];
+ } // came from the db
+
+ // Check to see if it's a URL
+ if (isset($data['url'])) {
+ $snoopy = new Snoopy();
+ if(Config::get('proxy_host') AND Config::get('proxy_port')) {
+ $snoopy->proxy_user = Config::get('proxy_host');
+ $snoopy->proxy_port = Config::get('proxy_port');
+ $snoopy->proxy_user = Config::get('proxy_user');
+ $snoopy->proxy_pass = Config::get('proxy_pass');
+ }
+ $snoopy->fetch($data['url']);
+ return $snoopy->results;
+ }
+
+ // Check to see if it's a FILE
+ if (isset($data['file'])) {
+ $handle = fopen($data['file'],'rb');
+ $image_data = fread($handle,filesize($data['file']));
+ fclose($handle);
+ return $image_data;
+ }
+
+ // Check to see if it is embedded in id3 of a song
+ if (isset($data['song'])) {
+ // If we find a good one, stop looking
+ $getID3 = new getID3();
+ $id3 = $getID3->analyze($data['song']);
+
+ if ($id3['format_name'] == "WMA") {
+ return $id3['asf']['extended_content_description_object']['content_descriptors']['13']['data'];
+ }
+ elseif (isset($id3['id3v2']['APIC'])) {
+ // Foreach incase they have more then one
+ foreach ($id3['id3v2']['APIC'] as $image) {
+ return $image['data'];
+ }
+ }
+ } // if data song
+
+ return false;
} // get_from_source
@@ -435,52 +435,52 @@ class Art extends database_object {
}
$config = Config::get('art_order');
- $methods = get_class_methods('Art');
+ $methods = get_class_methods('Art');
- /* If it's not set */
- if (empty($config)) {
- // They don't want art!
- return array();
- }
- elseif (!is_array($config)) {
- $config = array($config);
- }
+ /* If it's not set */
+ if (empty($config)) {
+ // They don't want art!
+ return array();
+ }
+ elseif (!is_array($config)) {
+ $config = array($config);
+ }
debug_event('Art','Searching using:' . print_r($config,1),3);
- foreach ($config AS $method) {
+ foreach ($config AS $method) {
- $data = array();
+ $data = array();
- $method_name = "gather_" . $method;
- if (in_array($method_name,$methods)) {
- // Some of these take options!
- switch ($method_name) {
- case 'gather_amazon':
- $data = $this->{$method_name}($options['keyword'],$limit);
- break;
- case 'gather_lastfm':
- $data = $this->{$method_name}($limit,$options);
- break;
- default:
- $data = $this->{$method_name}($limit);
- break;
- }
+ $method_name = "gather_" . $method;
+ if (in_array($method_name,$methods)) {
+ // Some of these take options!
+ switch ($method_name) {
+ case 'gather_amazon':
+ $data = $this->{$method_name}($options['keyword'],$limit);
+ break;
+ case 'gather_lastfm':
+ $data = $this->{$method_name}($limit,$options);
+ break;
+ default:
+ $data = $this->{$method_name}($limit);
+ break;
+ }
- // Add the results we got to the current set
- $total_results += count($data);
- // HACK for PHP 5, $data must be cast as array $results = array_merge($results, (array)$data);
- $results = array_merge($results,(array)$data);
+ // Add the results we got to the current set
+ $total_results += count($data);
+ // HACK for PHP 5, $data must be cast as array $results = array_merge($results, (array)$data);
+ $results = array_merge($results,(array)$data);
- if ($total_results > $limit AND $limit > 0) {
- return $results;
- }
+ if ($total_results > $limit AND $limit > 0) {
+ return $results;
+ }
- } // if the method exists
+ } // if the method exists
- } // end foreach
+ } // end foreach
- return $results;
+ return $results;
} // gather
@@ -494,140 +494,140 @@ class Art extends database_object {
* This function retrives art based on MusicBrainz' Advanced Relationships
*/
public function gather_musicbrainz($limit=0) {
- $images = array();
+ $images = array();
$num_found = 0;
- $mbquery = new MusicBrainzQuery();
+ $mbquery = new MusicBrainzQuery();
if ($this->mbid) {
debug_event('mbz-gatherart', "Album MBID: " . $this->mbid, '5');
- }
- else {
+ }
+ else {
return $images;
- }
+ }
$includes = new mbReleaseIncludes();
- try {
+ try {
$release = $mbquery->getReleaseByID($this->mbid, $includes->urlRelations());
- } catch (Exception $e) {
+ } catch (Exception $e) {
return $images;
- }
+ }
- $asin = $release->getAsin();
+ $asin = $release->getAsin();
- if ($asin) {
+ if ($asin) {
debug_event('mbz-gatherart', "Found ASIN: " . $asin, '5');
$base_urls = array(
- "01" => "ec1.images-amazon.com",
- "02" => "ec1.images-amazon.com",
- "03" => "ec2.images-amazon.com",
- "08" => "ec1.images-amazon.com",
- "09" => "ec1.images-amazon.com",
+ "01" => "ec1.images-amazon.com",
+ "02" => "ec1.images-amazon.com",
+ "03" => "ec2.images-amazon.com",
+ "08" => "ec1.images-amazon.com",
+ "09" => "ec1.images-amazon.com",
);
foreach ($base_urls as $server_num => $base_url) {
- // to avoid complicating things even further, we only look for large cover art
- $url = 'http://' . $base_url . '/images/P/' . $asin . '.' . $server_num . '.LZZZZZZZ.jpg';
- debug_event('mbz-gatherart', "Evaluating Amazon URL: " . $url, '5');
- $snoopy = new Snoopy();
- if(Config::get('proxy_host') AND Config::get('proxy_port')) {
- $snoopy->proxy_user = Config::get('proxy_host');
- $snoopy->proxy_port = Config::get('proxy_port');
- $snoopy->proxy_user = Config::get('proxy_user');
- $snoopy->proxy_pass = Config::get('proxy_pass');
- }
- if ($snoopy->fetch($url)) {
- $num_found++;
- debug_event('mbz-gatherart', "Amazon URL added: " . $url, '5');
- $images[] = array(
- 'url' => $url,
- 'mime' => 'image/jpeg',
- );
- if ($num_found >= $limit) {
- return $images;
- }
- }
+ // to avoid complicating things even further, we only look for large cover art
+ $url = 'http://' . $base_url . '/images/P/' . $asin . '.' . $server_num . '.LZZZZZZZ.jpg';
+ debug_event('mbz-gatherart', "Evaluating Amazon URL: " . $url, '5');
+ $snoopy = new Snoopy();
+ if(Config::get('proxy_host') AND Config::get('proxy_port')) {
+ $snoopy->proxy_user = Config::get('proxy_host');
+ $snoopy->proxy_port = Config::get('proxy_port');
+ $snoopy->proxy_user = Config::get('proxy_user');
+ $snoopy->proxy_pass = Config::get('proxy_pass');
+ }
+ if ($snoopy->fetch($url)) {
+ $num_found++;
+ debug_event('mbz-gatherart', "Amazon URL added: " . $url, '5');
+ $images[] = array(
+ 'url' => $url,
+ 'mime' => 'image/jpeg',
+ );
+ if ($num_found >= $limit) {
+ return $images;
+ }
+ }
}
- }
- // The next bit is based directly on the MusicBrainz server code that displays cover art.
- // I'm leaving in the releaseuri info for the moment, though it's not going to be used.
- $coverartsites[] = array(
- name => "CD Baby",
- domain => "cdbaby.com",
- regexp => '@http://cdbaby\.com/cd/(\w)(\w)(\w*)@',
- imguri => 'http://cdbaby.name/$matches[1]/$matches[2]/$matches[1]$matches[2]$matches[3].jpg',
+ }
+ // The next bit is based directly on the MusicBrainz server code that displays cover art.
+ // I'm leaving in the releaseuri info for the moment, though it's not going to be used.
+ $coverartsites[] = array(
+ name => "CD Baby",
+ domain => "cdbaby.com",
+ regexp => '@http://cdbaby\.com/cd/(\w)(\w)(\w*)@',
+ imguri => 'http://cdbaby.name/$matches[1]/$matches[2]/$matches[1]$matches[2]$matches[3].jpg',
releaseuri => 'http://cdbaby.com/cd/$matches[1]$matches[2]$matches[3]/from/musicbrainz',
- );
- $coverartsites[] = array(
- name => "CD Baby",
- domain => "cdbaby.name",
- regexp => "@http://cdbaby\.name/([a-z0-9])/([a-z0-9])/([A-Za-z0-9]*).jpg@",
- imguri => 'http://cdbaby.name/$matches[1]/$matches[2]/$matches[3].jpg',
+ );
+ $coverartsites[] = array(
+ name => "CD Baby",
+ domain => "cdbaby.name",
+ regexp => "@http://cdbaby\.name/([a-z0-9])/([a-z0-9])/([A-Za-z0-9]*).jpg@",
+ imguri => 'http://cdbaby.name/$matches[1]/$matches[2]/$matches[3].jpg',
releaseuri => 'http://cdbaby.com/cd/$matches[3]/from/musicbrainz',
- );
- $coverartsites[] = array(
- name => 'archive.org',
- domain => 'archive.org',
- regexp => '/^(.*\.(jpg|jpeg|png|gif))$/',
- imguri => '$matches[1]',
+ );
+ $coverartsites[] = array(
+ name => 'archive.org',
+ domain => 'archive.org',
+ regexp => '/^(.*\.(jpg|jpeg|png|gif))$/',
+ imguri => '$matches[1]',
releaseuri => '',
- );
- $coverartsites[] = array(
- name => "Jamendo",
- domain => "www.jamendo.com",
- regexp => '/http://www\.jamendo\.com/(\w\w/)?album/(\d+)/',
- imguri => 'http://img.jamendo.com/albums/$matches[2]/covers/1.200.jpg',
+ );
+ $coverartsites[] = array(
+ name => "Jamendo",
+ domain => "www.jamendo.com",
+ regexp => '/http://www\.jamendo\.com/(\w\w/)?album/(\d+)/',
+ imguri => 'http://img.jamendo.com/albums/$matches[2]/covers/1.200.jpg',
releaseuri => 'http://www.jamendo.com/album/$matches[2]',
- );
- $coverartsites[] = array(
- name => '8bitpeoples.com',
- domain => '8bitpeoples.com',
- regexp => '/^(.*)$/',
- imguri => '$matches[1]',
+ );
+ $coverartsites[] = array(
+ name => '8bitpeoples.com',
+ domain => '8bitpeoples.com',
+ regexp => '/^(.*)$/',
+ imguri => '$matches[1]',
releaseuri => '',
- );
- $coverartsites[] = array(
- name => 'Encyclopédisque',
- domain => 'encyclopedisque.fr',
- regexp => '/http://www.encyclopedisque.fr/images/imgdb/(thumb250|main)/(\d+).jpg/',
- imguri => 'http://www.encyclopedisque.fr/images/imgdb/thumb250/$matches[2].jpg',
+ );
+ $coverartsites[] = array(
+ name => 'Encyclopédisque',
+ domain => 'encyclopedisque.fr',
+ regexp => '/http://www.encyclopedisque.fr/images/imgdb/(thumb250|main)/(\d+).jpg/',
+ imguri => 'http://www.encyclopedisque.fr/images/imgdb/thumb250/$matches[2].jpg',
releaseuri => 'http://www.encyclopedisque.fr/',
- );
- $coverartsites[] = array(
- name => 'Thastrom',
- domain => 'www.thastrom.se',
- regexp => '/^(.*)$/',
- imguri => '$matches[1]',
+ );
+ $coverartsites[] = array(
+ name => 'Thastrom',
+ domain => 'www.thastrom.se',
+ regexp => '/^(.*)$/',
+ imguri => '$matches[1]',
releaseuri => '',
- );
- $coverartsites[] = array(
- name => 'Universal Poplab',
- domain => 'www.universalpoplab.com',
- regexp => '/^(.*)$/',
- imguri => '$matches[1]',
+ );
+ $coverartsites[] = array(
+ name => 'Universal Poplab',
+ domain => 'www.universalpoplab.com',
+ regexp => '/^(.*)$/',
+ imguri => '$matches[1]',
releaseuri => '',
- );
- foreach ($release->getRelations($mbRelation->TO_URL) as $ar) {
+ );
+ foreach ($release->getRelations($mbRelation->TO_URL) as $ar) {
$arurl = $ar->getTargetId();
debug_event('mbz-gatherart', "Found URL AR: " . $arurl , '5');
foreach ($coverartsites as $casite) {
- if (strstr($arurl, $casite['domain'])) {
- debug_event('mbz-gatherart', "Matched coverart site: " . $casite['name'], '5');
- if (preg_match($casite['regexp'], $arurl, $matches) == 1) {
- $num_found++;
- eval("\$url = \"$casite[imguri]\";");
- debug_event('mbz-gatherart', "Generated URL added: " . $url, '5');
- $images[] = array(
- 'url' => $url,
- 'mime' => 'image/jpeg',
- );
- if ($num_found >= $limit) {
- return $images;
- }
- }
- }
+ if (strstr($arurl, $casite['domain'])) {
+ debug_event('mbz-gatherart', "Matched coverart site: " . $casite['name'], '5');
+ if (preg_match($casite['regexp'], $arurl, $matches) == 1) {
+ $num_found++;
+ eval("\$url = \"$casite[imguri]\";");
+ debug_event('mbz-gatherart', "Generated URL added: " . $url, '5');
+ $images[] = array(
+ 'url' => $url,
+ 'mime' => 'image/jpeg',
+ );
+ if ($num_found >= $limit) {
+ return $images;
+ }
+ }
+ }
} // end foreach coverart sites
- } // end foreach
+ } // end foreach
- return $images;
+ return $images;
} // gather_musicbrainz
@@ -639,138 +639,138 @@ class Art extends database_object {
public function gather_amazon($keywords='',$limit=5) {
- $images = array();
- $final_results = array();
- $possible_keys = array("LargeImage","MediumImage","SmallImage");
-
- // Prevent the script from timing out
- set_time_limit(0);
-
- if (empty($keywords)) {
- $keywords = $this->full_name;
- /* If this isn't a various album combine with artist name */
- if ($this->artist_count == '1') { $keywords .= ' ' . $this->artist_name; }
- }
-
- /* Create Base Vars */
- $amazon_base_urls = array();
-
- /* Attempt to retrive the album art order */
- $config_value = Config::get('amazon_base_urls');
-
- /* If it's not set */
- if (empty($config_value)) {
- $amazon_base_urls = array('http://webservices.amazon.com');
- }
- elseif (!is_array($config_value)) {
- array_push($amazon_base_urls,$config_value);
- }
- else {
- $amazon_base_urls = array_merge($amazon_base_urls, Config::get('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(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');
- $proxyuser = Config::get('proxy_user');
- $proxypass = Config::get('proxy_pass');
- debug_print("amazon", "setProxy", "5");
- $amazon->setProxy($proxyhost, $proxyport, $proxyuser, $proxypass);
- }
-
- $search_results = array();
-
- /* Setup the needed variables */
- $max_pages_to_search = max(Config::get('max_amazon_results_pages'),$amazon->_default_results_pages);
- $pages_to_search = $max_pages_to_search; //init to max until we know better.
- // while we have pages to search
- do {
- $raw_results = $amazon->search(array('artist'=>$artist,'album'=>$albumname,'keywords'=>$keywords));
-
- $total = count($raw_results) + count($search_results);
-
- // If we've gotten more then we wanted
- if (!empty($limit) && $total > $limit) {
- // We don't want ot re-count every loop
- $i = $total;
- while ($i > $limit) {
- array_pop($raw_results);
- $i--;
- }
-
- debug_event('amazon-xml',"Found $total, Limit $limit reducing and breaking from loop",'5');
- // Merge the results and BREAK!
- $search_results = array_merge($search_results,$raw_results);
- break;
- } // if limit defined
-
- $search_results = array_merge($search_results,$raw_results);
- $pages_to_search = min($max_pages_to_search, $amazon->_maxPage);
- debug_event('amazon-xml', "Searched results page " . ($amazon->_currentPage+1) . "/" . $pages_to_search,'5');
- $amazon->_currentPage++;
-
- } while($amazon->_currentPage < $pages_to_search);
-
-
- // Only do the second search if the first actually returns something
- if (count($search_results)) {
- $final_results = $amazon->lookup($search_results);
- }
-
- /* Log this if we're doin debug */
- debug_event('amazon-xml',"Searched using $keywords with " . Config::get('amazon_developer_key') . " as key " . count($final_results),1);
-
- // If we've hit our limit
- if (!empty($limit) && count($final_results) >= $limit) {
- break;
- }
-
- } // end foreach
-
- /* Foreach through what we've found */
- foreach ($final_results as $result) {
-
- /* Recurse through the images found */
- foreach ($possible_keys as $key) {
- if (strlen($result[$key])) {
- break;
- }
- } // foreach
-
- // Rudimentary image type detection, only JPG and GIF allowed.
- if (substr($result[$key], -4 == '.jpg')) {
- $mime = "image/jpeg";
- }
- elseif (substr($result[$key], -4 == '.gif')) {
- $mime = "image/gif";
- }
- elseif (substr($result[$key], -4 == '.png')) {
- $mime = "image/png";
- }
- else {
- /* Just go to the next result */
- continue;
- }
-
- $data['url'] = $result[$key];
- $data['mime'] = $mime;
-
- $images[] = $data;
-
- if (!empty($limit)) {
- if (count($images) >= $limit) {
- return $images;
- }
- }
-
- } // if we've got something
-
- return $images;
+ $images = array();
+ $final_results = array();
+ $possible_keys = array("LargeImage","MediumImage","SmallImage");
+
+ // Prevent the script from timing out
+ set_time_limit(0);
+
+ if (empty($keywords)) {
+ $keywords = $this->full_name;
+ /* If this isn't a various album combine with artist name */
+ if ($this->artist_count == '1') { $keywords .= ' ' . $this->artist_name; }
+ }
+
+ /* Create Base Vars */
+ $amazon_base_urls = array();
+
+ /* Attempt to retrive the album art order */
+ $config_value = Config::get('amazon_base_urls');
+
+ /* If it's not set */
+ if (empty($config_value)) {
+ $amazon_base_urls = array('http://webservices.amazon.com');
+ }
+ elseif (!is_array($config_value)) {
+ array_push($amazon_base_urls,$config_value);
+ }
+ else {
+ $amazon_base_urls = array_merge($amazon_base_urls, Config::get('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(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');
+ $proxyuser = Config::get('proxy_user');
+ $proxypass = Config::get('proxy_pass');
+ debug_print("amazon", "setProxy", "5");
+ $amazon->setProxy($proxyhost, $proxyport, $proxyuser, $proxypass);
+ }
+
+ $search_results = array();
+
+ /* Setup the needed variables */
+ $max_pages_to_search = max(Config::get('max_amazon_results_pages'),$amazon->_default_results_pages);
+ $pages_to_search = $max_pages_to_search; //init to max until we know better.
+ // while we have pages to search
+ do {
+ $raw_results = $amazon->search(array('artist'=>$artist,'album'=>$albumname,'keywords'=>$keywords));
+
+ $total = count($raw_results) + count($search_results);
+
+ // If we've gotten more then we wanted
+ if (!empty($limit) && $total > $limit) {
+ // We don't want ot re-count every loop
+ $i = $total;
+ while ($i > $limit) {
+ array_pop($raw_results);
+ $i--;
+ }
+
+ debug_event('amazon-xml',"Found $total, Limit $limit reducing and breaking from loop",'5');
+ // Merge the results and BREAK!
+ $search_results = array_merge($search_results,$raw_results);
+ break;
+ } // if limit defined
+
+ $search_results = array_merge($search_results,$raw_results);
+ $pages_to_search = min($max_pages_to_search, $amazon->_maxPage);
+ debug_event('amazon-xml', "Searched results page " . ($amazon->_currentPage+1) . "/" . $pages_to_search,'5');
+ $amazon->_currentPage++;
+
+ } while($amazon->_currentPage < $pages_to_search);
+
+
+ // Only do the second search if the first actually returns something
+ if (count($search_results)) {
+ $final_results = $amazon->lookup($search_results);
+ }
+
+ /* Log this if we're doin debug */
+ debug_event('amazon-xml',"Searched using $keywords with " . Config::get('amazon_developer_key') . " as key " . count($final_results),1);
+
+ // If we've hit our limit
+ if (!empty($limit) && count($final_results) >= $limit) {
+ break;
+ }
+
+ } // end foreach
+
+ /* Foreach through what we've found */
+ foreach ($final_results as $result) {
+
+ /* Recurse through the images found */
+ foreach ($possible_keys as $key) {
+ if (strlen($result[$key])) {
+ break;
+ }
+ } // foreach
+
+ // Rudimentary image type detection, only JPG and GIF allowed.
+ if (substr($result[$key], -4 == '.jpg')) {
+ $mime = "image/jpeg";
+ }
+ elseif (substr($result[$key], -4 == '.gif')) {
+ $mime = "image/gif";
+ }
+ elseif (substr($result[$key], -4 == '.png')) {
+ $mime = "image/png";
+ }
+ else {
+ /* Just go to the next result */
+ continue;
+ }
+
+ $data['url'] = $result[$key];
+ $data['mime'] = $mime;
+
+ $images[] = $data;
+
+ if (!empty($limit)) {
+ if (count($images) >= $limit) {
+ return $images;
+ }
+ }
+
+ } // if we've got something
+
+ return $images;
} // gather_amazon
@@ -784,69 +784,69 @@ class Art extends database_object {
$media = new Album($this->uid);
$songs = $media->get_songs();
- $data = array();
+ $data = array();
- /* See if we are looking for a specific filename */
- $preferred_filename = Config::get('album_art_preferred_filename');
+ /* See if we are looking for a specific filename */
+ $preferred_filename = Config::get('album_art_preferred_filename');
- // Init a horrible hack array of lameness
- $cache =array();
+ // Init a horrible hack array of lameness
+ $cache =array();
- /* Thanks to dromio for origional code */
- /* Added search for any .jpg, png or .gif - Vollmer */
- foreach($songs as $song_id) {
- $song = new Song($song_id);
- $dir = dirname($song->file);
+ /* Thanks to dromio for origional code */
+ /* Added search for any .jpg, png or .gif - Vollmer */
+ foreach($songs as $song_id) {
+ $song = new Song($song_id);
+ $dir = dirname($song->file);
- debug_event('folder_art',"Opening $dir and checking for Album Art",'3');
+ debug_event('folder_art',"Opening $dir and checking for Album Art",'3');
- /* Open up the directory */
- $handle = @opendir($dir);
+ /* Open up the directory */
+ $handle = @opendir($dir);
- if (!is_resource($handle)) {
- Error::add('general',_('Error: Unable to open') . ' ' . $dir);
- debug_event('read',"Error: Unable to open $dir for album art read",'2');
- }
+ if (!is_resource($handle)) {
+ Error::add('general',_('Error: Unable to open') . ' ' . $dir);
+ debug_event('read',"Error: Unable to open $dir for album art read",'2');
+ }
- /* Recurse through this dir and create the files array */
- while ( FALSE !== ($file = @readdir($handle)) ) {
- $extension = substr($file,strlen($file)-3,4);
+ /* Recurse through this dir and create the files array */
+ while ( FALSE !== ($file = @readdir($handle)) ) {
+ $extension = substr($file,strlen($file)-3,4);
- /* If it's an image file */
- if ($extension == "jpg" || $extension == "gif" || $extension == "png" || $extension == "jp2" || $extension == "bmp") {
+ /* If it's an image file */
+ if ($extension == "jpg" || $extension == "gif" || $extension == "png" || $extension == "jp2" || $extension == "bmp") {
- if ($extension == 'jpg') { $extension = 'jpeg'; }
+ if ($extension == 'jpg') { $extension = 'jpeg'; }
- // HACK ALERT this is to prevent duplicate filenames
- $full_filename = $dir . '/' . $file;
- $index = md5($full_filename);
+ // HACK ALERT this is to prevent duplicate filenames
+ $full_filename = $dir . '/' . $file;
+ $index = md5($full_filename);
- /* Make sure it's got something in it */
- if (!filesize($dir . '/' . $file)) { continue; }
+ /* Make sure it's got something in it */
+ if (!filesize($dir . '/' . $file)) { continue; }
- if ($file == $preferred_filename) {
- // If we found the preferred filename we're done, wipe out previous results
- $data = array(array('file' => $full_filename, 'mime' => 'image/' . $extension));
- return $data;
- }
- elseif (!isset($cache[$index])) {
- $data[] = array('file' => $full_filename, 'mime' => 'image/' . $extension);
- }
+ if ($file == $preferred_filename) {
+ // If we found the preferred filename we're done, wipe out previous results
+ $data = array(array('file' => $full_filename, 'mime' => 'image/' . $extension));
+ return $data;
+ }
+ elseif (!isset($cache[$index])) {
+ $data[] = array('file' => $full_filename, 'mime' => 'image/' . $extension);
+ }
- $cache[$index] = '1';
+ $cache[$index] = '1';
- } // end if it's an image
+ } // end if it's an image
- } // end while reading dir
- @closedir($handle);
+ } // end while reading dir
+ @closedir($handle);
- if (!empty($limit) && $limit < count($data)) {
- return $data;
- }
+ if (!empty($limit) && $limit < count($data)) {
+ return $data;
+ }
- } // end foreach songs
+ } // end foreach songs
- return $data;
+ return $data;
} // gather_folder
@@ -860,38 +860,38 @@ class Art extends database_object {
// We need the filenames
$album = new Album($this->uid);
- // grab the songs and define our results
- $songs = $album->get_songs();
- $data = array();
-
- // Foreach songs in this album
- foreach ($songs as $song_id) {
- $song = new Song($song_id);
- // If we find a good one, stop looking
- $getID3 = new getID3();
- try { $id3 = $getID3->analyze($song->file); }
- catch (Exception $error) {
- debug_event('getid3',$error->message,'1');
- }
-
- if ($id3['format_name'] == "WMA") {
- $image = $id3['asf']['extended_content_description_object']['content_descriptors']['13'];
- $data[] = array('song'=>$song->file,'raw'=>$image['data'],'mime'=>$image['mime']);
- }
- elseif (isset($id3['id3v2']['APIC'])) {
- // Foreach incase they have more then one
- foreach ($id3['id3v2']['APIC'] as $image) {
- $data[] = array('song'=>$song->file,'raw'=>$image['data'],'mime'=>$image['mime']);
- }
- }
-
- if (!empty($limit) && $limit < count($data)) {
- return $data;
- }
-
- } // end foreach
-
- return $data;
+ // grab the songs and define our results
+ $songs = $album->get_songs();
+ $data = array();
+
+ // Foreach songs in this album
+ foreach ($songs as $song_id) {
+ $song = new Song($song_id);
+ // If we find a good one, stop looking
+ $getID3 = new getID3();
+ try { $id3 = $getID3->analyze($song->file); }
+ catch (Exception $error) {
+ debug_event('getid3',$error->message,'1');
+ }
+
+ if ($id3['format_name'] == "WMA") {
+ $image = $id3['asf']['extended_content_description_object']['content_descriptors']['13'];
+ $data[] = array('song'=>$song->file,'raw'=>$image['data'],'mime'=>$image['mime']);
+ }
+ elseif (isset($id3['id3v2']['APIC'])) {
+ // Foreach incase they have more then one
+ foreach ($id3['id3v2']['APIC'] as $image) {
+ $data[] = array('song'=>$song->file,'raw'=>$image['data'],'mime'=>$image['mime']);
+ }
+ }
+
+ if (!empty($limit) && $limit < count($data)) {
+ return $data;
+ }
+
+ } // end foreach
+
+ return $data;
} // gather_tags
@@ -901,32 +901,32 @@ class Art extends database_object {
*/
public function gather_google($limit=5) {
- $images = array();
+ $images = array();
$media = new $this->type($this->uid);
$media->format();
- $search = $media->full_name;
+ $search = $media->full_name;
- if ($media->artist_count == '1')
- $search = $media->artist_name . ', ' . $search;
+ if ($media->artist_count == '1')
+ $search = $media->artist_name . ', ' . $search;
- $search = rawurlencode($search);
+ $search = rawurlencode($search);
- $size = '&imgsz=m'; // Medium
- //$size = '&imgsz=l'; // Large
+ $size = '&imgsz=m'; // Medium
+ //$size = '&imgsz=l'; // Large
- $html = file_get_contents("http://images.google.com/images?source=hp&q=$search&oq=&um=1&ie=UTF-8&sa=N&tab=wi&start=0&tbo=1$size");
+ $html = file_get_contents("http://images.google.com/images?source=hp&q=$search&oq=&um=1&ie=UTF-8&sa=N&tab=wi&start=0&tbo=1$size");
- if(preg_match_all("|\ssrc\=\"(http.+?)\"|", $html, $matches, PREG_PATTERN_ORDER))
- foreach ($matches[1] as $match) {
- $extension = "image/jpeg";
+ if(preg_match_all("|\ssrc\=\"(http.+?)\"|", $html, $matches, PREG_PATTERN_ORDER))
+ foreach ($matches[1] as $match) {
+ $extension = "image/jpeg";
- if (strrpos($extension, '.') !== false) $extension = substr($extension, strrpos($extension, '.') + 1);
+ if (strrpos($extension, '.') !== false) $extension = substr($extension, strrpos($extension, '.') + 1);
- $images[] = array('url' => $match, 'mime' => $extension);
- }
+ $images[] = array('url' => $match, 'mime' => $extension);
+ }
- return $images;
+ return $images;
} // gather_google
@@ -937,57 +937,57 @@ class Art extends database_object {
*/
public function gather_lastfm($limit,$options=false) {
- // Create the parser object
- $lastfm = new LastFMSearch();
+ // Create the parser object
+ $lastfm = new LastFMSearch();
switch ($this->type) {
case 'album':
- if (is_array($options)) {
- $artist = $options['artist'];
- $album = $options['album_name'];
- }
- else {
+ if (is_array($options)) {
+ $artist = $options['artist'];
+ $album = $options['album_name'];
+ }
+ else {
$media = new Album($this->uid);
$media->format();
- $artist = $media->artist_name;
- $album = $media->full_name;
- }
+ $artist = $media->artist_name;
+ $album = $media->full_name;
+ }
break;
}
- if(Config::get('proxy_host') AND Config::get('proxy_port')) {
- $proxyhost = Config::get('proxy_host');
- $proxyport = Config::get('proxy_port');
- $proxyuser = Config::get('proxy_user');
- $proxypass = Config::get('proxy_pass');
- debug_event("lastfm", "set Proxy", "5");
- $lastfm->setProxy($proxyhost, $proxyport, $proxyuser, $proxypass);
- }
- $raw_data = $lastfm->album_search($artist,$album);
+ if(Config::get('proxy_host') AND Config::get('proxy_port')) {
+ $proxyhost = Config::get('proxy_host');
+ $proxyport = Config::get('proxy_port');
+ $proxyuser = Config::get('proxy_user');
+ $proxypass = Config::get('proxy_pass');
+ debug_event("lastfm", "set Proxy", "5");
+ $lastfm->setProxy($proxyhost, $proxyport, $proxyuser, $proxypass);
+ }
+ $raw_data = $lastfm->album_search($artist,$album);
- if (!count($raw_data)) { return array(); }
+ if (!count($raw_data)) { return array(); }
- $coverart = $raw_data['coverart'];
+ $coverart = $raw_data['coverart'];
- ksort($coverart);
+ ksort($coverart);
- foreach ($coverart as $key=>$value) {
- $i++;
- $url = $coverart[$key];
+ foreach ($coverart as $key=>$value) {
+ $i++;
+ $url = $coverart[$key];
- // We need to check the URL for the /noimage/ stuff
- if (strstr($url,"/noimage/")) {
- debug_event('LastFM','Detected as noimage, skipped ' . $url,'3');
- continue;
- }
+ // We need to check the URL for the /noimage/ stuff
+ if (strstr($url,"/noimage/")) {
+ debug_event('LastFM','Detected as noimage, skipped ' . $url,'3');
+ continue;
+ }
- $results = pathinfo($url);
- $mime = 'image/' . $results['extension'];
- $data[] = array('url'=>$url,'mime'=>$mime);
- if ($i >= $limit) { return $data; }
- } // end foreach
+ $results = pathinfo($url);
+ $mime = 'image/' . $results['extension'];
+ $data[] = array('url'=>$url,'mime'=>$mime);
+ if ($i >= $limit) { return $data; }
+ } // end foreach
- return $data;
+ return $data;
} // gather_lastfm