From a3439befb65b4dafe7c0d4808f599c77052f8e84 Mon Sep 17 00:00:00 2001 From: lshprung Date: Fri, 10 Sep 2021 14:26:07 -0700 Subject: Fix for array tags --- build_db.plx | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'build_db.plx') 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; -- cgit