summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlshprung <lshprung@yahoo.com>2021-09-09 18:33:54 -0700
committerlshprung <lshprung@yahoo.com>2021-09-09 18:33:54 -0700
commita59fdc08f2efbfbbd20c36e942b1d65b177d1320 (patch)
treec95e5407182f32ca3590f3239158da3922131617
parent175ecce690b06de2053ff60aa1d1ad84bd72e724 (diff)
Added --extension flag
-rwxr-xr-xbuild_db.plx31
1 files changed, 26 insertions, 5 deletions
diff --git a/build_db.plx b/build_db.plx
index 4ef65c5..4fc67d1 100755
--- a/build_db.plx
+++ b/build_db.plx
@@ -15,11 +15,8 @@ our %columns;
our $music_dir = File::HomeDir->my_home . "/Music/";
our $dbname;
our $table_name = "LIBRARY";
-our %extensions = (
- flac => '1',
- mp3 => '1',
- ogg => '1'
-);
+our $extensions_list = "flac,mp3,ogg";
+our %extensions;
# Keep track of options that have been set
our %options = (
@@ -39,6 +36,13 @@ sub audio_scan {
return %$data;
}
+sub build_extension_hash {
+ my @extensions_arr = split /[,]/,$extensions_list;
+ for my $i (@extensions_arr){
+ $extensions{$i} = 1;
+ }
+}
+
# Wrapper to handle sqlite commands
# @_[0] -> database handle
# @_[1] -> command/statement
@@ -102,6 +106,7 @@ Generate a database for audio files in DIRECTORY (by default ~/Music).
Options:
-a, --append append to database file, instead of overwriting it
+ -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)
-t, --table-name TABLE specify table name in database file (default is LIBRARY)
@@ -124,6 +129,11 @@ for (my $i = 0; $i <= $#ARGV; $i++){
$options{append} = 1;
}
+ elsif ($ARGV[$i] =~ /-e|--extension/){
+ $i++;
+ $extensions_list = $ARGV[$i];
+ }
+
elsif ($ARGV[$i] =~ /-h|--help/){
print_help();
exit;
@@ -151,12 +161,18 @@ $music_dir =~ s/\/+$//g;
if (!$options{output}){
$dbname = $music_dir . "/library.db";
}
+for my $i (keys %extensions){
+ print "$i\n";
+}
# Test to ensure $music_dir is a valid directory
if (! -d $music_dir){
die "Error: \"$music_dir\" is not a directory\n";
}
+# Build the extensions hash for use in get_files
+build_extension_hash();
+
# Get a list of files in $music_dir
print "Looking through files in $music_dir\n";
my @file_list = get_files($music_dir, %extensions);
@@ -165,6 +181,11 @@ for my $i (sort @file_list){
print "$i\n";
}
+# Quit if @file_list is empty
+if ($#file_list < 1){
+ die "Error: Could not find any files in \"$music_dir\" matching extension(s) \"$extensions_list\"\n";
+}
+
# Get tags for each file
#for my $file (sort @file_list){
# $data = Audio::Scan->scan("$file");