diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2006-12-22 06:03:03 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2006-12-22 06:03:03 +0000 |
commit | 2d06bf58a22f52e3ca3a3d046a48862da1790a40 (patch) | |
tree | e047aa79c2b1f6eb3bf8e7da0b9614503ad8288f /lib/duplicates.php | |
parent | c9bf00afb1611a05b85088264cb4d42efbb8ab73 (diff) | |
download | ampache-2d06bf58a22f52e3ca3a3d046a48862da1790a40.tar.gz ampache-2d06bf58a22f52e3ca3a3d046a48862da1790a40.tar.bz2 ampache-2d06bf58a22f52e3ca3a3d046a48862da1790a40.zip |
new best guess duplicate logic
Diffstat (limited to 'lib/duplicates.php')
-rw-r--r-- | lib/duplicates.php | 69 |
1 files changed, 46 insertions, 23 deletions
diff --git a/lib/duplicates.php b/lib/duplicates.php index 71b786f0..c6af8c58 100644 --- a/lib/duplicates.php +++ b/lib/duplicates.php @@ -5,9 +5,8 @@ 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 - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. + 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 @@ -20,28 +19,37 @@ */ - -/*! - @function get_duplicate_songs - @discussion -*/ +/** + * get_duplicate_songs + * This function takes a search type and returns a list of all songs that + * are likely to be duplicates based on the search type selected + */ function get_duplicate_songs($search_type) { + + // Setup the base SQL $sql = "SELECT song.id as song,artist.name,album.name,title,count(title) as ctitle". " FROM song,artist,album ". " WHERE song.artist=artist.id AND song.album=album.id AND song.title<>'' ". " GROUP BY title"; - if ($search_type=="artist_title"||$search_type=="artist_album_title") + + // Additional constraints + if ($search_type=="artist_title"||$search_type=="artist_album_title") { $sql = $sql.",artist"; - if ($search_type=="artist_album_title") + } + + if ($search_type=="artist_album_title") { $sql = $sql.",album"; + } + + // Final componets $sql = $sql." HAVING count(title) > 1"; $sql = $sql." ORDER BY ctitle"; - $result = mysql_query($sql, dbh()); + $db_results = mysql_query($sql, dbh()); $arr = array(); - while ($flag = mysql_fetch_array($result)) { + while ($flag = mysql_fetch_assoc($db_results)) { $arr[] = $flag; } // end while @@ -49,29 +57,39 @@ function get_duplicate_songs($search_type) { } // get_duplicate_songs -/*! - @function get_duplicate_info - @discussion -*/ -function get_duplicate_info($song,$search_type) { +/** + * get_duplicate_info + * This takes a song, search type and auto flag and returns the duplicate songs in the correct + * order, if AUTO is selected it sorts them by longest, higest bitrate, largest filesize, checking + * the last one as most likely bad + */ +function get_duplicate_info($song,$search_type,$auto='') { + // Get the artist name $artist = $song->get_artist_name(); - $sql = "SELECT song.id as songid,song.title as song,file,bitrate,size,time,album.name AS album,album.id as albumid, artist.name AS artist,artist.id as artistid". + + // Build the SQL + $sql = "SELECT song.id as songid,song.title as song,file,bitrate,size,time," . + "album.name AS album,album.id as albumid, artist.name AS artist,artist.id as artistid". " FROM song,artist,album ". " WHERE song.artist=artist.id AND song.album=album.id ". - " AND song.title= '".str_replace("'","''",$song->title)."'"; + " AND song.title= '".sql_escape($song->title)."'"; if ($search_type == "artist_title" || $search_type == "artist_album_title") { - $sql = $sql." AND artist.id = '".$song->artist."'"; + $sql .=" AND artist.id = '".$song->artist."'"; } if ($search_type == "artist_album_title" ) { - $sql = $sql." AND album.id = '".$song->album."'"; + $sql .=" AND album.id = '".$song->album."'"; } - $result = mysql_query($sql, dbh()); + if ($auto) { + $sql .= " ORDER BY time,bitrate,size"; + } + + $db_results = mysql_query($sql, dbh()); $arr = array(); - while ($flag = mysql_fetch_array($result)) { + while ($flag = mysql_fetch_assoc($db_results)) { $arr[] = $flag; } // end while @@ -84,7 +102,9 @@ function get_duplicate_info($song,$search_type) { @discussion */ function show_duplicate_songs($flags,$search_type) { + require_once(conf('prefix').'/templates/show_list_duplicates.inc.php'); + } // show_duplicate_songs /*! @@ -92,6 +112,9 @@ function show_duplicate_songs($flags,$search_type) { @discussion */ function show_duplicate_searchbox($search_type) { + require_once(conf('prefix') . '/templates/show_duplicates.inc.php'); + } // show_duplicate_searchbox + ?> |