summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl 'vollmerk' Vollmer <vollmer@ampache.org>2005-12-16 09:53:55 +0000
committerKarl 'vollmerk' Vollmer <vollmer@ampache.org>2005-12-16 09:53:55 +0000
commit8a847a4efd25e5b419886e55d55bc4fd9b9e55c9 (patch)
treea48b40f5a1f4f0673c7b87c9cabfc5ec0cc3b05b
parent961bf509d45dee506d3914c0f7c839311ec3b7c6 (diff)
downloadampache-8a847a4efd25e5b419886e55d55bc4fd9b9e55c9.tar.gz
ampache-8a847a4efd25e5b419886e55d55bc4fd9b9e55c9.tar.bz2
ampache-8a847a4efd25e5b419886e55d55bc4fd9b9e55c9.zip
some of the more unattractive code Ive commited in a while...
-rw-r--r--albums.php51
-rwxr-xr-xdocs/CHANGELOG3
-rw-r--r--lib/class/album.class.php141
-rw-r--r--modules/amazon/AmazonSearchEngine.class.php6
-rw-r--r--templates/show_album_art.inc.php73
5 files changed, 199 insertions, 75 deletions
diff --git a/albums.php b/albums.php
index 67d075c9..96596c54 100644
--- a/albums.php
+++ b/albums.php
@@ -71,7 +71,7 @@ elseif ($_REQUEST['action'] === 'find_art') {
// adding retry to album art searching. I hope my PHP style doesn't make vollmer cry,
// because that would make me cry...then my girlfriend would cry...then my cat would laugh.
// She's such a little trouper!
-
+ // *NOTE* I knocked it up a notch with some more horrible code :S - Vollmer
/* Echo notice if no amazon token is found, but it's enabled */
if (in_array('amazon',conf('album_art_order')) AND !conf('amazon_developer_key')) {
@@ -81,13 +81,26 @@ elseif ($_REQUEST['action'] === 'find_art') {
// get the Album information
$album = new Album($_REQUEST['album_id']);
- // Attempt to find the art with what we've got
- $result = $album->find_art($_REQUEST['cover'], $_REQUEST['artist_name'], $_REQUEST['album_name']);
+ if ($_REQUEST['artist_name']) {
+ $artist = scrub_in($_REQUEST['artist_name']);
+ }
+ else {
+ $artist = $album->artist;
+ }
+
+ if ($_REQUEST['album_name']) {
+ $album_name = scrub_in($_REQUEST['album_name']);
+ }
+ else {
+ $album_name = $album->name;
+ }
- if ($result) {
- show_confirmation(_("Album Art Located"),_("Album Art information has been located in Amazon. If incorrect, click \"Reset Album Art\" below to remove the artwork."),"/albums.php?action=show&amp;album=" . $album->id);
- echo "&nbsp;[ <a href=\"" . conf('web_path') . "/albums.php?action=clear_art&amp;album_id=" . $album->id . "\">Reset Album Art</a> ]";
- echo "<p align=left><img src=\"" . conf('web_path') . "/albumart.php?id=" . $album->id . "\" /></p>";
+ // Attempt to find the art with what we've got
+ $images = $album->find_art($_REQUEST['cover'], $artist . " " . $album_name);
+ $_SESSION['form']['images'] = $images;
+
+ if (count($images)) {
+ include(conf('prefix') . '/templates/show_album_art.inc.php');
}
else {
show_confirmation(_("Album Art Not Located"),_("Album Art could not be located at this time. This may be due to Amazon being busy, or the album not being present in their collection."),"/albums.php?action=show&amp;album=" . $album->id);
@@ -104,6 +117,30 @@ elseif ($_REQUEST['action'] === 'find_art') {
} // find_art
+// Selecting image from find_art
+elseif ($_REQUEST['action'] === 'select_art') {
+
+ /* Check to see if we have the image url still */
+ $image_id = $_REQUEST['image'];
+ $album_id = $_REQUEST['album_id'];
+
+ $url = $_SESSION['form']['images'][$image_id]['url'];
+ $mime = $_SESSION['form']['images'][$image_id]['mime'];
+ $snoopy = new Snoopy();
+ $snoopy->fetch($url);
+
+ $image_data = $snoopy->results;
+
+ $album = new Album($album_id);
+ $album->insert_art($image_data,$mime);
+
+ $msg = "<br />\n<img src=\"" . conf('web_path') . "/albumart.php?id=$album_id\" width=\"175\" height=\"175\" /><br />";
+
+ show_confirmation(_("Album Art Inserted"),$msg,"/albums.php?action=show&album=$album_id");
+
+
+} // end select art
+
// Updates Album from tags
elseif ($_REQUEST['action'] === 'update_from_tags') {
diff --git a/docs/CHANGELOG b/docs/CHANGELOG
index 2dad9f50..a4e2db04 100755
--- a/docs/CHANGELOG
+++ b/docs/CHANGELOG
@@ -4,6 +4,9 @@
--------------------------------------------------------------------------
v.3.3.2-Alpha4
+ - Fixed a flaw in album art search which only returned a single
+ result, now shows all results and allows you to pick
+ the correct one.
- Added ability to re-define album art search (Thx csammis)
https://ampache.bountysource.com/Task.View?task_id=86
- Fixed a logic flaw where it would attempt to parse the m3u
diff --git a/lib/class/album.class.php b/lib/class/album.class.php
index 9a4ecd6c..12f0af24 100644
--- a/lib/class/album.class.php
+++ b/lib/class/album.class.php
@@ -205,10 +205,7 @@ class Album {
$mime = $image['mime'];
// Stick it in the db for next time
- $sql = "UPDATE album SET art = '" . sql_escape($art) . "'," .
- " art_mime = '" . sql_escape($mime) . "'" .
- " WHERE id = '" . $this->id . "'";
- $db_result = mysql_query($sql, dbh());
+ $this->insert_art($art,$mime);
return true;
} // end if image
@@ -239,7 +236,7 @@ class Album {
if (!is_resource($handle)) {
echo "<font class=\"error\">" . _("Error: Unable to open") . " $dir</font><br />\n";
- if (conf('debug')) { log_event($GLOBALS['user']->username,' read ',"Error: Unable to open $dir for album art read"); }
+ if (conf('debug')) { log_event($GLOBALS['user']->username,'read',"Error: Unable to open $dir for album art read"); }
}
/* Recurse through this dir and create the files array */
@@ -277,10 +274,7 @@ class Album {
$art .= fread($handle, 1024);
}
fclose($handle);
- $sql = "UPDATE album SET art = '" . sql_escape($art) . "'," .
- " art_mime = '" . sql_escape($mime) . "'" .
- " WHERE id = '$this->id'";
- $db_results = mysql_query($sql, dbh());
+ $this->insert_art($art,$mime);
return true;
} // if found
} // end foreach songs
@@ -312,7 +306,17 @@ class Album {
*/
function get_amazon_art() {
- return $this->find_art();
+ $results = $this->find_art();
+
+ if (count($results) < 1) { return false; }
+
+ $snoopy = new Snoopy();
+ $snoopy->fetch($results['0']['url']);
+ $data = $snoopy->results;
+
+ $this->insert_art($data,$results['0']['mime']);
+
+ return true;
} // get_amazon_art
@@ -349,6 +353,32 @@ class Album {
} // clear_art
/*!
+ @function insert_art
+ @discussion this takes a string representation of an image
+ and inserts it into the database. You must pass the
+ mime type as well
+ */
+ function insert_art($image, $mime) {
+
+ // 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) == 1 || @imagesy($im) == 1 && $im) {
+ return false;
+ }
+ } // if we have PHP:GD
+
+ // Push the image into the database
+ $sql = "UPDATE album SET art = '" . sql_escape($image) . "'," .
+ " art_mime = '" . sql_escape($mime) . "'" .
+ " WHERE id = '$this->id'";
+ $db_results = mysql_query($sql, dbh());
+
+ return true;
+
+ } // insert_art
+
+ /*!
@function find_art
@discussion searches amazon or a url
for the album art
@@ -359,102 +389,79 @@ class Album {
// search a little; replaced $this->name with $albumname and $this->artist with $artist.
// See /albums.php, ~line 80, for where these values are coming from.
*/
- function find_art($coverurl = '', $artist = '', $albumname = '') {
+ function find_art($coverurl = '', $keywords = '') {
+
+ $images = array();
+ $final_results = array();
+ $possible_keys = array("LargeImage","MediumImage","SmallImage");
+
+ /* We're gonna need this object */
+ $snoopy = new Snoopy();
+
+ // Prevent the script from timing out
+ set_time_limit(0);
// No coverurl specified search amazon
if (empty($coverurl)) {
- // Prevent the script from timing out
- set_time_limit(0);
-
- // csammis: Assign defaults to the arguments if they are empty
- if(empty($artist)) {
- $artist = $this->artist;
+ if (empty($keywords)) {
+ $keywords = $this->name . ' ' . $this->artist;
}
- if(empty($albumname)) {
- $albumname = $this->name;
- }
-
+
// Create the Search Object
$amazon = new AmazonSearch(conf('amazon_developer_key'));
-
- $search_term = $artist . " " . $albumname;
-
- $amazon->search(array('artist' => $artist, 'album' => $albumname, 'keywords' => $serch_term));
+
+ $search_results = $amazon->search(array('artist' => $artist, 'album' => $albumname, 'keywords' => $keywords));
// Only do the second search if the first actually returns something
- if (count($amazon->results)) {
- $amazon->lookup($amazon->results);
+ if (count($search_results)) {
+ $final_results = $amazon->lookup($search_results);
}
/* Log this if we're doin debug */
if (conf('debug')) {
- log_event($_SESSION['userdata']['username'],' amazon-xml ',"Searched using $search_term with " . conf('amazon_developer_key') . " as key " . count($amazon->results) . " results found");
+ log_event($GLOBALS['user']->username,'amazon-xml',"Searched using $search_term with " . conf('amazon_developer_key') . " as key " . count($final_results) . " results found");
}
- //FIXME: For now just pull the first one we find
- foreach ($amazon->results as $key=>$value) {
- $results = $value;
- break;
- } //FIXME
-
} // if no cover
// If we've specified a coverurl, create a fake Amazon array with it
else {
- $results = array('LargeImage' => $coverurl);
+ $final_results = array(array('LargeImage' => $coverurl));
}
- // If we have results of some kind
- if (is_array($results)) {
+ /* Foreach through what we've found */
+ foreach ($final_results as $result) {
/* Recurse through the images found */
- $possible_keys = array("LargeImage","MediumImage","SmallImage");
-
foreach ($possible_keys as $key) {
- if (strlen($results[$key])) {
+ if (strlen($result[$key])) {
break;
}
-
-
} // foreach
// Rudimentary image type detection, only JPG and GIF allowed.
- if (substr($results[$key], -4 == ".jpg")) {
+ if (substr($result[$key], -4 == ".jpg")) {
$mime = "image/jpg";
}
- elseif (substr($results[$key], -4 == ".gif")) {
+ elseif (substr($result[$key], -4 == ".gif")) {
$mime = "image/gif";
}
else {
- return false;
- }
-
- /* Create Snoopy Object and pull info */
- $snoopy = new Snoopy;
- $snoopy->fetch($results[$key]);
- $art = $snoopy->results;
-
- // Skip 1x1 size images
- if (function_exists('ImageCreateFromString')) {
- $im = @ImageCreateFromString($art);
- if (@imagesx($im) == 1 || @imagesy($im) == 1 && $im) {
- return false;
- }
+ /* Just go to the next result */
+ continue;
}
- // Push the image into the database
- $sql = "UPDATE album SET art = '" . sql_escape($art) . "'," .
- " art_mime = '" . sql_escape($mime) . "'" .
- " WHERE id = '$this->id'";
- $db_results = mysql_query($sql, dbh());
-
- return true;
+// $snoopy->fetch($results[$key]);
+ $data['url'] = $result[$key];
+ $data['mime'] = $mime;
- } // if we've got something
+ $images[] = $data;
+ } // if we've got something
+
/* Default to false */
- return false;
+ return $images;
} // find_art
diff --git a/modules/amazon/AmazonSearchEngine.class.php b/modules/amazon/AmazonSearchEngine.class.php
index 6a6f7b73..691d8b85 100644
--- a/modules/amazon/AmazonSearchEngine.class.php
+++ b/modules/amazon/AmazonSearchEngine.class.php
@@ -91,7 +91,7 @@ class AmazonSearch {
xml_parser_free($this->_parser);
- } // search
+ } // run_search
/*!
@function search
@@ -107,6 +107,8 @@ class AmazonSearch {
unset($this->results['ASIN']);
+ return $this->results;
+
} // search
/*!
@@ -132,6 +134,8 @@ class AmazonSearch {
unset($this->results['ASIN']);
+ return $this->results;
+
} // lookup
function start_element($parser, $tag, $attributes) {
diff --git a/templates/show_album_art.inc.php b/templates/show_album_art.inc.php
new file mode 100644
index 00000000..c02b8b52
--- /dev/null
+++ b/templates/show_album_art.inc.php
@@ -0,0 +1,73 @@
+<?php
+/*
+
+ Copyright (c) 2001 - 2006 Ampache.org
+ All rights reserved.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+
+// Gotta do some math here!
+$total_images = count($images);
+
+$rows = floor($total_images/6);
+$spare = $total_images - ($rows * 6);
+
+$i = 0;
+?>
+
+<table class="text-box">
+<?php
+while ($i <= $rows) {
+ $images[$i];
+ $ii = $i+1;
+ $iii = $i+2;
+?>
+ <tr>
+ <td align="center">
+ <a href="<?php echo $images[$i]['url']; ?>" target="_blank">
+ <img src="<?php echo scrub_out($images[$i]['url']); ?>" border="0" height="175" width="175" /><br />
+ </a>
+ <p align="center">
+ [<a href="<?php echo conf('web_path'); ?>/albums.php?action=select_art&amp;image=<?php echo $i; ?>&amp;album_id=<?php echo urlencode($_REQUEST['album_id']); ?>">Select</a>]
+ </p>
+ </td>
+ <td align="center">
+ <?php if (isset($images[$ii])) { ?>
+ <a href="<?php echo $images[$ii]['url']; ?>" target="_blank">
+ <img src="<?php echo scrub_out($images[$ii]['url']); ?>" border="0" height="175" width="175" /><br />
+ </a>
+ <p align="center">
+ [<a href="<?php echo conf('web_path'); ?>/albums.php?action=select_art&amp;image=<?php echo $ii; ?>&amp;album_id=<?php echo urlencode($_REQUEST['album_id']); ?>">Select</a>]
+ </p>
+ <?php } ?>
+ </td>
+ <td align="center">
+ <?php if (isset($images[$iii])) { ?>
+ <a href="<?php echo $images[$iii]['url']; ?>" target="_blank">
+ <img src="<?php echo scrub_out($images[$iii]['url']); ?>" border="0" height="175" width="175" /><br />
+ </a>
+ <p align="center">
+ [<a href="<?php echo conf('web_path'); ?>/albums.php?action=select_art&amp;image=<?php echo $iii; ?>&amp;album_id=<?php echo urlencode($_REQUEST['album_id']); ?>">Select</a>]
+ </p>
+ <?php } ?>
+ </td>
+ </tr>
+<?php
+ $i++;
+} // end while
+?>
+</table>