diff options
author | Christian Pointner <equinox@helsinki.at> | 2010-03-24 11:41:13 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2010-03-24 11:41:13 (GMT) |
commit | c9d2691935e2a87cb74b6f04ad6b4f561728e0c6 (patch) | |
tree | 3b2ae589421775e11657748bd97a9bc3519856bb /rhimport.pm | |
parent | f52380b976948ec2f3776d63baaf2549f4a81b49 (diff) |
improved handling of ListStore
better formatting for dropbox names in GUI
added emptyCarts function
basic m3u parsing
Diffstat (limited to 'rhimport.pm')
-rw-r--r-- | rhimport.pm | 113 |
1 files changed, 112 insertions, 1 deletions
diff --git a/rhimport.pm b/rhimport.pm index 512652b..5827bb2 100644 --- a/rhimport.pm +++ b/rhimport.pm @@ -25,12 +25,120 @@ use strict; package rhimport; +sub get_dropboxes +{ + my $dbh = shift; + my $user = shift; + + my $sql = qq{select USER_PERMS.GROUP_NAME,DROPBOXES.PATH from USER_PERMS, DROPBOXES where USER_PERMS.USER_NAME='$user' and DROPBOXES.GROUP_NAME=USER_PERMS.GROUP_NAME;}; + my $sth = $dbh->prepare($sql); + $sth->execute(); + my @allowed_dbs; + while(my ($group, $path) = $sth->fetchrow_array()) { + $path =~ s/\/\*$//; + my $name = $path; + $name =~ s/^\/programm\///; + if($name =~ /^([0-9]{2}-[A-Za-z]+)\/([0-9]{4})-([01]{4})-([0-9]{3})-(.*)$/) { + $name = "$1 - $2: $5 ($3, $4)"; + } + elsif($name =~ /^([0-9]{2}-[A-Za-z]+)\/programmvorschau_(.*)$/) { + $name = "Programmvorschau - $1 - $2"; + } + elsif($name =~ /^([0-9]{2}-[A-Za-z]+)\/jingle$/ || $name =~ /^jingles\/(.*)$/) { + $name = "Jingles - $1"; + } + elsif($name =~ /^pool\/pool(.*)$/) { + $name = "Pool - $1"; + } + elsif($name =~ /^pool\/(.*)$/) { + $name = "Pool - $1"; + } + elsif($name =~ /^sondersendungen\/(.*)$/) { + $name = "Sondersendungen - $1"; + } + my $perm = {}; + $perm->{'GROUP'} = $group; + $perm->{'PATH'} = $path; + $perm->{'NAME'} = $name; + push @allowed_dbs, $perm; + } + $sth->finish(); + + return sort { uc($a->{'NAME'}) cmp uc($b->{'NAME'}) } @allowed_dbs; +} + +sub get_cart_range +{ + my $dbh = shift; + my $group = shift; + + my $sql = qq{select DEFAULT_LOW_CART,DEFAULT_HIGH_CART from GROUPS where NAME='$group';}; + my $sth = $dbh->prepare($sql); + $sth->execute(); + my @carts; + my ($low_cart, $high_cart) = $sth->fetchrow_array(); + $sth->finish(); + + return ($low_cart, $high_cart); +} + +sub get_used_carts +{ + my $dbh = shift; + my $group = shift; + + my ($low_cart, $high_cart) = get_cart_range($dbh, $group); + my @carts; + return @carts; +} + +sub empty_carts +{ + my $dbh = shift; + my $group = shift; + my ($low_cart, $high_cart) = get_cart_range($dbh, $group); + + my $cart = $low_cart; + while($cart <= $high_cart) { + my $sql = qq{select CUT_NAME from CUTS where CART_NUMBER='$cart';}; + my $sth = $dbh->prepare($sql); + $sth->execute(); + while(my $cut_name = $sth->fetchrow_array()) { + my $filename = "/var/snd/$cut_name.wav"; + + ### call unlink!!! + print "deleting $filename\n"; + } + $sth->finish(); + +# my $sql = qq{delete from CUTS where CART_NUMBER='$cart';}; +# my $sth = $dbh->prepare($sql); +# $sth->execute(); +# $sth->finish(); + +# my $sql = qq{delete from CARTS where NUMBER='$cart';}; +# my $sth = $dbh->prepare($sql); +# $sth->execute(); +# $sth->finish(); + + $cart++; + } +} + sub import_playlist { my ($playlist, $dropbox) = @_; print "Starting import from playlist $playlist to $dropbox\n"; + open (FILE, $playlist) or die "can't open playlist $playlist: $!"; + while (my $entry = <FILE>) { + next if($entry =~ /^#/); + next if($entry =~ /^\s/); + $entry =~ s/\n$//; + import_file($entry, $dropbox); + } + close(FILE); return 0; } @@ -39,8 +147,11 @@ sub import_file { my ($file, $dropbox) = @_; - print "Starting import from $file to $dropbox\n"; + print "importing $file to $dropbox .. "; + $| = 1; + sleep(1); + print "Ok\n"; return 0; } |