diff options
-rw-r--r-- | bin/delete_disabled.inc | 20 | ||||
-rw-r--r-- | bin/sort_files.inc | 49 | ||||
-rwxr-xr-x | docs/CHANGELOG | 1 | ||||
-rw-r--r-- | lib/class/catalog.class.php | 21 | ||||
-rw-r--r-- | lib/class/song.class.php | 6 | ||||
-rw-r--r-- | lib/class/stream.class.php | 2 |
6 files changed, 37 insertions, 62 deletions
diff --git a/bin/delete_disabled.inc b/bin/delete_disabled.inc index bec402ea..f975cbc2 100644 --- a/bin/delete_disabled.inc +++ b/bin/delete_disabled.inc @@ -1,7 +1,7 @@ <?php /* - Copyright 2001 - 2006 Ampache.org + Copyright 2001 - 2007 Ampache.org All Rights Reserved This program is free software; you can redistribute it and/or @@ -34,19 +34,21 @@ $path = dirname(__FILE__); $prefix = realpath($path . '/../'); require_once $prefix . '/lib/init.php'; -/* Get a list of filenames */ -$sql = "SELECT id,file FROM song WHERE enabled='0'"; -$db_results = mysql_query($sql,dbh()); +if ($debug) { echo "DEBUG ENABLED WILL NOT DELETE FILES!\n"; } -while ($r = mysql_fetch_assoc($db_results)) { +/* Get a list of filenames */ +$sql = "SELECT `id`,`file` FROM song WHERE enabled='0'"; +$db_results = Dba::query($sql); +while ($row = Dba::fetch_assoc($db_results)) { if ($debug) { - echo "Deleting: " . $r['file'] . "\n"; + echo "Would Delete: " . $row['file'] . "\n"; } else { - unlink($r['file']); - $sql = "DELETE FROM song WHERE id='" . sql_escape($r['id']) . "'"; - $del_results = mysql_query($sql,dbh()); + echo "Deleting: " . $row['file'] . "\n"; + unlink($row['file']); + $sql = "DELETE FROM `song` WHERE `id`='" . Dba::escape($row['id']) . "'"; + $del_results = Dba::query($sql); } } // end while diff --git a/bin/sort_files.inc b/bin/sort_files.inc index cb01e7f1..3a1d71cc 100644 --- a/bin/sort_files.inc +++ b/bin/sort_files.inc @@ -32,7 +32,7 @@ */ /* Don't do anything just tell me what you would do */ -//$test_mode = true; +$test_mode = true; /* m(__)m */ $alphabet_prefix = true; @@ -42,14 +42,16 @@ $path = dirname(__FILE__); $prefix = realpath($path . '/../'); require_once $prefix . '/lib/init.php'; +ob_end_clean(); + /* First Clean the catalog to we don't try to write anything we shouldn't */ $sql = "SELECT id FROM catalog WHERE catalog_type='local'"; -$db_results = mysql_query($sql, dbh()); +$db_results = Dba::query($sql); $catalogs = array(); -while ($r = mysql_fetch_row($db_results)) { +while ($r = Dba::fetch_row($db_results)) { $catalog = new Catalog($r['0']); $songs = $catalog->get_catalog_files(); @@ -59,7 +61,7 @@ while ($r = mysql_fetch_row($db_results)) { /* Foreach through each file and find it a home! */ foreach ($songs as $song) { /* Find this poor song a home */ - $song->format_song(); + $song->format(); $song->format_pattern(); $directory = sort_find_home($song,$catalog->sort_pattern,$catalog->path); $filename = $song->f_file; @@ -78,8 +80,6 @@ while ($r = mysql_fetch_row($db_results)) { sort_move_file($song,$fullpath); } - - } // end foreach song } // end foreach catalogs @@ -87,35 +87,6 @@ while ($r = mysql_fetch_row($db_results)) { /************** FUNCTIONS *****************/ /** - * sort_find_filename - * This gets the filename that this file should have, it takes the rename pattern of the catalog - * along with the song object. Nothing Special Here - */ -function sort_find_filename($song,$rename_pattern) { - - $extension = ltrim(substr($song->file,strlen($song->file)-4,4),"."); - - /* Create the filename that this file should have */ - $album = sort_clean_name($song->f_album_full); - $artist = sort_clean_name($song->f_artist_full); - $genre = sort_clean_name($song->f_genre); - $track = sort_clean_name($song->track); - $title = sort_clean_name($song->title); - $year = sort_clean_name($song->year); - - /* Start replacing stuff */ - $replace_array = array('%a','%A','%t','%T','%y','%g'); - $content_array = array($artist,$album,$title,$track,$year,$genre); - - $rename_pattern = str_replace($replace_array,$content_array,$rename_pattern); - - $rename_pattern = preg_replace("[\-\:\!]","_",$rename_pattern); - - return $rename_pattern . "." . $extension; - -} // sort_find_filename - -/** * sort_find_home * Get the directory for this file from the catalog and the song info using the sort_pattern * takes into account various artists and the alphabet_prefix @@ -135,6 +106,7 @@ function sort_find_home($song,$sort_pattern,$base) { /* Do the various check */ $album_object = new Album($song->album); + $album_object->format(); if ($album_object->artist_count != '1') { $artist = "Various"; } @@ -267,8 +239,9 @@ function sort_move_file($song,$fullname) { /* Now that we've got the correct directory structure let's try to copy it */ if ($GLOBALS['test_mode']) { echo "\tCopying $file to $directory\n"; - $sql = "UPDATE song SET file='" . sql_escape($fullname) . "' WHERE id='" . sql_escape($song->id) . "'"; + $sql = "UPDATE song SET file='" . Dba::escape($fullname) . "' WHERE id='" . Dba::escape($song->id) . "'"; echo "\tSQL: $sql\n"; + flush(); } else { @@ -311,8 +284,8 @@ function sort_move_file($song,$fullname) { if (!$results) { echo "Error: Unable to delete " . $song->file . "\n"; } /* Update the catalog */ - $sql = "UPDATE song SET file='" . sql_escape($fullname) . "' WHERE id='" . sql_escape($song->id) . "'"; - $db_results = mysql_query($sql, dbh()); + $sql = "UPDATE song SET file='" . Dba::escape($fullname) . "' WHERE id='" . Dba::escape($song->id) . "'"; + $db_results = Dba::query($sql); } // end else diff --git a/docs/CHANGELOG b/docs/CHANGELOG index 4383e026..7784169a 100755 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -4,6 +4,7 @@ -------------------------------------------------------------------------- v.3.4-Alpha4 + - Fixed Delete Disabled & Sort Files command line scripts - Fixed Find Duplicates Functionality - Added Highest Rated option to Advanced Random - Fixed incorrect mime type being set on ASX playlists diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php index d5e8535f..ce5c3e0d 100644 --- a/lib/class/catalog.class.php +++ b/lib/class/catalog.class.php @@ -677,24 +677,23 @@ class Catalog { } // get_catalog_albums - /*! - @function get_catalog_files - @discussion Returns an array of song objects from a catalog - @param $catalog_id=0 Specify the catalog ID you want to get the files of - */ - function get_catalog_files($catalog_id=0) { + /** + * get_catalog_files + * Returns an array of song objects from a catalog, used by sort_files script + */ + public function get_catalog_files($catalog_id=0) { $results = array(); /* Use $this->id if nothing passed */ - if (!$catalog_id) { $catalog_id = $this->id; } + $catalog_id = $catalog_id ? Dba::escape($catalog_id) : Dba::escape($this->id); - $sql = "SELECT id FROM song WHERE catalog='$catalog_id' AND enabled='1'"; - $db_results = mysql_query($sql, dbh()); + $sql = "SELECT `id` FROM `song` WHERE `catalog`='$catalog_id' AND `enabled`='1'"; + $db_results = Dba::query($sql); $results = array(); // return an emty array instead of nothing if no objects - while ($r = mysql_fetch_object($db_results)) { - $results[] = new Song($r->id); + while ($r = Dba::fetch_assoc($db_results)) { + $results[] = new Song($r['id']); } //end while return $results; diff --git a/lib/class/song.class.php b/lib/class/song.class.php index 8a9a6637..4aa773fd 100644 --- a/lib/class/song.class.php +++ b/lib/class/song.class.php @@ -725,13 +725,13 @@ class Song { $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','%g','/','\\'); + $content_array = array($artist,$album,$title,$track,$year,$genre,'-','-'); $rename_pattern = str_replace($replace_array,$content_array,$catalog->rename_pattern); $rename_pattern = preg_replace("[\-\:\!]","_",$rename_pattern); - + $this->f_pattern = $rename_pattern; $this->f_file = $rename_pattern . "." . $extension; diff --git a/lib/class/stream.class.php b/lib/class/stream.class.php index 18350a0e..507cee02 100644 --- a/lib/class/stream.class.php +++ b/lib/class/stream.class.php @@ -309,7 +309,7 @@ class Stream { header("Cache-control: public"); header("Content-Disposition: filename=playlist.asx"); - header("Content-Type: audio/x-ms-wax;"); + header("Content-Type: audio/x-ms-wmv;"); echo "<ASX version = \"3.0\" BANNERBAR=\"AUTO\">\n"; echo "<TITLE>Ampache ASX Playlist</TITLE>"; |