summaryrefslogtreecommitdiffstats
path: root/lib/class
diff options
context:
space:
mode:
authorPaul 'flowerysong' Arthur <flowerysong00@yahoo.com>2010-05-09 19:50:35 +0000
committerPaul 'flowerysong' Arthur <flowerysong00@yahoo.com>2010-05-09 19:50:35 +0000
commit3a5a8dad2e8ddc0162496baa3f839651c05b2843 (patch)
treee974f8ea0c9e60435a80092ab7537fbd6cba0339 /lib/class
parent5e4162cd0ada44796008c6d1cafb98ecf62226c1 (diff)
downloadampache-3a5a8dad2e8ddc0162496baa3f839651c05b2843.tar.gz
ampache-3a5a8dad2e8ddc0162496baa3f839651c05b2843.tar.bz2
ampache-3a5a8dad2e8ddc0162496baa3f839651c05b2843.zip
Some more Art-related cleanup. Removing references to album_data, removing old
art methods from Album, etc. Should fix FS#76
Diffstat (limited to 'lib/class')
-rw-r--r--lib/class/album.class.php245
-rw-r--r--lib/class/art.class.php21
-rw-r--r--lib/class/catalog.class.php89
-rw-r--r--lib/class/xmldata.class.php4
4 files changed, 82 insertions, 277 deletions
diff --git a/lib/class/album.class.php b/lib/class/album.class.php
index ebc3a7f0..3e56151e 100644
--- a/lib/class/album.class.php
+++ b/lib/class/album.class.php
@@ -36,12 +36,6 @@ class Album extends database_object {
public $prefix;
public $mbid; // MusicBrainz ID
- /* Art Related Fields */
- public $art;
- public $art_mime;
- public $thumb;
- public $thumb_mime;
-
// cached information
public $_songs=array();
@@ -111,18 +105,22 @@ class Album extends database_object {
// If we're extra'ing cache the extra info as well
if ($extra) {
- $sql = "SELECT COUNT(DISTINCT(song.artist)) as artist_count,COUNT(song.id) AS song_count,artist.name AS artist_name" .
- ",artist.prefix AS artist_prefix,album_data.art AS has_art,album_data.thumb AS has_thumb, artist.id AS artist_id,`song`.`album`".
+ $sql = "SELECT COUNT(DISTINCT(`song`.`artist`)) AS `artist_count`, " .
+ "COUNT(`song`.`id`) AS `song_count`, " .
+ "`artist`.`name` AS `artist_name`, " .
+ "`artist`.`prefix` AS `artist_prefix`, " .
+ "`artist`.`id` AS `artist_id`, `song`.`album`" .
"FROM `song` " .
"INNER JOIN `artist` ON `artist`.`id`=`song`.`artist` " .
- "LEFT JOIN `album_data` ON `album_data`.`album_id` = `song`.`album` " .
"WHERE `song`.`album` IN $idlist GROUP BY `song`.`album`";
$db_results = Dba::read($sql);
while ($row = Dba::fetch_assoc($db_results)) {
- $row['has_art'] = make_bool($row['has_art']);
- $row['has_thumb'] = make_bool($row['has_thumb']);
+ $art = new Art($row['album'], 'album');
+ $art->get_db();
+ $row['has_art'] = make_bool($art->raw);
+ $row['has_thumb'] = make_bool($art->thumb);
parent::add_to_cache('album_extra',$row['album'],$row);
} // while rows
} // if extra
@@ -143,17 +141,18 @@ class Album extends database_object {
}
$sql = "SELECT COUNT(DISTINCT(song.artist)) as artist_count,COUNT(song.id) AS song_count,artist.name AS artist_name" .
- ",artist.prefix AS artist_prefix,album_data.art AS has_art,album_data.thumb AS has_thumb, artist.id AS artist_id ".
+ ",artist.prefix AS artist_prefix, artist.id AS artist_id ".
"FROM `song` " .
"INNER JOIN `artist` ON `artist`.`id`=`song`.`artist` " .
- "LEFT JOIN `album_data` ON `album_data`.`album_id` = `song`.`album` " .
"WHERE `song`.`album`='$this->id' GROUP BY `song`.`album`";
$db_results = Dba::read($sql);
$results = Dba::fetch_assoc($db_results);
- if ($results['has_art']) { $results['has_art'] = 1; }
- if ($results['has_thumb']) { $results['has_thumb'] = 1; }
+ $art = new Art($this->id, 'album');
+ $art->get_db();
+ $results['has_art'] = make_bool($art->raw);
+ $results['has_thumb'] = make_bool($art->thumb);
parent::add_to_cache('album_extra',$this->id,$results);
@@ -188,25 +187,6 @@ class Album extends database_object {
} // get_songs
/**
- * has_art
- * This returns true or false depending on if we find any art for this
- * album.
- */
- public function has_art() {
-
- $sql = "SELECT `album_id` FROM `album_data` WHERE `album_id`='" . $this->id . "' AND art IS NOT NULL";
- $db_results = Dba::read($sql);
-
- if (Dba::fetch_assoc($db_results)) {
- $this->has_art = true;
- return true;
- }
-
- return false;
-
- } // has_art
-
- /**
* has_track
* This checks to see if this album has a track of the specified title
*/
@@ -343,74 +323,6 @@ class Album extends database_object {
} // update
/**
- * clear_art
- * clears the album art from the DB
- */
- public function clear_art() {
-
- $sql = "UPDATE `album_data` SET `art`=NULL, `art_mime`=NULL, `thumb`=NULL, `thumb_mime`=NULL WHERE `album_id`='$this->id'";
- $db_results = Dba::write($sql);
-
- } // clear_art
-
- /**
- * insert_art
- * this takes a string representation of an image
- * and inserts it into the database. You must pass the mime type as well
- */
- public function insert_art($image, $mime) {
-
- /* Have to disable this for Demo because people suck and try to
- * insert PORN :(
- */
- if (Config::get('demo_mode')) { return false; }
-
- // Check for PHP:GD and if we have it make sure this image is of some size
- if (function_exists('ImageCreateFromString')) {
- $im = ImageCreateFromString($image);
- if (imagesx($im) <= 5 || imagesy($im) <= 5 || !$im) {
- return false;
- }
- } // if we have PHP:GD
- elseif (strlen($image) < 5) {
- return false;
- }
-
- // Default to image/jpeg as a guess if there is no passed mime type
- $mime = $mime ? $mime : 'image/jpeg';
-
- // Push the image into the database
- $sql = "REPLACE INTO `album_data` SET `art` = '" . Dba::escape($image) . "'," .
- " `art_mime` = '" . Dba::escape($mime) . "'" .
- ", `album_id` = '$this->id'," .
- "`thumb` = NULL, `thumb_mime`=NULL";
- $db_results = Dba::write($sql);
-
- return true;
-
- } // insert_art
-
- /**
- * save_resized_art
- * This takes data from a gd resize operation and saves
- * it back into the database as a thumbnail
- */
- public static function save_resized_art($data,$mime,$album) {
-
- // Make sure there's actually something to save
- if (strlen($data) < '5') { return false; }
-
- $data = Dba::escape($data);
- $mime = Dba::escape($mime);
- $album = Dba::escape($album);
-
- $sql = "UPDATE `album_data` SET `thumb`='$data',`thumb_mime`='$mime' " .
- "WHERE `album_data`.`album_id`='$album'";
- $db_results = Dba::write($sql);
-
- } // save_resized_art
-
- /**
* get_random_albums
* This returns a random number of albums from the catalogs
* this is used by the index to return some 'potential' albums to play
@@ -420,137 +332,22 @@ class Album extends database_object {
$sql = 'SELECT `id` FROM `album` ORDER BY RAND() LIMIT ' . ($count*2);
$db_results = Dba::read($sql);
- $in_sql = '`album_id` IN (';
-
while ($row = Dba::fetch_assoc($db_results)) {
- $in_sql .= "'" . $row['id'] . "',";
- $total++;
+ $art = new Art($row['id'], 'album');
+ $art->get_db();
+ if ($art->raw) {
+ $results[] = $row['id'];
+ }
}
- if ($total < $count) { return false; }
+ if (count($results) < $count) { return false; }
- $in_sql = rtrim($in_sql,',') . ')';
-
- $sql = "SELECT `album_id`,ISNULL(`art`) AS `no_art` FROM `album_data` WHERE $in_sql";
- $db_results = Dba::read($sql);
- $results = array();
-
- while ($row = Dba::fetch_assoc($db_results)) {
- $results[$row['album_id']] = $row['no_art'];
- } // end for
-
- asort($results);
- $albums = array_keys($results);
- $results = array_slice($albums,0,$count);
+ $results = array_slice($results, 0, $count);
return $results;
} // get_random_albums
- /**
- * get_image_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 static function get_image_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
- $album_id = Dba::escape($data['db']);
- $sql = "SELECT * FROM `album_data` WHERE `album_id`='$album_id'";
- $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_image_from_source
-
- /**
- * get_art_url
- * This returns the art URL for the album
- */
- public static function get_art_url($album_id,$sid=false) {
-
- $sid = $sid ? scrub_out($sid) : session_id();
-
- $sql = "SELECT `art_mime`,`thumb_mime` FROM `album_data` WHERE `album_id`='" . Dba::escape($album_id) . "'";
- $db_results = Dba::read($sql);
-
- $row = Dba::fetch_assoc($db_results);
-
- $mime = $row['thumb_mime'] ? $row['thumb_mime'] : $row['art_mime'];
-
- switch ($type) {
- case 'image/gif':
- $type = 'gif';
- break;
- case 'image/png':
- $type = 'png';
- break;
- default:
- case 'image/jpeg':
- $type = 'jpg';
- break;
- } // end type translation
-
- $name = 'art.' . $type;
-
- $url = Config::get('web_path') . '/image.php?id=' . scrub_out($album_id) . '&auth=' . $sid . '&name=' . $name;
-
- return $url;
-
- } // get_art_url
-
} //end of album class
?>
diff --git a/lib/class/art.class.php b/lib/class/art.class.php
index 9f306380..da4f6015 100644
--- a/lib/class/art.class.php
+++ b/lib/class/art.class.php
@@ -457,6 +457,27 @@ class Art extends database_object {
} // url
+
+ /**
+ * clean
+ * This cleans up art that no longer has a corresponding object
+ */
+ public static function clean() {
+ // iterate over our types and delete the images
+ foreach (array('album', 'artist') as $type) {
+ $sql = "DELETE FROM `image` USING `image` LEFT JOIN `" .
+ $type . "` ON `" . $type . "`.`id`=" .
+ "`image`.`object_id` WHERE `object_type`='" .
+ $type . "' AND `source`.`id` IS NULL";
+ $db_results = Dba::write($sql);
+ } // foreach
+
+ // Optimize the table, large potential space savings
+ $sql = "OPTIMIZE TABLE `image`";
+ $db_results = Dba::write($sql);
+ } // clean
+
+
/**
* gather
* This tries to get the art in question
diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php
index 03166b5d..cdc20ec2 100644
--- a/lib/class/catalog.class.php
+++ b/lib/class/catalog.class.php
@@ -749,26 +749,18 @@ class Catalog extends database_object {
* This generates the thumbnails from the images for object
* of this catalog
*/
- public function generate_thumbnails($override=false) {
-
- $limit = $override ? '' : ' AND `thumb_mime` IS NULL';
+ public function generate_thumbnails() {
// Albums first
$albums = $this->get_album_ids();
- $idlist = '(' . implode(',', $albums) . ')';
-
- $sql = "SELECT `album_id`,`art`,`art_mime` FROM `album_data` WHERE `album_id` IN $idlist $limit";
- $db_results = Dba::read($sql);
-
// Start the ticker
$ticker = time();
$thumb_count = 0;
- while ($row = Dba::fetch_assoc($db_results)) {
- $art = new Art($row['album_id'],'album');
- $data = $art->generate_thumb($row['art'],array('width'=>275,'height'=>275),$row['art_mime']);
- $art->save_thumb($data['thumb'], $data['thumb_mime'], '275x275');
+ foreach ($albums as $album) {
+ $art = new Art($album, 'album');
+ $image = $art->get();
/* Stupid little cutesie thing */
$thumb_count++;
@@ -780,7 +772,7 @@ class Catalog extends database_object {
$ticker = time();
} //echos thumb count
- } // end while albums
+ } // end foreach albums
echo "<script type=\"text/javascript\">\n";
echo "update_txt('" . $search_count ."','count_thumb_" . $this->id . "');";
@@ -931,38 +923,32 @@ class Catalog extends database_object {
} // get_duplicate_info
/**
- * dump_album_art (Added by Cucumber 20050216)
- * This runs through all of the albums and trys to dump the
+ * dump_album_art
+ * This runs through all of the albums and tries to dump the
* art for them into the 'folder.jpg' file in the appropriate dir
*/
- public static function dump_album_art($catalog_id,$methods=array()) {
+ public static function dump_album_art($catalog_id, $methods=array()) {
// Get all of the albums in this catalog
$albums = self::get_catalog_albums($catalog_id);
echo "Starting Dump Album Art...\n";
- // Run through them an get the art!
+ // Run through them and get the art!
foreach ($albums as $album_id) {
$album = new Album($album_id);
-
+ $art = new Art($album_id, 'album');
+
// If no art, skip
- if (!$album->has_art()) { continue; }
+ if ( ! $art->get_db() ) { continue; }
- $image = $album->get_db_art();
-
- /* Get the first song in the album */
+ // Get the first song in the album
$songs = $album->get_songs(1);
$song = new Song($songs[0]);
$dir = dirname($song->file);
- if ($image['0']['mime'] == 'image/jpeg') {
- $extension = 'jpg';
- }
- else {
- $extension = substr($image['0']['mime'],strlen($image['0']['mime'])-3,3);
- }
+ $extension = Art::extension($art->raw_mime);
// Try the preferred filename, if that fails use folder.???
$preferred_filename = Config::get('album_art_preferred_filename');
@@ -970,9 +956,10 @@ class Catalog extends database_object {
$file = "$dir/$preferred_filename";
if ($file_handle = fopen($file,"w")) {
- if (fwrite($file_handle, $image['0']['raw'])) {
+ if (fwrite($file_handle, $art->raw)) {
- // Also check and see if we should write out some meta data
+ // Also check and see if we should write
+ // out some metadata
if ($methods['metadata']) {
switch ($methods['metadata']) {
case 'windows':
@@ -1549,12 +1536,13 @@ class Catalog extends database_object {
debug_event($label, "image_url: " . $server_path,'4');
$data['url'] = $server_path;
- $local_album = new Album($local_album_id);
- $image_data = $local_album->get_image_from_source($data);
+ $local_art = new Art($local_album_id, 'album');
+ $image_data = $local_art->get_from_source($data);
// If we got something back insert it
if ($image_data) {
- $local_album->insert_art($image_data,"");
+ // TODO: Null argument looks broken
+ $local_art->insert($image_data, "");
$total_updated++;
debug_event($label, "adding album image succes", '4');
} else {
@@ -1774,12 +1762,7 @@ class Catalog extends database_object {
$db_results = Dba::write($sql);
/* Now remove any album art that is now dead */
- $sql = "DELETE FROM `album_data` USING `album_data` LEFT JOIN `album` ON `album`.`id`=`album_data`.`album_id` WHERE `album`.`id` IS NULL";
- $db_results = Dba::write($sql);
-
- // This can save a lot of space so always optomize
- $sql = "OPTIMIZE TABLE `album_data`";
- $db_results = Dba::write($sql);
+ Art::clean();
} // clean_albums
@@ -1805,6 +1788,9 @@ class Catalog extends database_object {
$sql = "DELETE FROM artist USING artist LEFT JOIN song ON song.artist = artist.id WHERE song.id IS NULL";
$db_results = Dba::write($sql);
+ // Now remove any dead art
+ Art::clean();
+
} //clean_artists
/**
@@ -2047,22 +2033,23 @@ class Catalog extends database_object {
/**
* optimize_tables
- * This runs an optomize on the tables and updates the stats to improve join speed
- * this can be slow, but is a good idea to do from time to time. This is incase the dba
- * isn't doing it... which we're going to assume they aren't
+ * This runs an optimize on the tables and updates the stats to improve
+ * join speed.
+ * This can be slow, but is a good idea to do from time to time. We do
+ * it in case the dba isn't doing it... which we're going to assume they
+ * aren't
*/
public static function optimize_tables() {
+ $sql = "SHOW TABLES";
+ $db_results = Dba::read($sql);
- $sql = "OPTIMIZE TABLE `song_data`,`song`,`rating`,`catalog`,`session`,`object_count`,`album`,`album_data`" .
- ",`artist`,`ip_history`,`flagged`,`now_playing`,`user_preference`,`tag`,`tag_map`,`tmp_playlist`" .
- ",`tmp_playlist_data`,`playlist`,`playlist_data`,`session_stream`,`video`";
- $db_results = Dba::write($sql);
-
- $sql = "ANALYZE TABLE `song_data`,`song`,`rating`,`catalog`,`session`,`object_count`,`album`,`album_data`" .
- ",`artist`,`ip_history`,`flagged`,`now_playing`,`user_preference`,`tag`,`tag_map`,`tmp_playlist`" .
- ",`tmp_playlist_data`,`playlist`,`playlist_data`,`session_stream`,`video`";
- $db_results = Dba::write($sql);
+ while($row = Dba::fetch_row($db_results)) {
+ $sql = "OPTIMIZE TABLE `" . $row[0] . "`";
+ $db_results_inner = Dba::write($sql);
+ $sql = "ANALYZE TABLE `" . $row[0] . "`";
+ $db_results_inner = Dba::write($sql);
+ }
} // optimize_tables;
/**
diff --git a/lib/class/xmldata.class.php b/lib/class/xmldata.class.php
index 26015f1f..2ce5a8eb 100644
--- a/lib/class/xmldata.class.php
+++ b/lib/class/xmldata.class.php
@@ -362,7 +362,7 @@ class xmlData {
$rating = new Rating($song_id,'song');
- $art_url = Album::get_art_url($song->album,$_REQUEST['auth']);
+ $art_url = Art::url($song->album, 'album', $_REQUEST['auth']);
$string .= "<song id=\"$song->id\">\n" .
"\t<title><![CDATA[$song->title]]></title>\n" .
@@ -450,7 +450,7 @@ class xmlData {
$rating = new Rating($song_id,'song');
- $art_url = Album::get_art_url($song->album,$_REQUEST['auth']);
+ $art_url = Art::url($song->album, 'album', $_REQUEST['auth']);
$string .= "<song id=\"$song->id\">\n" .
"\t<title><![CDATA[$song->title]]></title>\n" .