diff options
author | lshprung <lshprung@yahoo.com> | 2021-09-10 14:26:07 -0700 |
---|---|---|
committer | lshprung <lshprung@yahoo.com> | 2021-09-10 14:26:07 -0700 |
commit | a3439befb65b4dafe7c0d4808f599c77052f8e84 (patch) | |
tree | d54b5fd8e5071c404b48841dedb40467d798be92 | |
parent | a59fdc08f2efbfbbd20c36e942b1d65b177d1320 (diff) |
Fix for array tags
-rwxr-xr-x | build_db.plx | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/build_db.plx b/build_db.plx index 4fc67d1..fa314c7 100755 --- a/build_db.plx +++ b/build_db.plx @@ -28,6 +28,26 @@ my %data; #Hold info from Audio::Scan my $statement; #Hold statements for sqlite +# Handle digging into non-scalar tags +# @_[0] -> array tag +sub array_handler { + my $output = ""; + + for my $i (@_){ + # If another array, recursively handle + if (ref($i) eq 'ARRAY'){ + $output = $output . array_handler(@$i); + } + + # If scalar, append to output normally + elsif (!ref($i)){ + $output = $output . "$i;"; + } + } + + return $output; +} + # Wrapper to handle calls to Audio::Scan->scan(); returns tags hash # @_[0] -> file to scan sub audio_scan { @@ -265,7 +285,18 @@ for my $file (@file_list){ for my $i (sort(keys %data)){ next if $i eq "MCDI"; #FIXME MCDI field creates issues $data{$i} =~ s/\"/\'\'/g; - $statement = $statement . "\"$i\" = \"$data{$i}\","; + $statement = $statement . "\"$i\" = \""; + + # If tag is an array, encode the array into semicolon-separated string + if (ref($data{$i}) eq 'ARRAY'){ + $statement = $statement . array_handler($data{$i}); + $statement =~ s/[;]+$//g; + $statement = $statement . "\","; + } + + else { + $statement = $statement . "$data{$i}\","; + } } $statement =~ s/[,]$/\n/g; |