From bad34ad0166f03e753905aae1bbe1cdea2d9c4f8 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Fri, 20 Jun 2014 18:00:17 +0000 Subject: added check for supported file extension diff --git a/rhimport-zf b/rhimport-zf index 24c7ad7..c255519 100755 --- a/rhimport-zf +++ b/rhimport-zf @@ -115,6 +115,11 @@ for my $entry ($feed->entries) { exit 0; } $out_file = $ff->output_file; + if(!rhimport::check_file_extension($out_file)) { + print "\n\nThe extension of the matching file '". $out_file . "' seems to be wrong - manual import necessary!!!\n"; + $dbh->disconnect(); + exit 0; + } print $regexp . ": downloading " . $entry->enclosure->url . " (" . $entry->enclosure->length . " Bytes) .. "; $file = $ff->fetch( to => '/tmp' ) or die $ff->error; diff --git a/rhimport.pm b/rhimport.pm index 1263e7e..79c921e 100644 --- a/rhimport.pm +++ b/rhimport.pm @@ -28,6 +28,7 @@ package rhimport; use IO::Handle; use IPC::Open3; use File::Spec; +use File::Basename; use URI::Escape; my $ssh_host = "airplay"; @@ -135,11 +136,11 @@ sub clear_carts } my $log = "clearing Carts $low_cart - $high_cart\n"; - print $log; + print $log; my $cart = $low_cart; while($cart <= $high_cart) { $progress_cb->($cart - $low_cart, $high_cart + 1 - $low_cart, "deleting $cart") if($progress_cb); - + my $sql = qq{select CUT_NAME from CUTS where CART_NUMBER='$cart';}; my $sth = $dbh->prepare($sql); $sth->execute(); @@ -148,12 +149,12 @@ sub clear_carts $log .= " - deleting file /var/snd/$cut_name.wav"; } $sth->finish(); - + $sql = qq{delete from CUTS where CART_NUMBER='$cart';}; $sth = $dbh->prepare($sql); $sth->execute(); $sth->finish(); - + $sql = qq{delete from CART where NUMBER='$cart';}; $sth = $dbh->prepare($sql); $sth->execute(); @@ -165,6 +166,19 @@ sub clear_carts return $log; } +sub check_file_extension +{ + my ($file) = @_; + + my $ext = uc((fileparse($file, qr/\.[^.]*/))[2]); + foreach (".MP3", ".OGG", ".FLAC", ".WAV") { + if($ext eq $_) { + return 1; + } + } + return 0; +} + sub import_playlist { my ($playlist, $dropbox, $user, $num_carts, $progress_cb, $error_cb) = @_; @@ -181,7 +195,7 @@ sub import_playlist $entry = uri_unescape($entry); next if(-d $entry); next if(!-r $entry); - push @entries, $entry; + push @entries, $entry; } close(FILE); my $num_entries = scalar(@entries); @@ -239,7 +253,7 @@ sub import_single return ($ret, $out); } -sub scp_put_file +sub scp_put_file { my ($file, $user, $host, $path) = @_; my @cmd = ( 'scp', '-prqB', '-i', $ssh_key_file, $file, "$user\@$host:$path/" ); @@ -258,7 +272,7 @@ sub scp_put_file return $errstr; } -sub ssh_exec_command +sub ssh_exec_command { my ($command) = @_; my @cmd = ( 'ssh' , '-q', '-o', 'BatchMode=yes', '-i', $ssh_key_file, "$ssh_user\@$ssh_host" , $command ); @@ -305,9 +319,9 @@ sub import_file } print "transferred .. "; - ### remotely call rdimport + ### remotely call rdimport my ($volume, $directories, $remote_file) = File::Spec->splitpath($file); - $remote_file = "$ssh_dir/$user/$remote_file"; + $remote_file = "$ssh_dir/$user/$remote_file"; my ($out ,$error) = ssh_exec_command("$rdimport_wrapper --path \"$dropbox\" --file \"$remote_file\""); my $lastline = $1 if $out =~ /\n(.*)$/; if($error ne "" || $lastline !~ /^[0-9:\- ]+:\s+Deleted file/) { -- cgit v0.10.2