summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/class/catalog.class.php48
-rw-r--r--lib/class/democratic.class.php6
-rw-r--r--lib/class/song.class.php56
-rw-r--r--lib/class/tmpplaylist.class.php13
-rw-r--r--lib/class/update.class.php16
-rw-r--r--lib/class/vainfo.class.php65
6 files changed, 108 insertions, 96 deletions
diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php
index 02e780e8..1e468e82 100644
--- a/lib/class/catalog.class.php
+++ b/lib/class/catalog.class.php
@@ -1048,7 +1048,7 @@ class Catalog {
* updates the song info based on tags, this is called from a bunch of different places
* and passes in a full fledged song object, so it's a static function
*/
- public static function update_song_from_tags($song,$sort_pattern='',$rename_pattern='') {
+ public static function update_song_from_tags(&$song,$sort_pattern='',$rename_pattern='') {
// If the patterns aren't passed go look them up
if (!$sort_pattern OR !$rename_pattern) {
@@ -1112,6 +1112,8 @@ class Catalog {
if ($info['change']) {
debug_event('update',"$song->file difference found, updating database",'5','ampache-catalog');
$song->update_song($song->id,$new_song);
+ // Redfine our reference
+ $song = $new_song;
}
else {
debug_event('update',"$song->file no difference found returning",'5','ampache-catalog');
@@ -1659,7 +1661,7 @@ class Catalog {
$catalog = new Catalog($catalog_id);
/* First get the filenames for the catalog */
- $sql = "SELECT `id` FROM `song` WHERE `catalog`='$catalog_id'";
+ $sql = "SELECT `id`,`file` FROM `song` WHERE `catalog`='$catalog_id'";
$db_results = Dba::query($sql);
$number = Dba::num_rows($db_results);
@@ -1669,6 +1671,9 @@ class Catalog {
/* Magical Fix so we don't run out of time */
set_time_limit(0);
+ // Caching array for album art, save us some time here
+ $album_art_check_cache = array();
+
/* Recurse through this catalogs files
* and get the id3 tage information,
* if it's not blank, and different in
@@ -1676,12 +1681,13 @@ class Catalog {
*/
while ($results = Dba::fetch_assoc($db_results)) {
- /* Create the object from the existing database information */
- $song = new Song($results['id']);
-
- debug_event('verify',"Starting work on $song->file",'5','ampache-catalog');
+ debug_event('verify',"Starting work on " . $results['file'],'5','ampache-catalog');
- if (is_readable($song->file)) {
+ if (is_readable($results['file'])) {
+
+ /* Create the object from the existing database information */
+ $song = new Song($results['id']);
+
unset($skip);
/* Make sure the song isn't flagged, we don't update flagged stuff */
@@ -1695,19 +1701,23 @@ class Catalog {
$info = self::update_song_from_tags($song,$this->sort_pattern,$this->rename_pattern);
$album_id = $song->album;
if ($info['change']) {
- $update_string .= $info['text'] . "<br />\n";
-
- $album = new Album($song->album);
- if (!$album->has_art) {
- $found = $album->find_art($options,1);
- if (count($found)) {
- $image = get_image_from_source($found['0']);
- $album->insert_art($image,$found['mime']);
- $is_found = _(' FOUND');
+
+ // Check our cache, this avoids at the very least 2 queriest per song
+ if (!$album_art_check_cache[$song->album]) {
+ $album = new Album($song->album);
+ if (!$album->has_art) {
+ $found = $album->find_art($options,1);
+ if (count($found)) {
+ $image = get_image_from_source($found['0']);
+ $album->insert_art($image,$found['mime']);
+ $album_art_check_cache[$album->id] = 1;
+ }
+ } // if no art
+ else {
+ $album_art_check_cache[$album->id] = 1;
}
- $update_string .= "<b>" . _('Searching for new Album Art') . ". . .$is_found</b><br />\n";
- unset($found,$is_found);
- }
+ } // if not in cache
+
flush();
$total_updated++;
}
diff --git a/lib/class/democratic.class.php b/lib/class/democratic.class.php
index f8008035..df323f62 100644
--- a/lib/class/democratic.class.php
+++ b/lib/class/democratic.class.php
@@ -438,6 +438,12 @@ class Democratic extends tmpPlaylist {
"VALUES ('$name','$base','$cool','$level','$user','$default')";
$db_results = Dba::query($sql);
+ if ($db_results) {
+ $insert_id = Dba::insert_id();
+ parent::create($insert_id,'vote','song');
+ }
+
+
return $db_results;
} // create
diff --git a/lib/class/song.class.php b/lib/class/song.class.php
index 27c602a5..012aac38 100644
--- a/lib/class/song.class.php
+++ b/lib/class/song.class.php
@@ -422,23 +422,35 @@ class Song {
*/
public static function update_song($song_id, $new_song) {
- self::update_title($new_song->title,$song_id);
- self::update_bitrate($new_song->bitrate,$song_id);
- self::update_rate($new_song->rate,$song_id);
- self::update_mode($new_song->mode,$song_id);
- self::update_size($new_song->size,$song_id);
- self::update_time($new_song->time,$song_id);
- self::update_track($new_song->track,$song_id);
- self::update_artist($new_song->artist,$song_id);
- self::update_genre($new_song->genre,$song_id);
- self::update_album($new_song->album,$song_id);
- self::update_year($new_song->year,$song_id);
- self::update_comment($new_song->comment,$song_id);
- self::update_language($new_song->language,$song_id);
- self::update_lyrics($new_song->lyrics,$song_id);
- self::update_mime($new_song->mime,$song_id);
- self::update_played(0,$song_id);
- self::update_utime($song_id);
+ $title = Dba::escape($new_song->title);
+ $bitrate = Dba::escape($new_song->bitrate);
+ $rate = Dba::escape($new_song->rate);
+ $mode = Dba::escape($new_song->mode);
+ $size = Dba::escape($new_song->size);
+ $time = Dba::escape($new_song->time);
+ $track = Dba::escape($new_song->track);
+ $artist = Dba::escape($new_song->artist);
+ $genre = Dba::escape($new_song->genre);
+ $album = Dba::escape($new_song->album);
+ $year = Dba::escape($new_song->year);
+ $song_id = Dba::escape($song_id);
+ $update_time = time();
+
+
+ $sql = "UPDATE `song` SET `album`='$album', `year`='$year', `artist`='$artist', " .
+ "`title`='$title', `bitrate`='$bitrate', `rate`='$rate', `mode`='$mode', " .
+ "`size`='$size', `time`='$time', `track`='$track', `genre`='$genre', " .
+ "`update_time`='$update_time' WHERE `id`='$song_id'";
+ $db_results = Dba::query($sql);
+
+
+ $comment = Dba::escape($new_song->comment);
+ $language = Dba::escape($new_song->language);
+ $lyrics = Dba::escape($new_song->lyrics);
+
+ $sql = "UPDATE `song_data` SET `lyrics`='$lyrics', `language`='$language', `comment`='$comment' " .
+ "WHERE `song_id`='$song_id'";
+ $db_results = Dba::query($sql);
} // update_song
@@ -453,16 +465,6 @@ class Song {
} // update_year
/**
- * update_mime
- * This updates the mime type of the song object we're passed
- */
- public static function update_mime($new_mime,$song_id) {
-
- self::_update_item('mime',$new_mime,$song_id,'50');
-
- } // update_mime
-
- /**
* update_language
* This updates the language tag of the song
*/
diff --git a/lib/class/tmpplaylist.class.php b/lib/class/tmpplaylist.class.php
index 905da3bd..050d6211 100644
--- a/lib/class/tmpplaylist.class.php
+++ b/lib/class/tmpplaylist.class.php
@@ -88,7 +88,7 @@ class tmpPlaylist {
$results = Dba::fetch_row($db_results);
if (!$results['0']) {
- $results['0'] = tmpPlaylist::create($session_id,'user','song','0');
+ $results['0'] = tmpPlaylist::create($session_id,'user','song');
}
$playlist = new tmpPlaylist($results['0']);
@@ -201,15 +201,14 @@ class tmpPlaylist {
* This function initializes a new tmpPlaylist it is assoicated with the current
* session rather then a user, as you could have same user multiple locations
*/
- public static function create($sessid,$type,$object_type,$base_playlist) {
+ public static function create($sessid,$type,$object_type) {
$sessid = Dba::escape($sessid);
$type = Dba::escape($type);
$object_type = Dba::escape($object_type);
- $base_playlist = Dba::escape($base_playlist);
- $sql = "INSERT INTO `tmp_playlist` (`session`,`type`,`object_type`,`base_playlist`) " .
- " VALUES ('$sessid','$type','$object_type','$base_playlist')";
+ $sql = "INSERT INTO `tmp_playlist` (`session`,`type`,`object_type`) " .
+ " VALUES ('$sessid','$type','$object_type')";
$db_results = Dba::query($sql);
$id = Dba::insert_id();
@@ -269,7 +268,7 @@ class tmpPlaylist {
/* Just delete if no matching session row */
$sql = "DELETE FROM `tmp_playlist` USING `tmp_playlist` " .
"LEFT JOIN session ON session.id=tmp_playlist.session " .
- "WHERE session.id IS NULL AND tmp_playlist.session != '-1'";
+ "WHERE session.id IS NULL AND tmp_playlist.type != 'vote'";
$db_results = Dba::query($sql);
return true;
@@ -285,7 +284,7 @@ class tmpPlaylist {
// This prue is always run clears data for playlists that don't have tmp_playlist anymore
$sql = "DELETE FROM tmp_playlist_data USING tmp_playlist_data " .
"LEFT JOIN tmp_playlist ON tmp_playlist_data.tmp_playlist=tmp_playlist.id " .
- "WHERE tmp_playlist.id IS NULL AND tmp_playlist.type != 'vote'";
+ "WHERE tmp_playlist.id IS NULL";
$db_results = Dba::query($sql);
} // prune_tracks
diff --git a/lib/class/update.class.php b/lib/class/update.class.php
index 42cd9b86..4d21c958 100644
--- a/lib/class/update.class.php
+++ b/lib/class/update.class.php
@@ -263,6 +263,12 @@ class Update {
$version[] = array('version' => '340015','description'=>$update_string);
+ $update_string = '- Alter the Democratic Playlist table, adding base_playlist.<br />' .
+ '- Alter tmp_playlist to account for Democratic changes.<br />' .
+ '- Cleared Existing Democratic playlists due to changes.<br />';
+
+// $version[] = array('version' => '340016','description'=>$update_string);
+
return $version;
} // populate_version
@@ -1167,8 +1173,16 @@ class Update {
$sql = "ALTER TABLE `democratic` ADD `base_playlist` INT( 11 ) UNSIGNED NOT NULL AFTER `name`";
$db_results = Dba::query($sql);
- self::set_version('db_version','340017');
+ $sql = "ALTER TABLE `tmp_playlist` DROP `base_playlist`";
+ $db_results = Dba::query($sql);
+ $sql = "DELETE FROM `tmp_playlist` WHERE `session`='-1'";
+ $db_results = Dba::query($sql);
+
+ $sql = "TRUNCATE `democratic`";
+ $db_results = Dba::query($sql);
+
+ self::set_version('db_version','340017');
} // update_340017
diff --git a/lib/class/vainfo.class.php b/lib/class/vainfo.class.php
index 2f8c7ba2..3b08ebfa 100644
--- a/lib/class/vainfo.class.php
+++ b/lib/class/vainfo.class.php
@@ -68,9 +68,8 @@ class vainfo {
$this->_getID3->option_tags_html = false;
$this->_getID3->option_extra_info = false;
$this->_getID3->option_tag_lyrics3 = false;
- $this->_getID3->encoding = $this->encoding;
- $this->_getID3->encoding_id3v1 = $this->encoding;
- $this->_getID3->encoding_id3v2 = $this->encoding;
+ $this->_getID3->encoding = $this->encoding;
+ $this->_getID3->option_tags_process = true;
/* Check for ICONV */
if (function_exists('iconv')) {
@@ -99,11 +98,6 @@ class vainfo {
/* Figure out what type of file we are dealing with */
$this->type = $this->_get_type();
- /* This is very important, figure out the encoding of the
- * file
- */
- $this->_set_encoding();
-
/* Get the general information about this file */
$info = $this->_get_info();
@@ -117,26 +111,6 @@ class vainfo {
} // get_info
/**
- * _set_encoding
- * This function trys to figure out what the encoding
- * is based on the file type and sets the _file_encoding
- * var to whatever it finds, the default is UTF-8 if we
- * can't find anything
- */
- function _set_encoding() {
- /* Switch on the file type */
- switch ($this->type) {
- case 'mp3':
- case 'ogg':
- case 'flac':
- default:
- $this->_file_encoding = $this->_raw['encoding'];
- break;
- } // end switch
-
- } // _get_encoding
-
- /**
* _get_type
* This function takes the raw information and figures out
* what type of file we are dealing with for use by the tag
@@ -227,7 +201,7 @@ class vainfo {
* This function gathers and returns the general information
* about a song, vbr/cbr sample rate channels etc
*/
- function _get_info() {
+ private function _get_info() {
$array = array();
@@ -268,7 +242,7 @@ class vainfo {
* This standardizes the type that we are given into a reconized
* type
*/
- function _clean_type($type) {
+ private function _clean_type($type) {
switch ($type) {
case 'mp3':
@@ -297,7 +271,7 @@ class vainfo {
* returns the elements translated using iconv if needed in a
* pretty little format
*/
- function _parse_vorbiscomment($tags) {
+ private function _parse_vorbiscomment($tags) {
/* Results array */
$array = array();
@@ -332,9 +306,11 @@ class vainfo {
* returns the elements translated using iconv if needed in a
* pretty little format
*/
- function _parse_id3v1($tags) {
+ private function _parse_id3v1($tags) {
$array = array();
+
+ // $encoding = $this->_raw['id3v1']['encoding'];
/* Go through all the tags */
foreach ($tags as $tag=>$data) {
@@ -342,7 +318,7 @@ class vainfo {
/* This is our baseline for naming
* so no translation needed
*/
- $array[$tag] = $this->_clean_tag($data['0'],$this->_file_encoding);
+ $array[$tag] = $this->_clean_tag($data['0'],$encoding);
} // end foreach
@@ -356,7 +332,7 @@ class vainfo {
* returns the lelements translated using iconv if needed in a
* pretty little format
*/
- function _parse_id3v2($tags) {
+ private function _parse_id3v2($tags) {
$array = array();
@@ -373,14 +349,14 @@ class vainfo {
$array['disk'] = $el[0];
break;
case 'track_number':
- $array['track'] = $this->_clean_tag($data['0'],$this->_file_encoding);
+ $array['track'] = $this->_clean_tag($data['0'],'');
break;
break;
case 'comments':
- $array['comment'] = $this->_clean_tag($data['0'],$this->_file_encoding);
+ $array['comment'] = $this->_clean_tag($data['0'],'');
break;
default:
- $array[$tag] = $this->_clean_tag($data['0'],$this->_file_encoding);
+ $array[$tag] = $this->_clean_tag($data['0'],'');
break;
} // end switch on tag
@@ -396,7 +372,7 @@ class vainfo {
* returns the elements translated using iconv if needed in a
* pretty little format
*/
- function _parse_ape($tags) {
+ private function _parse_ape($tags) {
foreach ($tags as $tag=>$data) {
@@ -413,7 +389,7 @@ class vainfo {
* this function takes the riff take information passed by getid3() and
* then reformats it so that it matches the other formats. May require iconv
*/
- function _parse_riff($tags) {
+ private function _parse_riff($tags) {
foreach ($tags as $tag=>$data) {
@@ -438,7 +414,7 @@ class vainfo {
* returns the elements translated using iconv if needed in a
* pretty little format
*/
- function _parse_quicktime($tags) {
+ private function _parse_quicktime($tags) {
/* Results array */
$array = array();
@@ -472,7 +448,7 @@ class vainfo {
* To pull out extra tag information and populate it into
* it's own array
*/
- function _parse_filename($filename) {
+ private function _parse_filename($filename) {
$results = array();
@@ -508,7 +484,7 @@ class vainfo {
* is, and or if it's different then the encoding recorded
* in the file
*/
- function _clean_tag($tag,$encoding='') {
+ private function _clean_tag($tag,$encoding='') {
/* Guess that it's UTF-8 */
if (!$encoding) { $encoding = 'UTF-8'; }
@@ -517,6 +493,11 @@ class vainfo {
$charset = $this->encoding . '//TRANSLIT';
$tag = iconv($encoding,$charset,$tag);
}
+ elseif ($this->_iconv) {
+ // We have to transcode anyway and protect from non-[CHARGET] chars
+ $charset = $this->encoding . '//IGNORE';
+ $tag = iconv($this->encoding,$charset,$tag);
+ }
return $tag;