summaryrefslogtreecommitdiffstats
path: root/lib/class
diff options
context:
space:
mode:
Diffstat (limited to 'lib/class')
-rw-r--r--lib/class/catalog.class.php153
-rw-r--r--lib/class/song.class.php111
-rw-r--r--lib/class/tag.class.php10
3 files changed, 45 insertions, 229 deletions
diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php
index 7c7fe355..22ef5ff2 100644
--- a/lib/class/catalog.class.php
+++ b/lib/class/catalog.class.php
@@ -44,7 +44,6 @@ class Catalog {
// Used in functions
private static $albums = array();
private static $artists = array();
- private static $genres = array(); //FIXME
private static $tags = array();
private static $_art_albums = array();
@@ -331,15 +330,9 @@ class Catalog {
$data = Dba::fetch_row($db_results);
$artists = $data['0'];
- $sql = "SELECT COUNT(DISTINCT(`genre`)) FROM `song` $catalog_search";
- $db_results = Dba::query($sql);
- $data = Dba::fetch_row($db_results);
- $genres = $data['0'];
-
$results['songs'] = $songs;
$results['albums'] = $albums;
$results['artists'] = $artists;
- $results['genres'] = $genres;
$results['size'] = $size;
$results['time'] = $time;
@@ -1101,7 +1094,6 @@ class Catalog {
$new_song->track = $results['track'];
$artist = $results['artist'];
$album = $results['album'];
- $genre = $results['genre'];
$disk = $results['disk'];
/* Clean up Old Vars */
@@ -1113,8 +1105,6 @@ class Catalog {
*/
$new_song->artist = self::check_artist($artist);
$new_song->f_artist = $artist;
- $new_song->genre = self::check_genre($genre);
- $new_song->f_genre = $new_song->get_genre_name();
$new_song->album = self::check_album($album,$new_song->year,$disk);
$new_song->f_album = $album . " - " . $new_song->year;
$new_song->title = self::check_title($new_song->title,$new_song->file);
@@ -1345,7 +1335,6 @@ class Catalog {
$song = unserialize($serialized_song);
$song->artist = self::check_artist($song->artist);
$song->album = self::check_album($song->album,$song->year);
- $song->genre = self::check_genre($song->genre);
$song->file = $root_path . "/play/index.php?song=" . $song->id;
$song->catalog = $this->id;
@@ -1463,16 +1452,6 @@ class Catalog {
$results = array();
- /* A'right let's check genre first */
- $sql = "SELECT song.genre FROM song WHERE genre='" . $song->genre . "'";
- $db_results = mysql_query($sql, dbh());
-
- if (!mysql_num_rows($db_results)) {
- $sql = "DELETE FROM genre WHERE id='" . $song->genre . "'";
- $db_results = mysql_query($sql, dbh());
- $results['genre'] = true;
- }
-
/* Now for the artist */
$sql = "SELECT song.artist FROM song WHERE artist='" . $song->artist . "'";
$db_results = mysql_query($sql, dbh());
@@ -1498,18 +1477,6 @@ class Catalog {
} // clean_single_song
/**
- * clean_genres
- * This functions cleans up unused genres
- */
- public static function clean_genres() {
-
- /* Do a complex delete to get albums where there are no songs */
- $sql = "DELETE FROM genre USING genre LEFT JOIN song ON song.genre = genre.id WHERE song.id IS NULL";
- $db_results = Dba::query($sql);
-
- } // clean_genres
-
- /**
* clean_tags
* This cleans out tag_maps that are not assoicated with a 'living' object
* and then cleans the tags that have no maps
@@ -1651,10 +1618,6 @@ class Catalog {
$sql = "DELETE FROM object_count USING object_count LEFT JOIN artist ON artist.id=object_count.object_id WHERE object_type='artist' AND artist.id IS NULL";
$db_results = Dba::query($sql);
- // Delete genre stat information
- $sql = "DELETE FROM object_count USING object_count LEFT JOIN genre ON genre.id=object_count.object_id WHERE object_type='genre' AND genre.id IS NULL";
- $db_results = Dba::query($sql);
-
// Delete the live_stream stat information
$sql = "DELETE FROM object_count USING object_count LEFT JOIN live_stream ON live_stream.id=object_count.object_id WHERE object_type='live_stream' AND live_stream.id IS NULL";
$db_results = Dba::query($sql);
@@ -1663,10 +1626,6 @@ class Catalog {
$sql = "DELETE FROM rating USING rating LEFT JOIN song ON song.id=rating.object_id WHERE object_type='song' AND song.id IS NULL";
$db_results = Dba::query($sql);
- // Delete Genre Ratings Information
- $sql = "DELETE FROM rating USING rating LEFT JOIN genre ON genre.id=rating.object_id WHERE object_type='genre' AND genre.id IS NULL";
- $db_results = Dba::query($sql);
-
// Delete Album Rating Information
$sql = "DELETE FROM rating USING rating LEFT JOIN album ON album.id=rating.object_id WHERE object_type='album' AND album.id IS NULL";
$db_results = Dba::query($sql);
@@ -1786,7 +1745,6 @@ class Catalog {
self::clean_albums();
self::clean_artists();
- self::clean_genres();
self::clean_flagged();
self::clean_stats();
self::clean_ext_info();
@@ -1805,12 +1763,12 @@ class Catalog {
public static function optimize_tables() {
$sql = "OPTIMIZE TABLE `song_data`,`song`,`rating`,`catalog`,`session`,`object_count`,`album`,`album_data`" .
- ",`artist`,`ip_history`,`genre`,`flagged`,`now_playing`,`user_preference`,`tags`,`tag_map`,`tmp_playlist`" .
+ ",`artist`,`ip_history`,`flagged`,`now_playing`,`user_preference`,`tag`,`tag_map`,`tmp_playlist`" .
",`tmp_playlist_data`,`playlist`,`playlist_data`";
$db_results = Dba::query($sql);
$sql = "ANALYZE TABLE `song_data`,`song`,`rating`,`catalog`,`session`,`object_count`,`album`,`album_data`" .
- ",`artist`,`ip_history`,`genre`,`flagged`,`now_playing`,`user_preference`,`tags`,`tag_map`,`tmp_playlist`" .
+ ",`artist`,`ip_history`,`flagged`,`now_playing`,`user_preference`,`tag`,`tag_map`,`tmp_playlist`" .
",`tmp_playlist_data`,`playlist`,`playlist_data`";
$db_results = Dba::query($sql);
@@ -1823,9 +1781,6 @@ class Catalog {
*/
public static function check_artist($artist,$readonly='') {
- // Only get the var ones.. less func calls
- $cache_limit = Config::get('artist_cache_limit');
-
/* Clean up the artist */
$artist = trim($artist);
$artist = Dba::escape($artist);
@@ -1837,7 +1792,8 @@ class Catalog {
}
// Remove the prefix so we can sort it correctly
- preg_match("/^(The\s|An\s|A\s|Die\s|Das\s|Ein\s|Eine\s)(.*)/i",$artist,$matches);
+ $prefix_pattern = '/^(' . implode('\\s|',explode('|',Config::get('catalog_prefix_pattern'))) . '\\s)(.*)/i';
+ preg_match($prefix_pattern,$artist,$matches);
if (count($matches)) {
$artist = $matches[2];
@@ -1881,18 +1837,9 @@ class Catalog {
return false;
}
- if ($cache_limit) {
-
- $artist_count = count($this->artists);
- if ($artist_count == $cache_limit) {
- self::$artists = array_slice(self::$artists,3);
- }
- debug_event('cache',"Adding $artist with $artist_id to Cache",'5','ampache-catalog');
- $array = array($artist => $artist_id);
- self::$artists = array_merge(self::$artists, $array);
- unset($array);
-
- } // if cache limit is on..
+ $array = array($artist => $artist_id);
+ self::$artists = array_merge(self::$artists, $array);
+ unset($array);
return $artist_id;
@@ -1910,9 +1857,6 @@ class Catalog {
$album_year = intval($album_year);
$album_disk = intval($disk);
- // Set it once to reduce function calls
- $cache_limit = Config::get('album_cache_limit');
-
/* Ohh no the album has lost it's mojo */
if (!$album) {
$album = _('Unknown (Orphaned)');
@@ -1920,7 +1864,9 @@ class Catalog {
}
// Remove the prefix so we can sort it correctly
- preg_match("/^(The\s|An\s|A\s|Die\s|Das\s|Ein\s|Eine\s)(.*)/i",$album,$matches);
+ $prefix_pattern = '/^(' . implode('\\s|',explode('|',Config::get('catalog_prefix_pattern'))) . '\\s)(.*)/i';
+debug_event('prefix',$prefix_pattern,'3');
+ preg_match($prefix_pattern,$album,$matches);
if (count($matches)) {
$album = $matches[2];
@@ -1973,59 +1919,15 @@ class Catalog {
return false;
}
- if ($cache_limit > 0) {
-
- $albums_count = count(self::$albums);
-
- if ($albums_count == $cache_limit) {
- self::$albums = array_slice(self::$albums,3);
- }
- $array = array($album => $album_id);
- self::$albums = array_merge(self::$albums,$array);
- unset($array);
-
- } // if cache limit is on..
+ $array = array($album => $album_id);
+ self::$albums = array_merge(self::$albums,$array);
+ unset($array);
return $album_id;
} // check_album
/**
- * check_genre
- * Finds the Genre_id from the text name
- */
- public static function check_genre($genre) {
-
- /* If a genre isn't specified force one */
- if (strlen(trim($genre)) < 1) {
- $genre = _('Unknown (Orphaned)');
- }
-
- if (self::$genres[$genre]) {
- return self::$genres[$genre];
- }
-
- /* Look in the genre table */
- $genre = Dba::escape($genre);
- $sql = "SELECT `id` FROM `genre` WHERE `name` = '$genre'";
- $db_results = Dba::query($sql);
-
- $results = Dba::fetch_assoc($db_results);
-
- if (!$results['id']) {
- $sql = "INSERT INTO `genre` (`name`) VALUES ('$genre')";
- $db_results = Dba::query($sql);
- $insert_id = Dba::insert_id();
- }
- else { $insert_id = $results['id']; }
-
- self::$genres[$genre] = $insert_id;
-
- return $insert_id;
-
- } // check_genre
-
- /**
* check_tag
* This checks the tag we've been passed (name)
* and sees if it exists, and if so if it's mapped
@@ -2074,8 +1976,7 @@ class Catalog {
public static function check_title($title,$file=0) {
if (strlen(trim($title)) < 1) {
- preg_match("/.+\/(.*)\.....?$/",$file,$matches);
- $title = Dba::escape($matches[1]);
+ $title = Dba::escape($file);
}
return $title;
@@ -2102,7 +2003,6 @@ class Catalog {
$title = Dba::escape($results['title']);
$artist = $results['artist'];
$album = $results['album'];
- $genre = $results['genre'];
$bitrate = $results['bitrate'];
$rate = $results['rate'];
$mode = $results['mode'];
@@ -2112,6 +2012,7 @@ class Catalog {
$disk = $results['disk'];
$year = $results['year'];
$comment = $results['comment'];
+ $tag = $results['genre'];
$current_time = time();
$lyrics = ' ';
@@ -2120,13 +2021,12 @@ class Catalog {
* If found then add & return id, else return id
*/
$artist_id = self::check_artist($artist);
- $genre_id = self::check_genre($genre);
$album_id = self::check_album($album,$year,$disk);
$title = self::check_title($title,$file);
$add_file = Dba::escape($file);
- $sql = "INSERT INTO `song` (file,catalog,album,artist,title,bitrate,rate,mode,size,time,track,genre,addition_time,year)" .
- " VALUES ('$add_file','$this->id','$album_id','$artist_id','$title','$bitrate','$rate','$mode','$size','$song_time','$track','$genre_id','$current_time','$year')";
+ $sql = "INSERT INTO `song` (file,catalog,album,artist,title,bitrate,rate,mode,size,time,track,addition_time,year)" .
+ " VALUES ('$add_file','$this->id','$album_id','$artist_id','$title','$bitrate','$rate','$mode','$size','$song_time','$track','$current_time','$year')";
$db_results = Dba::query($sql);
if (!$db_results) {
@@ -2136,7 +2036,7 @@ class Catalog {
$song_id = Dba::insert_id();
- self::check_tag($genre,$song_id);
+ self::check_tag($tag,$song_id);
/* Add the EXT information */
$sql = "INSERT INTO `song_data` (`song_id`,`comment`,`lyrics`) " .
@@ -2162,8 +2062,8 @@ class Catalog {
$title = Dba::escape($title);
$current_time = time();
- $sql = "INSERT INTO song (file,catalog,album,artist,title,bitrate,rate,mode,size,time,track,genre,addition_time,year)" .
- " VALUES ('$url','$song->catalog','$song->album','$song->artist','$title','$song->bitrate','$song->rate','$song->mode','$song->size','$song->time','$song->track','$song->genre','$current_time','$song->year')";
+ $sql = "INSERT INTO song (file,catalog,album,artist,title,bitrate,rate,mode,size,time,track,addition_time,year)" .
+ " VALUES ('$url','$song->catalog','$song->album','$song->artist','$title','$song->bitrate','$song->rate','$song->mode','$song->size','$song->time','$song->track','$current_time','$song->year')";
$db_results = Dba::query($sql);
if (!$db_results) {
@@ -2200,11 +2100,10 @@ class Catalog {
*/
public function check_local_mp3($full_file, $gather_type='') {
- if ($gather_type == 'fast_add') {
- $file_date = filemtime($full_file);
- if ($file_date < $this->last_add) {
- return true;
- }
+ $file_date = filemtime($full_file);
+ if ($file_date < $this->last_add) {
+ debug_event('Check','Skipping ' . $full_file . ' File modify time before last add run','3');
+ return true;
}
$full_file = Dba::escape($full_file);
@@ -2217,7 +2116,7 @@ class Catalog {
return true;
}
- return false;
+ return false;
} //check_local_mp3
@@ -2410,7 +2309,7 @@ class Catalog {
$xml['dict']['Name'] = $song->title;
$xml['dict']['Artist'] = $song->f_artist_full;
$xml['dict']['Album'] = $song->f_album_full;
- $xml['dict']['Genre'] = $song->f_genre;
+ $xml['dict']['Genre'] = $song->f_genre; // FIXME
$xml['dict']['Total Time'] = intval($song->time) * 1000; // iTunes uses milliseconds
$xml['dict']['Track Number'] = intval($song->track);
$xml['dict']['Year'] = intval($song->year);
diff --git a/lib/class/song.class.php b/lib/class/song.class.php
index e7fc098a..0a20e4b7 100644
--- a/lib/class/song.class.php
+++ b/lib/class/song.class.php
@@ -34,7 +34,6 @@ class Song extends database_object {
public $size;
public $time;
public $track;
- public $genre; // genre.id (Int)
public $type;
public $mime;
public $played;
@@ -83,7 +82,7 @@ class Song extends database_object {
// Song data cache
$sql = "SELECT song.id,file,catalog,album,year,artist,".
- "title,bitrate,rate,mode,size,time,track,genre,played,song.enabled,update_time,".
+ "title,bitrate,rate,mode,size,time,track,played,song.enabled,update_time,".
"addition_time FROM `song` WHERE `song`.`id` IN
$idlist";
$db_results = Dba::query($sql);
@@ -116,7 +115,7 @@ class Song extends database_object {
/* Grab the basic information from the catalog and return it */
$sql = "SELECT song.id,file,catalog,album,year,artist,".
- "title,bitrate,rate,mode,size,time,track,genre,played,song.enabled,update_time,".
+ "title,bitrate,rate,mode,size,time,track,played,song.enabled,update_time,".
"addition_time FROM `song` WHERE `song`.`id` = '$id'";
$db_results = Dba::query($sql);
@@ -248,19 +247,6 @@ class Song extends database_object {
} // get_album_name
/**
- * get_genre_name
- * gets the name of the genre, allow passing of a specified
- * id
- */
- public function get_genre_name($genre_id=0) {
-
- if (!$genre_id) { $genre_id = $this->genre; }
- $genre = new Genre($genre_id);
- return $genre->name;
-
- } // get_genre_name
-
- /**
* has_flag
* This just returns true or false depending on if this song is flagged for something
* We don't care what so we limit the SELECT to 1
@@ -363,21 +349,6 @@ class Song extends database_object {
break;
case 'artist':
case 'album':
- case 'genre':
- if ($value != $this->$key) {
- if ($value == -1) {
- // Add new data
- $fn = "check_$key";
- $value = Catalog::$fn($data["{$key}_name"]);
- }
- if ($value) {
- $fn = "update_$key";
- self::$fn($value, $this->id);
- $this->$key = $value;
- $updated = 1;
- }
- }
- break;
default:
// Rien a faire
break;
@@ -410,7 +381,6 @@ class Song extends database_object {
$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);
@@ -419,7 +389,7 @@ class Song extends database_object {
$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', " .
+ "`size`='$size', `time`='$time', `track`='$track', " .
"`update_time`='$update_time' WHERE `id`='$song_id'";
$db_results = Dba::query($sql);
@@ -555,16 +525,6 @@ class Song extends database_object {
} // update_artist
/**
- * update_genre
- * updates the genre field
- */
- public static function update_genre($new_genre,$song_id) {
-
- self::_update_item('genre',$new_genre,$song_id,'50');
-
- } // update_genre
-
- /**
* update_album
* updates the album field
*/
@@ -682,10 +642,6 @@ class Song extends database_object {
// Format the Bitrate
$this->f_bitrate = intval($this->bitrate/1000) . "-" . strtoupper($this->mode);
- // Format Genre
- $this->f_genre = $this->get_genre_name();
- $this->f_genre_link = "<a href=\"" . Config::get('web_path') . "/genre.php?action=show_genre&amp;genre_id=" . $this->genre . "\">$this->f_genre</a>";
-
// Format the Time
$min = floor($this->time/60);
$sec = sprintf("%02d", ($this->time%60) );
@@ -694,6 +650,10 @@ class Song extends database_object {
// Format the track (there isn't really anything to do here)
$this->f_track = $this->track;
+ // Get the top tags
+ $tags = Tag::get_top_tags('song',$this->id);
+ $this->f_tags = implode(', ',$tags);
+
// Format the size
$this->f_size = sprintf("%.2f",($this->size/1048576));
@@ -722,14 +682,13 @@ class Song extends database_object {
/* Create the filename that this file should have */
$album = $this->f_album_full;
$artist = $this->f_artist_full;
- $genre = $this->f_genre;
$track = $this->track;
$title = $this->title;
$year = $this->year;
/* Start replacing stuff */
- $replace_array = array('%a','%A','%t','%T','%y','%g','/','\\');
- $content_array = array($artist,$album,$title,$track,$year,$genre,'-','-');
+ $replace_array = array('%a','%A','%t','%T','%y','/','\\');
+ $content_array = array($artist,$album,$title,$track,$year,'-','-');
$rename_pattern = str_replace($replace_array,$content_array,$catalog->rename_pattern);
@@ -788,9 +747,6 @@ class Song extends database_object {
if (!strlen($results[$key]['artist'])) {
$results[$key]['artist'] = $this->get_info_from_filename($filename,$pattern,"%a");
}
- if (!strlen($results[$key]['genre'])) {
- $results[$key]['genre'] = $this->get_info_from_filename($filename,$pattern,"%g");
- }
return $results;
@@ -957,54 +913,5 @@ class Song extends database_object {
} // end stream_cmd
- /**
- * get_sql_from_match
- * This is specificly for browsing it takes the match and returns the sql call that we want to use
- * @package Song
- * @catagory Class
- */
- function get_sql_from_match($match) {
-
- switch ($match) {
- case 'Show_all':
- case 'Show_All':
- case 'show_all':
- $sql = "SELECT id FROM song";
- break;
- case 'Browse':
- case 'show_genres':
- $sql = "SELECT id FROM song";
- break;
- default:
- $sql = "SELECT id FROM song WHERE title LIKE '" . sql_escape($match) . "%'";
- break;
- } // end switch on match
-
- return $sql;
-
- } // get_sql_from_match
-
- /**
- * get_genres
- * this returns an array of songs based on a sql statement that's passed
- * @package songs
- * @catagory Class
- */
- function get_songs($sql) {
-
- $db_results = mysql_query($sql, dbh());
-
- $results = array();
-
- while ($r = mysql_fetch_assoc($db_results)) {
- $results[] = $r['id'];
- }
-
- return $results;
-
- } // get_genres
-
-
} // end of song class
-
?>
diff --git a/lib/class/tag.class.php b/lib/class/tag.class.php
index a34a2586..5c65455c 100644
--- a/lib/class/tag.class.php
+++ b/lib/class/tag.class.php
@@ -243,6 +243,16 @@ return array();
} // get_man_tags
/**
+ * get_top_tags
+ * This gets the top tags for the specified object using limit
+ */
+ public static function get_top_tags($type,$object_id,$limit='2') {
+
+
+
+ } // get_top_tags
+
+ /**
* get_object_tags
* Display all tags that apply to maching target type of the specified id
*/