From de32e720430c246af85209d210fb847fe477c63c Mon Sep 17 00:00:00 2001 From: lshprung Date: Wed, 8 Sep 2021 12:09:05 -0700 Subject: Table gets PATH for each file, ready to start setting tags --- main.plx | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/main.plx b/main.plx index 13f98a3..1c83970 100755 --- a/main.plx +++ b/main.plx @@ -102,6 +102,15 @@ for my $i (sort @file_list){ print "$i\n"; } +# Get tags for each file +#for my $file (sort @file_list){ +# $data = Audio::Scan->scan("$file"); +# $data = $data->{tags}; +# for my $i (keys %$data){ +# print "$i -> $data->{$i}\n"; +# } +#} + # Append tags to %columns for my $file (@file_list){ $data = Audio::Scan->scan("$file"); @@ -119,19 +128,33 @@ for my $i (keys %columns){ my $dbh = DBI->connect("DBI:SQLite:dbname=$music_dir/$dbname", "", "", { RaiseError => 1}) or die $DBI::errstr; print "Opened database successfully\n"; -# Create table in the database +# Overwrite $table_name if it exists (TODO alert user to overwrite) +# TODO create option to append to table, instead of overwriting +$statement = "DROP TABLE if EXISTS $table_name"; +db_cmd($dbh, $statement, "Overwriting table \"$table_name\""); + +# Create table $table_name in the database with columns from %columns +# Need to create additional columns for ID and PATH $statement = "CREATE TABLE $table_name -(ID INT PRIMARY KEY NOT NULL);"; +(ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, +PATH TEXT NOT NULL"; +for my $i (keys %columns){ + $statement = $statement . ", + \"$i\" TEXT"; +} +$statement = $statement . ");"; db_cmd($dbh, $statement, "Created table successfully"); - -# Get tags for each file -#for my $file (sort @file_list){ -# $data = Audio::Scan->scan("$file"); -# $data = $data->{tags}; -# for my $i (keys %$data){ -# print "$i -> $data->{$i}\n"; -# } -#} +# Add each file from @file_list to the table +$statement = "INSERT INTO $table_name(PATH) +VALUES"; +for my $file (@file_list){ + $statement = $statement . "(\"$file\"),"; +} +$statement =~ s/[,]$/;/g; +db_cmd($dbh, $statement); + +# Set each file's tags in the table + # Disconnect from sqlite database $dbh->disconnect(); -- cgit