summaryrefslogtreecommitdiffstats
path: root/lib/class
diff options
context:
space:
mode:
authorPaul Arthur <paul.arthur@flowerysong.com>2013-01-25 20:49:16 -0500
committerPaul Arthur <paul.arthur@flowerysong.com>2013-01-25 20:49:16 -0500
commitcad1380737f7ffcfa82d46ab3066823435a48a5d (patch)
treee64277b52b26bc549c66e08f8f662279da08fa6e /lib/class
parent80f4859712b433d8cee1158951efc19e939224f4 (diff)
downloadampache-cad1380737f7ffcfa82d46ab3066823435a48a5d.tar.gz
ampache-cad1380737f7ffcfa82d46ab3066823435a48a5d.tar.bz2
ampache-cad1380737f7ffcfa82d46ab3066823435a48a5d.zip
Move duplicate searching from Catalog to Song
Catalog::get_duplicate_songs() -> Song::find_duplicates() Catalog::get_duplicate_info() -> Song::get_duplicate_info()
Diffstat (limited to 'lib/class')
-rw-r--r--lib/class/catalog.class.php74
-rw-r--r--lib/class/song.class.php57
2 files changed, 61 insertions, 70 deletions
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
*/