TascamSlurp

This is a perl script that can be used to pull all the files from a DA-6400 and automatically divide them into folders based on their timestamps


#!/usr/bin/perl
$|=1;

$targetbase = “~/DownloadLocation”;
$host = “tascam”;

use Net::FTP;
use Time::Local qw ( timelocal );

use Data::Dumper;

print “Creating FTP object\n”;

$ftp = Net::FTP->new($host, Debug => 0) || die “Can’t connect to tascam”;
print “Logging in\n”;

$ftp->login(“DA-6400″,”DA-6400”) || die “Can’t login ” , $ftp->message;
print “CWD\n”;
$ftp->cwd(“/ssd/DA Files”) || die “Cannot CWD: ” . $ftp->message;
print “BIN\n”;
$ftp->binary() || die “Cannot set to bin mode: ” . $ftp->message;

my $list = $ftp->ls();

my $maxtime = 0;
my $timestamps = {};

# determine newest date
foreach $file (@{$list}) {
next if($file eq “.”);
next if($file eq “..”);
next if(!($file =~ /.*.wav/));

my $unixtime = getFileTimestamp($file);
my $ts = getTimestamp($unixtime);

print “file: [$file] ts: $ts\n”;
$maxtime = $unixtime if($unixtime > $maxtime);
$timestamps->{$unixtime} = 1;
}
foreach $ts (keys %{$timestamps}) {

$targetstub = getTargetDir($ts);
$targetdir = $targetbase . ‘/’ . $targetstub;
if(! -d $targetdir) {
mkdir $targetdir;
} else {
next;
}

$targetdir .= “/ftp”;
if(! -d $targetdir) {
mkdir $targetdir;
}

chdir $targetdir;
print “$ts – Writing to $targetdir\n”;

foreach $file (@{$list}) {
next if($file eq “.”);
next if($file eq “..”);
next if(!($file =~ /.*.wav/));

my $unixtime = getFileTimestamp($file);
if($unixtime == $ts) {
print “Fetching $file ..”;
$ftp->get($file);
print (-s $file);
print “\n”;
}
}
}

sub getTargetDir
{
my $time = shift;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time);
return sprintf(“%02d%02d%04d”,$mon+1,$mday,$year+1900);
}

sub getTimestamp
{
my $time = shift || time();

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time);
return sprintf(“%02d/%02d/%04d-%02d:%02d:%02d”,$mon+1,$mday,$year+1900,$hour,$min,$sec);
}

sub getFileTimestamp
{
my $file = shift;
my ($prefix, $datetime, $take, $channel, $name) = split(/_/, $file);

print “Datetime: [$datetime]\n” if($main::debug);

my ($date, $time) = split(/-/, $datetime);
print “Date: [$date]\n” if($main::debug);

my ($yy, $MM, $dd) = $date =~ /(\d{4})(\d{2})(\d{2})/;
my ($hh, $mm, $ss) = $time =~ /(\d{2})(\d{2})(\d{2})/;

print “yy: [$yy] mm: $mm dd: $dd\n” if($main::debug);

$MM -= 1;
$yy -= 1900;

my $unixtime = timelocal($ss, $mm, $hh, $dd, $MM, $yy);

return $unixtime;
}

Leave a Reply