diff options
-rw-r--r-- | admin/duplicates.php | 2 | ||||
-rw-r--r-- | lib/class/catalog.class.php | 74 | ||||
-rw-r--r-- | lib/class/song.class.php | 57 | ||||
-rw-r--r-- | templates/show_duplicates.inc.php | 4 |
4 files changed, 64 insertions, 73 deletions
diff --git a/admin/duplicates.php b/admin/duplicates.php index e06cf84e..4eb6ebb2 100644 --- a/admin/duplicates.php +++ b/admin/duplicates.php @@ -33,7 +33,7 @@ show_header(); switch ($_REQUEST['action']) { case 'find_duplicates': $search_type = Dba::escape($_REQUEST['search_type']); - $duplicates = Catalog::get_duplicate_songs($search_type); + $duplicates = Song::find_duplicates($search_type); require_once Config::get('prefix') . '/templates/show_duplicate.inc.php'; require_once Config::get('prefix') . '/templates/show_duplicates.inc.php'; break; diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php index 9d38fdb9..0807a351 100644 --- a/lib/class/catalog.class.php +++ b/lib/class/catalog.class.php @@ -446,11 +446,11 @@ class Catalog extends database_object { /** * add_files - * Recurses through $this->path and pulls out all mp3s and returns the full - * path in an array. Passes gather_type to determin if we need to check id3 - * information against the db. + * Recurses through $this->path and pulls out all mp3s and returns the + * full path in an array. Passes gather_type to determine if we need to + * check id3 information against the db. */ - public function add_files($path,$options) { + public function add_files($path, $options) { // Profile the memory a bit debug_event('Memory', format_bytes(memory_get_usage(true)), 5); @@ -821,72 +821,6 @@ class Catalog extends database_object { } // get_disabled /** - * get_duplicate_songs - * - * This function takes a search type and returns a list of likely - * duplicates. - */ - public static function get_duplicate_songs($search_type) { - $where_sql = $_REQUEST['search_disabled'] ? '' : "WHERE `enabled` != '0'"; - $sql = 'SELECT `id`, `artist`, `album`, `title`, ' . - 'COUNT(`title`) FROM `song` ' . $where_sql . - ' GROUP BY `title`'; - - if ($search_type == 'artist_title' || - $search_type == 'artist_album_title') { - $sql .= ',`artist`'; - } - if ($search_type == 'artist_album_title') { - $sql .= ',`album`'; - } - - $sql .= ' HAVING COUNT(`title`) > 1 ORDER BY `title`'; - - $db_results = Dba::read($sql); - - $results = array(); - - while ($item = Dba::fetch_assoc($db_results)) { - $results[] = $item; - } // end while - - return $results; - - } // get_duplicate_songs - - /** - * get_duplicate_info - * - * This takes a song id and search type and returns the - * duplicate songs in the correct order, sorted by length, bitrate, - * and filesize. - */ - public static function get_duplicate_info($item, $search_type) { - $sql = 'SELECT `id` FROM `song` ' . - "WHERE `title`='" . Dba::escape($item['title']) . "' "; - - if ($search_type == 'artist_title' || - $search_type == 'artist_album_title') { - $sql .= "AND `artist`='" . Dba::escape($item['artist']) . "' "; - } - if ($search_type == 'artist_album_title') { - $sql .= "AND `album` = '" . Dba::escape($item['album']) . "' "; - } - - $sql .= 'ORDER BY `time`,`bitrate`,`size`'; - $db_results = Dba::read($sql); - - $results = array(); - - while ($item = Dba::fetch_assoc($db_results)) { - $results[] = $item['id']; - } // end while - - return $results; - - } // get_duplicate_info - - /** * dump_album_art * This runs through all of the albums and tries to dump the * art for them into the 'folder.jpg' file in the appropriate dir diff --git a/lib/class/song.class.php b/lib/class/song.class.php index 6b92ea68..72ab88f9 100644 --- a/lib/class/song.class.php +++ b/lib/class/song.class.php @@ -252,6 +252,63 @@ class Song extends database_object implements media { } /** + * find_duplicates + * + * This function takes a search type and returns a list of probable + * duplicates + */ + public static function find_duplicates($search_type) { + $where_sql = $_REQUEST['search_disabled'] ? '' : "WHERE `enabled` != '0'"; + $sql = 'SELECT `id`, `artist`, `album`, `title`, ' . + 'COUNT(`title`) FROM `song` ' . $where_sql . + ' GROUP BY `title`'; + + if ($search_type == 'artist_title' || + $search_type == 'artist_album_title') { + $sql .= ',`artist`'; + } + if ($search_type == 'artist_album_title') { + $sql .= ',`album`'; + } + + $sql .= ' HAVING COUNT(`title`) > 1 ORDER BY `title`'; + + $db_results = Dba::read($sql); + + $results = array(); + + while ($item = Dba::fetch_assoc($db_results)) { + $results[] = $item; + } // end while + + return $results; + } + + public static function get_duplicate_info($dupe, $search_type) { + $sql = 'SELECT `id` FROM `song` ' . + "WHERE `title`='" . Dba::escape($item['title']) . "' "; + + if ($search_type == 'artist_title' || + $search_type == 'artist_album_title') { + $sql .= "AND `artist`='" . Dba::escape($item['artist']) . "' "; + } + if ($search_type == 'artist_album_title') { + $sql .= "AND `album` = '" . Dba::escape($item['album']) . "' "; + } + + $sql .= 'ORDER BY `time`,`bitrate`,`size`'; + $db_results = Dba::read($sql); + + $results = array(); + + while ($item = Dba::fetch_assoc($db_results)) { + $results[] = $item['id']; + } // end while + + return $results; + } + + /** * get_album_name * gets the name of $this->album, allows passing of id */ diff --git a/templates/show_duplicates.inc.php b/templates/show_duplicates.inc.php index 46de64f8..612a1ff6 100644 --- a/templates/show_duplicates.inc.php +++ b/templates/show_duplicates.inc.php @@ -46,9 +46,9 @@ <?php foreach ($duplicates as $item) { // Gather the duplicates - $songs = Catalog::get_duplicate_info($item,$search_type); + $songs = Song::get_duplicate_info($item, $search_type); - foreach ($songs as $key=>$song_id) { + foreach ($songs as $key => $song_id) { $song = new Song($song_id); $song->format(); $row_key = 'duplicate_' . $song_id; |