summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl 'vollmerk' Vollmer <vollmer@ampache.org>2007-06-04 01:31:58 +0000
committerKarl 'vollmerk' Vollmer <vollmer@ampache.org>2007-06-04 01:31:58 +0000
commit848a1bc5388301e128cb5c2c4d8dcb5d06721bb4 (patch)
tree55a165892eb2bfb486d3120ac376da0321413c35
parent3851c073e5b51059e60de5d79b78064c53075c04 (diff)
downloadampache-848a1bc5388301e128cb5c2c4d8dcb5d06721bb4.tar.gz
ampache-848a1bc5388301e128cb5c2c4d8dcb5d06721bb4.tar.bz2
ampache-848a1bc5388301e128cb5c2c4d8dcb5d06721bb4.zip
fixed lastfm gather album art and add
-rw-r--r--admin/catalog.php19
-rw-r--r--config/ampache.cfg.php.dist2
-rw-r--r--lib/class/album.class.php33
-rw-r--r--lib/class/catalog.class.php85
-rw-r--r--lib/init.php1
-rw-r--r--modules/infotools/lastfm.class.php22
-rw-r--r--templates/show_adds_catalog.inc.php27
-rw-r--r--templates/show_gather_art.inc.php27
8 files changed, 138 insertions, 78 deletions
diff --git a/admin/catalog.php b/admin/catalog.php
index 83d6a072..fa9b35fb 100644
--- a/admin/catalog.php
+++ b/admin/catalog.php
@@ -43,16 +43,14 @@ switch ($_REQUEST['action']) {
$catalog = new Catalog();
$_REQUEST['catalogs'] = $catalog->get_catalog_ids();
case 'add_to_catalog':
- if (conf('demo_mode')) { break; }
+ if (Config::get('demo_mode')) { break; }
if ($_REQUEST['catalogs'] ) {
foreach ($_REQUEST['catalogs'] as $catalog_id) {
- echo "<div class=\"confirmation-box\">";
$catalog = new Catalog($catalog_id);
$catalog->add_to_catalog();
- echo "</div>";
}
}
- $url = conf('web_path') . '/admin/index.php';
+ $url = Config::get('web_path') . '/admin/index.php';
$title = _('Catalog Updated');
$body = '';
show_confirmation($title,$body,$url);
@@ -247,17 +245,14 @@ switch ($_REQUEST['action']) {
include(conf('prefix') . '/templates/show_edit_catalog.inc.php');
break;
case 'gather_album_art':
- flush();
$catalogs = Catalog::get_catalogs();
- foreach ($catalogs as $data) {
- show_box_top(_('Starting Album Art Search'));
- echo _('Searched') . ": <span id=\"count_art_" . $data->id . "\">" . _('None') . "</span><br />";
- show_box_bottom();
+ foreach ($catalogs as $catalog) {
+ $catalog_id = $catalog->id;
+ require Config::get('prefix') . '/templates/show_gather_art.inc.php';
flush();
- echo "<b>" . _('Album Art Search Finished') . ". . .</b></div>\n";
- $data->get_album_art(0,1);
+ $catalog->get_album_art(0,1);
}
- $url = conf('web_path') . '/admin/index.php';
+ $url = Config::get('web_path') . '/admin/index.php';
$title = _('Album Art Search Finished');
$body = '';
show_confirmation($title,$body,$url);
diff --git a/config/ampache.cfg.php.dist b/config/ampache.cfg.php.dist
index 75d795e2..b4692d28 100644
--- a/config/ampache.cfg.php.dist
+++ b/config/ampache.cfg.php.dist
@@ -207,7 +207,7 @@ ratings = "true"
; method simply comment it out valid values are
; POSSIBLE VALUES: db id3 folder amazon lastfm
; DEFAULT: db,id3,folder,lastfm,amazon
-album_art_order = "db,id3,folder,amazon"
+album_art_order = "db,id3,folder,lastfm,amazon"
; Album Art
; Set this to true if you want album art displayed on pages besides the
diff --git a/lib/class/album.class.php b/lib/class/album.class.php
index ec1e819b..d801c518 100644
--- a/lib/class/album.class.php
+++ b/lib/class/album.class.php
@@ -260,11 +260,10 @@ class Album {
$data = $this->{$method_name}($options['keyword'],$limit);
break;
case 'get_id3_art':
- if ($options['skip_id3']) { break; }
$data = $this->{$method_name}($limit);
break;
default:
- $data = $this->{$method_name}();
+ $data = $this->{$method_name}($limit);
break;
}
@@ -284,6 +283,36 @@ class Album {
} // 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) {
+
+ // Create the parser object
+ $lastfm = new LastFMSearch();
+
+ $raw_data = $lastfm->search($this->artist_name,$this->name);
+
+ if (!count($raw_data)) { return array(); }
+
+ $coverart = $raw_data['coverart'];
+
+ ksort($coverart);
+ foreach ($coverart as $key=>$value) {
+ $i++;
+ $url = $coverart[$key];
+ $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
+
/*!
@function get_id3_art
@discussion looks for art from the id3 tags
diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php
index c4c794bb..f9ed1969 100644
--- a/lib/class/catalog.class.php
+++ b/lib/class/catalog.class.php
@@ -455,41 +455,40 @@ class Catalog {
} // get_albums
/**
- * get_catalog_album_ids
+ * get_album_ids
* This returns an array of ids of albums that have songs in this
* catalog
- * //FIXME:: :(
*/
- function get_catalog_album_ids() {
+ public function get_album_ids() {
- $id = sql_escape($this->id);
+ $id = Dba::escape($this->id);
$results = array();
- $sql = "SELECT DISTINCT(song.album) FROM song WHERE song.catalog='$id'";
- $db_results = mysql_query($sql,dbh());
+ $sql = "SELECT DISTINCT(song.album) FROM `song` WHERE `song`.`catalog`='$id'";
+ $db_results = Dba::query($sql);
- while ($r = mysql_fetch_assoc($db_results)) {
+ while ($r = Dba::fetch_assoc($db_results)) {
$results[] = $r['album'];
}
return $results;
- } // get_catalog_album_ids
+ } // get_album_ids
/**
- *get_album_art
- *This runs through all of the needs art albums and trys
- *to find the art for them from the mp3s
+ * get_album_art
+ * This runs through all of the needs art albums and trys
+ * to find the art for them from the mp3s
*/
- function get_album_art($catalog_id=0,$all='') {
- // Just so they get a page
- flush();
+ public function get_album_art($catalog_id=0,$all='') {
- if (!$catalog_id) { $catalog_id = $this->id; }
+ // Prevent the script from timing out
+ set_time_limit(0);
+ if (!$catalog_id) { $catalog_id = $this->id; }
if (!empty($all)) {
- $albums = $this->get_catalog_album_ids();
+ $albums = $this->get_album_ids();
}
else {
$albums = array_keys($this->_art_albums);
@@ -499,16 +498,16 @@ class Catalog {
foreach ($albums as $album_id) {
// Create the object
$album = new Album($album_id);
-
- if (conf('debug')) {
- debug_event('gather_art','Gathering art for ' . $album->name,'5');
- }
+ // We're going to need the name here
+ $album->format();
+
+ debug_event('gather_art','Gathering art for ' . $album->name,'5');
// Define the options we want to use for the find art function
$options = array(
'album_name' => $album->name,
- 'artist' => $album->artist,
- 'keyword' => $album->artist . ' ' . $album->name
+ 'artist' => $album->artist_name,
+ 'keyword' => $album->artist_name . ' ' . $album->name
);
// Return results
@@ -523,22 +522,18 @@ class Catalog {
/* Stupid little cutesie thing */
$search_count++;
- if ( !($search_count%conf('catalog_echo_count'))) {
- echo "<script type=\"text/javascript\">";
+ if ( !($search_count%5)) {
+ echo "<script type=\"text/javascript\">";
echo "update_txt('" . $search_count ."','count_art_" . $this->id . "');";
+ echo "update_txt('" . $album->name . "','read_art_" . $this->id . "');";
echo "</script>\n";
flush();
} //echos song count
-
- // Prevent the script from timing out
- set_time_limit(0);
unset($found);
} // foreach albums
- echo "<br />$art_found " . _('albums with art') . ". . .<br />\n";
- flush();
} // get_album_art
@@ -751,8 +746,8 @@ class Catalog {
function update_last_add() {
$date = time();
- $sql = "UPDATE catalog SET last_add='$date' WHERE id='$this->id'";
- $db_results = mysql_query($sql, dbh());
+ $sql = "UPDATE `catalog` SET `last_add`='$date' WHERE `id`='$this->id'";
+ $db_results = Dba::query($sql);
} // update_last_add
@@ -980,24 +975,20 @@ class Catalog {
} // update_song_from_tags
- /*!
- @function add_to_catalog
- @discussion this function adds new files to an
- existing catalog
- */
- function add_to_catalog($type='',$verbose=1) {
-
- if ($verbose) {
- echo "\n" . _('Starting New Song Search on') . " <b>[$this->name]</b> " . _('catalog') . "<br />\n";
- }
+ /**
+ * add_to_catalog
+ * this function adds new files to an
+ * existing catalog
+ */
+ public function add_to_catalog() {
if ($this->catalog_type == 'remote') {
echo _('Running Remote Update') . ". . .<br />";
$this->get_remote_catalog($type=0);
return true;
}
-
- echo _('Found') . ": <span id=\"count_add_" . $this->id ."\">" . _('None') . "</span><br />\n";
+
+ require Config::get('prefix') . '/templates/show_adds_catalog.inc.php';
flush();
/* Set the Start time */
@@ -1010,11 +1001,7 @@ class Catalog {
/* Get the songs and then insert them into the db */
$this->add_files($this->path,$type,0,$verbose);
- echo "<script type=\"text/javascript\">";
- echo "update_txt('" . $this->count . "','count_add_" . $this->id ."');";
- echo "</script>\n";
- flush();
-
+ // Foreach Playlists we found
foreach ($this->_playlists as $full_file) {
if ($this->import_m3u($full_file)) {
$file = basename($full_file);
@@ -1030,7 +1017,7 @@ class Catalog {
if ($verbose) {
echo "\n<b>" . _('Starting Album Art Search') . ". . .</b><br />\n";
- echo _('Searched') . ": <span id=\"count_art_" . $this->id . "\">" . _('None') . "</span>";
+ echo _('Searched') . ": <span id=\"art_count_" . $this->id . "\">" . _('None') . "</span>";
flush();
}
$this->get_album_art();
diff --git a/lib/init.php b/lib/init.php
index c443b1d7..c2679f7b 100644
--- a/lib/init.php
+++ b/lib/init.php
@@ -132,6 +132,7 @@ require_once $prefix . '/modules/catalog.php';
require_once $prefix . '/modules/getid3/getid3.php';
require_once $prefix . '/modules/infotools/Snoopy.class.php';
require_once $prefix . '/modules/infotools/AmazonSearchEngine.class.php';
+require_once $prefix . '/modules/infotools/lastfm.class.php';
//require_once $prefix . '/modules/infotools/jamendoSearch.class.php';
/* Temp Fixes */
diff --git a/modules/infotools/lastfm.class.php b/modules/infotools/lastfm.class.php
index 232c81ef..bdcf553a 100644
--- a/modules/infotools/lastfm.class.php
+++ b/modules/infotools/lastfm.class.php
@@ -22,22 +22,16 @@
class LastFMSearch {
- var $base_url = "http://ws.audioscrobbler.com/1.0/album";
- var $token;
- var $results=array(); // Array of results
- var $_parser; // The XML parser
- var $_grabtags; // Tags to grab the contents of
- var $_sourceTag; // source tag don't ask
- var $_subTag; // Stupid hack to make things come our right
- var $_currentTag; // Stupid hack to make things come out right
- var $_currentTagContents;
- var $_currentPage=0;
- var $_maxPage=1;
- var $_default_results_pages=1;
+ protected $base_url = "http://ws.audioscrobbler.com/1.0/album";
+ public $results=array(); // Array of results
+ private $_parser; // The XML parser
+ protected $_grabtags = array('coverart','large','medium','small');
+ private $_subTag; // Stupid hack to make things come our right
+ private $_currentTag; // Stupid hack to make things come out right
function LastFMSearch() {
-
- $this->_grabtags = array('coverart','large','medium','small');
+
+ // Rien a faire
} // LastFMSearch
diff --git a/templates/show_adds_catalog.inc.php b/templates/show_adds_catalog.inc.php
new file mode 100644
index 00000000..14844aaf
--- /dev/null
+++ b/templates/show_adds_catalog.inc.php
@@ -0,0 +1,27 @@
+<?php
+/*
+
+ Copyright (c) 2001 - 2007 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 v2
+ as published by the Free Software Foundation.
+
+ 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.
+
+*/
+
+show_box_top();
+echo "\n" . _('Starting New Song Search on') . " <b>[$this->name]</b> " . _('catalog') . "<br />\n";
+echo _('Found') . ": <span id=\"add_count_" . $this->id ."\">" . _('None') . "</span><br />\n";
+echo _('Reading') . ":<span id=\"add_dir_$catalog_id\"></span><br />";
+show_box_bottom();
+?>
diff --git a/templates/show_gather_art.inc.php b/templates/show_gather_art.inc.php
new file mode 100644
index 00000000..7687a588
--- /dev/null
+++ b/templates/show_gather_art.inc.php
@@ -0,0 +1,27 @@
+<?php
+/*
+
+ Copyright (c) 2001 - 2007 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 v2
+ as published by the Free Software Foundation.
+
+ 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.
+
+*/
+
+show_box_top();
+echo "<b>" . _('Starting Album Art Search') . ". . .</b><br />\n";
+echo _('Searched') . ": <span id=\"count_art_" . $catalog_id . "\">" . _('None') . "</span><br />";
+echo _('Reading') . ":<span id=\"read_art_$catalog_id\"></span><br />";
+show_box_bottom();
+?>