1
0
Fork 0
mirror of https://github.com/Yetangitu/ampache synced 2025-10-06 03:49:56 +02:00

minor change to tag gather, some speed improvements on the catalog verify and more changes to democratic play, will not work currently due to missing db update that needs more testing

This commit is contained in:
Karl 'vollmerk' Vollmer 2008-03-13 07:38:40 +00:00
parent 591ca8e918
commit 2ff28d9f26
6 changed files with 107 additions and 95 deletions

View file

@ -1048,7 +1048,7 @@ class Catalog {
* updates the song info based on tags, this is called from a bunch of different places * 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 * 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 the patterns aren't passed go look them up
if (!$sort_pattern OR !$rename_pattern) { if (!$sort_pattern OR !$rename_pattern) {
@ -1112,6 +1112,8 @@ class Catalog {
if ($info['change']) { if ($info['change']) {
debug_event('update',"$song->file difference found, updating database",'5','ampache-catalog'); debug_event('update',"$song->file difference found, updating database",'5','ampache-catalog');
$song->update_song($song->id,$new_song); $song->update_song($song->id,$new_song);
// Redfine our reference
$song = $new_song;
} }
else { else {
debug_event('update',"$song->file no difference found returning",'5','ampache-catalog'); debug_event('update',"$song->file no difference found returning",'5','ampache-catalog');
@ -1659,7 +1661,7 @@ class Catalog {
$catalog = new Catalog($catalog_id); $catalog = new Catalog($catalog_id);
/* First get the filenames for the catalog */ /* 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); $db_results = Dba::query($sql);
$number = Dba::num_rows($db_results); $number = Dba::num_rows($db_results);
@ -1669,6 +1671,9 @@ class Catalog {
/* Magical Fix so we don't run out of time */ /* Magical Fix so we don't run out of time */
set_time_limit(0); set_time_limit(0);
// Caching array for album art, save us some time here
$album_art_check_cache = array();
/* Recurse through this catalogs files /* Recurse through this catalogs files
* and get the id3 tage information, * and get the id3 tage information,
* if it's not blank, and different in * if it's not blank, and different in
@ -1676,12 +1681,13 @@ class Catalog {
*/ */
while ($results = Dba::fetch_assoc($db_results)) { while ($results = Dba::fetch_assoc($db_results)) {
/* Create the object from the existing database information */ debug_event('verify',"Starting work on " . $results['file'],'5','ampache-catalog');
$song = new Song($results['id']);
debug_event('verify',"Starting work on $song->file",'5','ampache-catalog'); if (is_readable($results['file'])) {
/* Create the object from the existing database information */
$song = new Song($results['id']);
if (is_readable($song->file)) {
unset($skip); unset($skip);
/* Make sure the song isn't flagged, we don't update flagged stuff */ /* 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); $info = self::update_song_from_tags($song,$this->sort_pattern,$this->rename_pattern);
$album_id = $song->album; $album_id = $song->album;
if ($info['change']) { if ($info['change']) {
$update_string .= $info['text'] . "<br />\n";
$album = new Album($song->album); // Check our cache, this avoids at the very least 2 queriest per song
if (!$album->has_art) { if (!$album_art_check_cache[$song->album]) {
$found = $album->find_art($options,1); $album = new Album($song->album);
if (count($found)) { if (!$album->has_art) {
$image = get_image_from_source($found['0']); $found = $album->find_art($options,1);
$album->insert_art($image,$found['mime']); if (count($found)) {
$is_found = _(' 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"; } // if not in cache
unset($found,$is_found);
}
flush(); flush();
$total_updated++; $total_updated++;
} }

View file

@ -438,6 +438,12 @@ class Democratic extends tmpPlaylist {
"VALUES ('$name','$base','$cool','$level','$user','$default')"; "VALUES ('$name','$base','$cool','$level','$user','$default')";
$db_results = Dba::query($sql); $db_results = Dba::query($sql);
if ($db_results) {
$insert_id = Dba::insert_id();
parent::create($insert_id,'vote','song');
}
return $db_results; return $db_results;
} // create } // create

View file

@ -422,23 +422,35 @@ class Song {
*/ */
public static function update_song($song_id, $new_song) { public static function update_song($song_id, $new_song) {
self::update_title($new_song->title,$song_id); $title = Dba::escape($new_song->title);
self::update_bitrate($new_song->bitrate,$song_id); $bitrate = Dba::escape($new_song->bitrate);
self::update_rate($new_song->rate,$song_id); $rate = Dba::escape($new_song->rate);
self::update_mode($new_song->mode,$song_id); $mode = Dba::escape($new_song->mode);
self::update_size($new_song->size,$song_id); $size = Dba::escape($new_song->size);
self::update_time($new_song->time,$song_id); $time = Dba::escape($new_song->time);
self::update_track($new_song->track,$song_id); $track = Dba::escape($new_song->track);
self::update_artist($new_song->artist,$song_id); $artist = Dba::escape($new_song->artist);
self::update_genre($new_song->genre,$song_id); $genre = Dba::escape($new_song->genre);
self::update_album($new_song->album,$song_id); $album = Dba::escape($new_song->album);
self::update_year($new_song->year,$song_id); $year = Dba::escape($new_song->year);
self::update_comment($new_song->comment,$song_id); $song_id = Dba::escape($song_id);
self::update_language($new_song->language,$song_id); $update_time = time();
self::update_lyrics($new_song->lyrics,$song_id);
self::update_mime($new_song->mime,$song_id);
self::update_played(0,$song_id); $sql = "UPDATE `song` SET `album`='$album', `year`='$year', `artist`='$artist', " .
self::update_utime($song_id); "`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 } // update_song
@ -452,16 +464,6 @@ class Song {
} // update_year } // 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 * update_language
* This updates the language tag of the song * This updates the language tag of the song

View file

@ -88,7 +88,7 @@ class tmpPlaylist {
$results = Dba::fetch_row($db_results); $results = Dba::fetch_row($db_results);
if (!$results['0']) { 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']); $playlist = new tmpPlaylist($results['0']);
@ -201,15 +201,14 @@ class tmpPlaylist {
* This function initializes a new tmpPlaylist it is assoicated with the current * 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 * 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); $sessid = Dba::escape($sessid);
$type = Dba::escape($type); $type = Dba::escape($type);
$object_type = Dba::escape($object_type); $object_type = Dba::escape($object_type);
$base_playlist = Dba::escape($base_playlist);
$sql = "INSERT INTO `tmp_playlist` (`session`,`type`,`object_type`,`base_playlist`) " . $sql = "INSERT INTO `tmp_playlist` (`session`,`type`,`object_type`) " .
" VALUES ('$sessid','$type','$object_type','$base_playlist')"; " VALUES ('$sessid','$type','$object_type')";
$db_results = Dba::query($sql); $db_results = Dba::query($sql);
$id = Dba::insert_id(); $id = Dba::insert_id();
@ -269,7 +268,7 @@ class tmpPlaylist {
/* Just delete if no matching session row */ /* Just delete if no matching session row */
$sql = "DELETE FROM `tmp_playlist` USING `tmp_playlist` " . $sql = "DELETE FROM `tmp_playlist` USING `tmp_playlist` " .
"LEFT JOIN session ON session.id=tmp_playlist.session " . "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); $db_results = Dba::query($sql);
return true; return true;
@ -285,7 +284,7 @@ class tmpPlaylist {
// This prue is always run clears data for playlists that don't have tmp_playlist anymore // 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 " . $sql = "DELETE FROM tmp_playlist_data USING tmp_playlist_data " .
"LEFT JOIN tmp_playlist ON tmp_playlist_data.tmp_playlist=tmp_playlist.id " . "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); $db_results = Dba::query($sql);
} // prune_tracks } // prune_tracks

View file

@ -263,6 +263,12 @@ class Update {
$version[] = array('version' => '340015','description'=>$update_string); $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; return $version;
} // populate_version } // populate_version
@ -1167,8 +1173,16 @@ class Update {
$sql = "ALTER TABLE `democratic` ADD `base_playlist` INT( 11 ) UNSIGNED NOT NULL AFTER `name`"; $sql = "ALTER TABLE `democratic` ADD `base_playlist` INT( 11 ) UNSIGNED NOT NULL AFTER `name`";
$db_results = Dba::query($sql); $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 } // update_340017

View file

@ -68,9 +68,8 @@ class vainfo {
$this->_getID3->option_tags_html = false; $this->_getID3->option_tags_html = false;
$this->_getID3->option_extra_info = false; $this->_getID3->option_extra_info = false;
$this->_getID3->option_tag_lyrics3 = false; $this->_getID3->option_tag_lyrics3 = false;
$this->_getID3->encoding = $this->encoding; $this->_getID3->encoding = $this->encoding;
$this->_getID3->encoding_id3v1 = $this->encoding; $this->_getID3->option_tags_process = true;
$this->_getID3->encoding_id3v2 = $this->encoding;
/* Check for ICONV */ /* Check for ICONV */
if (function_exists('iconv')) { if (function_exists('iconv')) {
@ -99,11 +98,6 @@ class vainfo {
/* Figure out what type of file we are dealing with */ /* Figure out what type of file we are dealing with */
$this->type = $this->_get_type(); $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 */ /* Get the general information about this file */
$info = $this->_get_info(); $info = $this->_get_info();
@ -116,26 +110,6 @@ class vainfo {
} // get_info } // 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 * _get_type
* This function takes the raw information and figures out * This function takes the raw information and figures out
@ -227,7 +201,7 @@ class vainfo {
* This function gathers and returns the general information * This function gathers and returns the general information
* about a song, vbr/cbr sample rate channels etc * about a song, vbr/cbr sample rate channels etc
*/ */
function _get_info() { private function _get_info() {
$array = array(); $array = array();
@ -268,7 +242,7 @@ class vainfo {
* This standardizes the type that we are given into a reconized * This standardizes the type that we are given into a reconized
* type * type
*/ */
function _clean_type($type) { private function _clean_type($type) {
switch ($type) { switch ($type) {
case 'mp3': case 'mp3':
@ -297,7 +271,7 @@ class vainfo {
* returns the elements translated using iconv if needed in a * returns the elements translated using iconv if needed in a
* pretty little format * pretty little format
*/ */
function _parse_vorbiscomment($tags) { private function _parse_vorbiscomment($tags) {
/* Results array */ /* Results array */
$array = array(); $array = array();
@ -332,17 +306,19 @@ class vainfo {
* returns the elements translated using iconv if needed in a * returns the elements translated using iconv if needed in a
* pretty little format * pretty little format
*/ */
function _parse_id3v1($tags) { private function _parse_id3v1($tags) {
$array = array(); $array = array();
// $encoding = $this->_raw['id3v1']['encoding'];
/* Go through all the tags */ /* Go through all the tags */
foreach ($tags as $tag=>$data) { foreach ($tags as $tag=>$data) {
/* This is our baseline for naming /* This is our baseline for naming
* so no translation needed * so no translation needed
*/ */
$array[$tag] = $this->_clean_tag($data['0'],$this->_file_encoding); $array[$tag] = $this->_clean_tag($data['0'],$encoding);
} // end foreach } // end foreach
@ -356,7 +332,7 @@ class vainfo {
* returns the lelements translated using iconv if needed in a * returns the lelements translated using iconv if needed in a
* pretty little format * pretty little format
*/ */
function _parse_id3v2($tags) { private function _parse_id3v2($tags) {
$array = array(); $array = array();
@ -373,14 +349,14 @@ class vainfo {
$array['disk'] = $el[0]; $array['disk'] = $el[0];
break; break;
case 'track_number': case 'track_number':
$array['track'] = $this->_clean_tag($data['0'],$this->_file_encoding); $array['track'] = $this->_clean_tag($data['0'],'');
break; break;
break; break;
case 'comments': case 'comments':
$array['comment'] = $this->_clean_tag($data['0'],$this->_file_encoding); $array['comment'] = $this->_clean_tag($data['0'],'');
break; break;
default: default:
$array[$tag] = $this->_clean_tag($data['0'],$this->_file_encoding); $array[$tag] = $this->_clean_tag($data['0'],'');
break; break;
} // end switch on tag } // end switch on tag
@ -396,7 +372,7 @@ class vainfo {
* returns the elements translated using iconv if needed in a * returns the elements translated using iconv if needed in a
* pretty little format * pretty little format
*/ */
function _parse_ape($tags) { private function _parse_ape($tags) {
foreach ($tags as $tag=>$data) { foreach ($tags as $tag=>$data) {
@ -413,7 +389,7 @@ class vainfo {
* this function takes the riff take information passed by getid3() and * this function takes the riff take information passed by getid3() and
* then reformats it so that it matches the other formats. May require iconv * 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) { foreach ($tags as $tag=>$data) {
@ -438,7 +414,7 @@ class vainfo {
* returns the elements translated using iconv if needed in a * returns the elements translated using iconv if needed in a
* pretty little format * pretty little format
*/ */
function _parse_quicktime($tags) { private function _parse_quicktime($tags) {
/* Results array */ /* Results array */
$array = array(); $array = array();
@ -472,7 +448,7 @@ class vainfo {
* To pull out extra tag information and populate it into * To pull out extra tag information and populate it into
* it's own array * it's own array
*/ */
function _parse_filename($filename) { private function _parse_filename($filename) {
$results = array(); $results = array();
@ -508,7 +484,7 @@ class vainfo {
* is, and or if it's different then the encoding recorded * is, and or if it's different then the encoding recorded
* in the file * in the file
*/ */
function _clean_tag($tag,$encoding='') { private function _clean_tag($tag,$encoding='') {
/* Guess that it's UTF-8 */ /* Guess that it's UTF-8 */
if (!$encoding) { $encoding = 'UTF-8'; } if (!$encoding) { $encoding = 'UTF-8'; }
@ -517,6 +493,11 @@ class vainfo {
$charset = $this->encoding . '//TRANSLIT'; $charset = $this->encoding . '//TRANSLIT';
$tag = iconv($encoding,$charset,$tag); $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; return $tag;