summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl 'vollmerk' Vollmer <vollmer@ampache.org>2010-03-21 20:53:15 +0000
committerKarl 'vollmerk' Vollmer <vollmer@ampache.org>2010-03-21 20:53:15 +0000
commit3ce42f5e88ea4bec2ef832fe33a2efc0b5b5fc8e (patch)
tree1122e6d0efafeff4d8bd6344becb4f36b77f0666
parent181d9c5dcfbf3a76f808ad6ea9518bb9be90871b (diff)
downloadampache-3ce42f5e88ea4bec2ef832fe33a2efc0b5b5fc8e.tar.gz
ampache-3ce42f5e88ea4bec2ef832fe33a2efc0b5b5fc8e.tar.bz2
ampache-3ce42f5e88ea4bec2ef832fe33a2efc0b5b5fc8e.zip
More changes to art - have not removed old functionality yet
-rw-r--r--albums.php6
-rw-r--r--config/ampache.cfg.php.dist10
-rwxr-xr-xdocs/CHANGELOG2
-rw-r--r--image.php2
-rw-r--r--lib/class/art.class.php741
-rw-r--r--lib/general.lib.php2
6 files changed, 748 insertions, 15 deletions
diff --git a/albums.php b/albums.php
index 3fce3720..ed79e348 100644
--- a/albums.php
+++ b/albums.php
@@ -59,12 +59,11 @@ switch ($_REQUEST['action']) {
break;
case 'find_art':
-
// If not a user then kick em out
if (!Access::check('interface','25')) { access_denied(); exit; }
// get the Album information
- $album = new Album($_REQUEST['album_id']);
+ $album = new Album($_GET['album_id']);
$album->format();
$images = array();
$cover_url = array();
@@ -74,7 +73,8 @@ switch ($_REQUEST['action']) {
$path_info = pathinfo($_FILES['file']['name']);
$upload['file'] = $_FILES['file']['tmp_name'];
$upload['mime'] = 'image/' . $path_info['extension'];
- $image_data = Album::get_image_from_source($upload);
+ $art = new Art($album->id,'album');
+ $image_data = $art->get_from_source($upload);
if ($image_data) {
$album->insert_art($image_data,$upload['0']['mime']);
diff --git a/config/ampache.cfg.php.dist b/config/ampache.cfg.php.dist
index 424c9907..25d0088f 100644
--- a/config/ampache.cfg.php.dist
+++ b/config/ampache.cfg.php.dist
@@ -289,13 +289,15 @@ sociable = "true"
; DEFAULT: false
;resize_images = "false"
-; Album Art Gather Order
+; Art Gather Order
; Simply arrange the following in the order you would like
; ampache to search. If you want to disable one of the search
-; methods simply leave it out.
+; methods simply leave it out. DB should be left as the first
+; method unless you want it to overwrite what's already in the
+; database
; POSSIBLE VALUES: db id3 folder amazon lastfm musicbrainz google
-; DEFAULT: db,id3,folder,lastfm,google
-album_art_order = "db,id3,folder,lastfm,google"
+; DEFAULT: db,tag,folder,musicbrainz,lastfm,google
+art_order = "db,tag,folder,musicbrainz,lastfm,google"
; Amazon Developer Key
; These are needed in order to actually use the amazon album art
diff --git a/docs/CHANGELOG b/docs/CHANGELOG
index 435e9026..8c4da903 100755
--- a/docs/CHANGELOG
+++ b/docs/CHANGELOG
@@ -4,6 +4,8 @@
--------------------------------------------------------------------------
v.3.6-Alpha1
+ - Change album_art_order to art_order to reflect general nature of
+ config option
- Fix PHP warning with IP History if no data is found.
- Add -g flag to catalog update to allow for art gathering via cmdline
- Change Update frequency of catalog display to 1 second rather then
diff --git a/image.php b/image.php
index 4ff15ad0..ac91ad79 100644
--- a/image.php
+++ b/image.php
@@ -107,7 +107,7 @@ switch ($_GET['type']) {
$mime = $_GET['thumb'] ? $art->thumb_mime : $art->raw_mime;
$source = $_GET['thumb'] ? $art->thumb : $art->raw;
- $extension = $art->extension($_GET['thumb']);
+ $extension = Art::extension($mime);
// Send the headers and output the image
header("Expires: Tue, 27 Mar 1984 05:00:00 GMT");
diff --git a/lib/class/art.class.php b/lib/class/art.class.php
index 9c30a8f4..cfac86d9 100644
--- a/lib/class/art.class.php
+++ b/lib/class/art.class.php
@@ -72,12 +72,8 @@ class Art extends database_object {
* extension
* This returns the file extension for the currently loaded art
*/
- public function extension($raw=false) {
-
- // No mime no extension!
- if (!$this->raw_mime) { return false; }
-
- $mime = $raw ? $this->raw_mime : $this->thumb_mime;
+ public static function extension($mime) {
+
$data = explode("/",$mime);
$extension = $data['1'];
@@ -154,6 +150,65 @@ class Art extends database_object {
} // get_db
/**
+ * insert
+ * This takes the string representation of an image and inserts it into the database. You
+ * must also pass the mime type
+ */
+ public function insert($source,$mime) {
+
+ // Disabled in demo mode cause people suck and upload porn
+ if (Config::get('demo_mode')) { return false; }
+
+ // Do a low impact test is this image of any size?
+ if (strlen($image) < 10) {
+ debug_event('Art','Invalid Image passed, not inserting',1);
+ return false;
+ }
+
+ // Check to make sure PHP:GD exists if so we can sanity check this
+ // image
+ if (function_exists('ImageCreateFromString')) {
+ $image = ImageCreateFromString($image);
+ if (!$image OR imagesx($iamge) < 5 OR imagesy($image) < 5) {
+ debug_event('Art','Image failed PHP-GD test, not inserting',1);
+ return false;
+ }
+ } // if we have GD
+
+ // Default to image/jpeg if they don't pass anything
+ $mime = $mime ? $mime : 'image/jpeg';
+
+
+ $image = Dba::escape($image);
+ $mime = Dba::escape($mime);
+ $uid = Dba::escape($this->id);
+ $type = Dba::escape($this->type);
+
+ // Insert it!
+ $sql = "REPLACE INTO `" . $type . "_data` SET `art`='$image',`art_mime`='$mime', `" . $type . "_id`='$uid', " .
+ "`thumb`=NULL, `thumb_mime`=NULL";
+ $db_results = Dba::write($sql);
+
+ return true;
+
+ } // insert
+
+ /**
+ * clear
+ * This resets the art in the database
+ */
+ public function clear() {
+
+ $type = Dba::escape($this->type);
+ $uid = Dba::escape($this->id);
+
+ $sql = "UPDATE `" . $type . "_data` SET `art`=NULL, `art_mime`=NULL, `thumb`=NULL, `thumb_mime`=NULL " .
+ "WHERE `" . $type . "_id`='$uid'";
+ $db_results = Dba::write($sql);
+
+ } // clear
+
+ /**
* save_thumb
* This saves the thumbnail that we're passing
*/
@@ -262,4 +317,678 @@ class Art extends database_object {
} // generate_thumb
+ /**
+ * 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
+ */
+ public function get_from_source($data) {
+
+ // 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']);
+ $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;
+
+ } // get_from_source
+
+ /**
+ * url
+ * This returns the constructed URL for the art in question
+ */
+ public static function url($uid,$type,$sid=false) {
+
+ $sid = $sid ? scrub_out($sid) : scrub_out(session_id());
+ $type = self::validate_type($type);
+
+ $type = Dba::escape($type);
+ $uid = Dba::escape($uid);
+
+ $sql = "SELECT `art_mime`,`thumb_mime` FROM `" . $type . "_data` WHERE `" . $type . "_id`='$uid'";
+ $db_results = Dba::read($sql);
+
+ $row = Dba::fetch_assoc($db_results);
+
+ $mime = $row['thumb_mime'] ? $row['thumb_mime'] : $row['art_mime'];
+ $extension = self::extension($mime);
+
+ $name = 'art.' . $extension;
+ $url = Config::get('web_path') . '/image.php?id=' . scrub_out($uid) . 'object_type=' . scrub_out($type) . '&auth=' . $sid . '&name=' . $name;
+
+ return $url;
+
+ } // url
+
+ /**
+ * gather
+ * This tries to get the art in question
+ */
+ public function gather($options=array(),$limit) {
+
+ // Define vars
+ $results = array();
+
+ switch ($this->type) {
+ case 'album':
+ $allowed_methods = array('lastfm','folder','amazon','google','musicbrainz','tag');
+ break;
+ case 'artist':
+ $allowed_methods = array();
+ break;
+ case 'video':
+ $allowed_methods = array();
+ break;
+ }
+
+ $config = Config::get('art_order');
+ $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_value = array($config_value);
+ }
+
+ foreach ($config AS $method) {
+
+ $data = array();
+
+ $method_name = "gather_" . $method;
+ if (in_array($method_name,$class_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);
+
+ if ($total_results > $limit AND $limit > 0) {
+ return $results;
+ }
+
+ } // if the method exists
+
+ } // end foreach
+
+ return $results;
+
+ } // gather
+
+
+ ///////////////////////////////////////////////////////////////////////
+ // Art Methods
+ ///////////////////////////////////////////////////////////////////////
+
+ /**
+ * gather_musicbrainz
+ * This function retrives art based on MusicBrainz' Advanced Relationships
+ */
+ public function gather_musicbrainz($limit=0) {
+ $images = array();
+ $num_found = 0;
+ $mbquery = new MusicBrainzQuery();
+
+ if ($this->mbid) {
+ debug_event('mbz-gatherart', "Album MBID: " . $this->mbid, '5');
+ }
+ else {
+ return $images;
+ }
+
+ $includes = new mbReleaseIncludes();
+ try {
+ $release = $mbquery->getReleaseByID($this->mbid, $includes->urlRelations());
+ } catch (Exception $e) {
+ return $images;
+ }
+
+ $asin = $release->getAsin();
+
+ 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",
+ );
+ 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;
+ }
+ }
+ }
+ }
+ // 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',
+ 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]',
+ 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',
+ releaseuri => 'http://www.jamendo.com/album/$matches[2]',
+ );
+ $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',
+ releaseuri => 'http://www.encyclopedisque.fr/',
+ );
+ $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]',
+ releaseuri => '',
+ );
+ 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;
+ }
+ }
+ }
+ } // end foreach coverart sites
+ } // end foreach
+
+ return $images;
+
+ } // gather_musicbrainz
+
+ /**
+ * gather_amazon
+ * This takes keywords and performs a search of the AMazon website
+ * for the art. It returns an array of found objects with mime/url keys
+ */
+ 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;
+
+ } // gather_amazon
+
+ /**
+ * gather_folder
+ * This returns the art from the folder of the files
+ * If a limit is passed or the preferred filename is found the current results set
+ * is returned
+ */
+ public function gather_folder($limit=5) {
+
+ if (!count($this->_songs)) {
+ $this->_songs = $this->get_songs();
+ }
+ $data = array();
+
+ /* 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();
+
+ /* Thanks to dromio for origional code */
+ /* Added search for any .jpg, png or .gif - Vollmer */
+ foreach($this->_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');
+
+ /* 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');
+ }
+
+ /* 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 ($extension == 'jpg') { $extension = 'jpeg'; }
+
+ // 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; }
+
+ 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';
+
+ } // end if it's an image
+
+ } // end while reading dir
+ @closedir($handle);
+
+ if (!empty($limit) && $limit < count($data)) {
+ return $data;
+ }
+
+ } // end foreach songs
+
+ return $data;
+
+ } // gather_folder
+
+ /**
+ * gather_tags
+ * This looks for the art in the meta-tags of the file
+ * itself
+ */
+ public function gather_tags($limit=5) {
+
+ // 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;
+
+ } // gather_tags
+
+ /**
+ * gather_google
+ * Raw google search to retrive the art, not very reliable
+ */
+ public function gather_google($limit=5) {
+
+ $images = array();
+ $media = new $this->type($this->uid);
+ $media->format();
+
+ $search = $media->full_name;
+
+ if ($media->artist_count == '1')
+ $search = $media->artist_name . ', ' . $search;
+
+ $search = rawurlencode($search);
+
+ $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");
+
+ 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);
+
+ $images[] = array('url' => $match, 'mime' => $extension);
+ }
+
+ return $images;
+
+ } // gather_google
+
+ /**
+ * gather_lastfm
+ * This returns the art from lastfm. It doesn't require an account currently
+ * but may in the future
+ */
+ public function gather_lastfm($limit,$options=false) {
+
+ // Create the parser object
+ $lastfm = new LastFMSearch();
+
+ switch ($this->type) {
+ case 'album':
+ 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;
+ }
+ 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 (!count($raw_data)) { return array(); }
+
+ $coverart = $raw_data['coverart'];
+
+ ksort($coverart);
+
+ 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;
+ }
+
+ $results = pathinfo($url);
+ $mime = 'image/' . $results['extension'];
+ $data[] = array('url'=>$url,'mime'=>$mime);
+ if ($i >= $limit) { return $data; }
+ } // end foreach
+
+ return $data;
+
+ } // gather_lastfm
+
} // Art
diff --git a/lib/general.lib.php b/lib/general.lib.php
index c13d6a99..0245d0f7 100644
--- a/lib/general.lib.php
+++ b/lib/general.lib.php
@@ -216,7 +216,7 @@ function generate_password($length) {
function scrub_out($str) {
//This feature has been DEPRECATED as of PHP 5.3.0
- if(version_compare(PHP_VERSION, '5.3.0', '<=') AND get_magic_quotes_gpc()) {
+ if(version_compare(PHP_VERSION, '5.3.0', '<=') AND ini_get('magic_quotes_gpc') != 'Off') {
$str = stripslashes($str);
}