diff options
author | lshprung <lshprung@yahoo.com> | 2021-09-12 11:41:07 -0700 |
---|---|---|
committer | lshprung <lshprung@yahoo.com> | 2021-09-12 11:41:07 -0700 |
commit | 7a5dbd86ff22344932b063077f68b9f6e9946431 (patch) | |
tree | e20ec888672dd0335ed8b2aa175345e06cf244c0 | |
parent | 7b6dfdf08f6e81bdf0cec9bc4157c12334c64898 (diff) |
Started working on script to build playlist files
-rw-r--r-- | .gitignore | 1 | ||||
-rwxr-xr-x | build_db.plx | 2 | ||||
-rwxr-xr-x | build_playlists.plx | 39 |
3 files changed, 41 insertions, 1 deletions
@@ -2,4 +2,5 @@ !.gitignore !build_db.plx +!build_playlists.plx !shared.pl diff --git a/build_db.plx b/build_db.plx index e98423a..7d2cf04 100755 --- a/build_db.plx +++ b/build_db.plx @@ -237,7 +237,7 @@ if (!$options{append}){ else { for my $i (sort(keys %columns)){ $statement = "SELECT COUNT(*) AS CNTREC FROM pragma_table_info('$table_name') WHERE name='$i';"; - if (db_cmd($dbh, $statement) == 0){ + if (!db_cmd($dbh, $statement)){ $statement = "ALTER TABLE $table_name ADD COLUMN \"$i\";"; db_cmd($dbh, $statement); } diff --git a/build_playlists.plx b/build_playlists.plx new file mode 100755 index 0000000..433c0a1 --- /dev/null +++ b/build_playlists.plx @@ -0,0 +1,39 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use DBI; +use File::HomeDir; + +require "./shared.pl"; + +# Variables to be set by the user +our $dbname = File::HomeDir->my_home . "/Music/library.db"; +our $output_dir; # By default, output in current directory +our $table_name = "LIBRARY"; + +my $statement; #Hold statements for sqlite + + +# Write to an m3u file to create a playlist +# @_[0] -> m3u file path +# @_[1] -> array of file paths +sub append_to_m3u { + open FH, ">> $_[0]" or die $!; + + for my $line ($_[1]){ + print FH $line; + } + + close FH; +} + +my $dbh = DBI->connect("DBI:SQLite:dbname=$dbname", "", "", { RaiseError => 1}) or die $DBI::errstr; +# DEBUG +print "Opened database successfully\n"; + +# Check that table exists +$statement = "SELECT count(*) FROM sqlite_master WHERE type='table' AND name='$table_name';"; +if (!db_cmd($dbh, $statement)){ + die "Error: table \"$table_name\" does not exist in $dbname"; +} |