summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbuild_db.plx8
-rwxr-xr-xbuild_playlists.plx1
-rw-r--r--shared.pl4
3 files changed, 11 insertions, 2 deletions
diff --git a/build_db.plx b/build_db.plx
index 1b01b58..4f5bcad 100755
--- a/build_db.plx
+++ b/build_db.plx
@@ -23,6 +23,7 @@ our %extensions;
# Keep track of options that have been set
our %options = (
append => 0,
+ debug => 0,
output => 0,
quiet => 0
);
@@ -98,6 +99,7 @@ Generate a database for audio files in DIRECTORY (by default ~/Music).
Options:
-a, --append append to database file, instead of overwriting it
+ -d, --debug print additional output for debugging purposes
-e, --extension EXTENSIONS Set file extensions to look for, separated by commas (default is flac,mp3,ogg)
-h, --help display this help and exit
-o, --output FILE specify output file for database (default is library.db at the root of DIRECTORY)
@@ -113,6 +115,10 @@ for (my $i = 0; $i <= $#ARGV; $i++){
$options{append} = 1;
}
+ if ($ARGV[$i] =~ /-d|--debug/){
+ $options{debug} = 1;
+ }
+
elsif ($ARGV[$i] =~ /-e|--extension/){
$i++;
$extensions_list = $ARGV[$i];
@@ -231,7 +237,7 @@ $statement = "INSERT INTO $table_name(PATH)
VALUES";
for my $file (@file_list){
# Skip existing files
- @db_output = flatten_array(db_cmd($dbh, "SELECT count(*) FROM $table_name WHERE PATH='$file';"));
+ @db_output = flatten_array(db_cmd($dbh, "SELECT count(*) FROM $table_name WHERE PATH=\"$file\";")); #FIXME this can break if there is a '"' character in a filename
if(!$db_output[0]){
$statement = $statement . "(\"$file\"),";
diff --git a/build_playlists.plx b/build_playlists.plx
index 9a41942..a2e0760 100755
--- a/build_playlists.plx
+++ b/build_playlists.plx
@@ -30,7 +30,6 @@ sub build_m3u {
my $filehandle = shift;
# Create m3u header
- # TODO check if file is empty before adding the header
if (eof $filehandle){
print $filehandle "#EXTM3U\n\n";
}
diff --git a/shared.pl b/shared.pl
index 4c71855..b07071b 100644
--- a/shared.pl
+++ b/shared.pl
@@ -6,6 +6,10 @@
# @_[1] -> command/statement
# @_[2] (optional) -> output statement
sub db_cmd {
+ if ($options{debug}){
+ print "Preparing SQL query \"$_[1]\"\n"
+ }
+
my $sth = $_[0]->prepare($_[1]);
if ($sth->execute < 0){