diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2010-04-01 12:04:08 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2010-04-01 12:04:08 +0000 |
commit | 0dc4669407da527bca635342ed6721242ff629ca (patch) | |
tree | 47eb11a8d247d2dbb9aadc72e2d26576dd23aa3c /lib/class/album.class.php | |
parent | 06bb1969f0738ed2466d799307c83211abc3fe22 (diff) | |
download | ampache-0dc4669407da527bca635342ed6721242ff629ca.tar.gz ampache-0dc4669407da527bca635342ed6721242ff629ca.tar.bz2 ampache-0dc4669407da527bca635342ed6721242ff629ca.zip |
Remove album art functions from album class, this most likely breaks things
Diffstat (limited to 'lib/class/album.class.php')
-rw-r--r-- | lib/class/album.class.php | 625 |
1 files changed, 0 insertions, 625 deletions
diff --git a/lib/class/album.class.php b/lib/class/album.class.php index bf8c6d40..ebc3a7f0 100644 --- a/lib/class/album.class.php +++ b/lib/class/album.class.php @@ -275,631 +275,6 @@ class Album extends database_object { } // format /** - * get_art - * This function only pulls art from the database, if thumb is passed - * it trys to pull the resized art instead, if resized art is found then - * it returns an additional resized=true in the array - */ - public function get_art($return_raw=false) { - - // Attempt to get the resized art first - if (!$return_raw) { - $art = $this->get_resized_db_art(); - } - - if (!is_array($art)) { - $art = $this->get_db_art(); - } - - return $art['0']; - - } // get_art - - /** - * find_art - * This function searches for album art using all configured methods - * for the current album. There is an optional 'limit' passed that will - * gather up to the specified number of possible album covers. - * There is also an optional array of options the possible options are - * ['keyword'] = STRING - * ['artist'] = STRING - * ['album_name'] = STRING - */ - public function find_art($options=array(),$limit='') { - - /* Create Base Vars */ - $results = array(); - - /* Attempt to retrive the album art order */ - $config_value = Config::get('album_art_order'); - $class_methods = get_class_methods('Album'); - - /* If it's not set */ - if (empty($config_value)) { - // They don't want art! - return array(); - } - elseif (!is_array($config_value)) { - $config_value = array($config_value); - } - - foreach ($config_value AS $method) { - - $data = array(); - - $method_name = "get_" . $method . "_art"; - if (in_array($method_name,$class_methods)) { - // Some of these take options! - switch ($method_name) { - case 'get_amazon_art': - $data = $this->{$method_name}($options['keyword'],$limit); - break; - case 'get_lastfm_art': - $data = $this->{$method_name}($limit,$options); - break; - case 'get_google_art': - $data = $this->{$method_name}($limit); - 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; - - } // find_art - - /** - * get_lastfm_art - * This returns the art as pulled from lastFM. This doesn't require - * a special account, we just parse and run with it. - */ - public function get_lastfm_art($limit,$options='') { - - // Create the parser object - $lastfm = new LastFMSearch(); - - if (is_array($options)) { - $artist = $options['artist']; - $album = $options['album_name']; - } - else { - $artist = $this->artist_name; - $album = $this->full_name; - } - - 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; - - } // get_lastfm_art - - /** - * get_google_art - * This retrieves art by searching google image search - */ - public function get_google_art($limit='') { - $images = array(); - - $search = $this->full_name; - - if ($this->artist_count == '1') - $search = $this->artist_name . ', ' . $search; - - $search = rawurlencode($search); - - //$size = ''; // Any - $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; - } // get_google_art - - /*! - @function get_id3_art - @discussion looks for art from the id3 tags - */ - function get_id3_art($limit='') { - - // grab the songs and define our results - if (!count($this->_songs)) { - $this->_songs = $this->get_songs(); - } - $data = array(); - - // Foreach songs in this album - foreach ($this->_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; - - } // get_id3_art - - /** - * get_folder_art() - * returns the album art from the folder of the audio files - * If a limit is passed or the preferred filename is found the current results set - * is returned - */ - function get_folder_art($limit='') { - - 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; - - } // get_folder_art - - /** - * get_resized_db_art - * This looks to see if we have a resized thumbnail that we can load rather then taking - * the fullsized and resizing that - */ - public function get_resized_db_art() { - - $id = Dba::escape($this->id); - - $sql = "SELECT `thumb` AS `art`,`thumb_mime` AS `art_mime` FROM `album_data` WHERE `album_id`='$id'"; - $db_results = Dba::read($sql); - - $results = Dba::fetch_assoc($db_results); - if (strlen($results['art_mime'])) { - $results['resized'] = true; - } - else { return false; } - - $data = array(array('db_resized'=>$this->id,'raw'=>$results['art'],'mime'=>$results['art_mime'])); - - return $data; - - } // get_resized_db_art - - /** - * get_db_art - * returns the album art from the db along with the mime type - */ - public function get_db_art() { - - $sql = "SELECT `art`,`art_mime` FROM `album_data` WHERE `album_id`='$this->id'"; - $db_results = Dba::read($sql); - - $results = Dba::fetch_assoc($db_results); - - if (!$results['art']) { return array(); } - - $data = array(array('db'=>$this->id,'raw'=>$results['art'],'mime'=>$results['art_mime'])); - - return $data; - - } // get_db_art - - /** - * get_musicbrainz_art - * This retrieves art based on MusicBrainz' Advanced Relationships - */ - public function get_musicbrainz_art($limit='') { - $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; - - } // get_musicbrainz_art - - /** - * get_amazon_art - * This takes keywords and performs a search of the Amazon website - * for album art. It returns an array of found objects with mime/url keys - */ - public function get_amazon_art($keywords = '',$limit='') { - - $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) . " results found",'5'); - - // 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; - - } // get_amazon_art - - /** * get_random_songs * gets a random number, and a random assortment of songs from this album */ |