{"id":4583,"date":"2024-02-16T03:17:08","date_gmt":"2024-02-16T10:17:08","guid":{"rendered":"https:\/\/www.sheer.us\/weblogs\/?p=4583"},"modified":"2024-02-16T03:18:10","modified_gmt":"2024-02-16T10:18:10","slug":"tascamslurp","status":"publish","type":"post","link":"https:\/\/www.sheer.us\/weblogs\/programming\/perl\/tascamslurp","title":{"rendered":"TascamSlurp"},"content":{"rendered":"<p>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<\/p>\n<p><PRE><br \/>\n#!\/usr\/bin\/perl<br \/>\n$|=1;<\/p>\n<p>$targetbase = &#8220;~\/DownloadLocation&#8221;;<br \/>\n$host = &#8220;tascam&#8221;;<\/p>\n<p>use Net::FTP;<br \/>\nuse Time::Local qw ( timelocal );<\/p>\n<p>use Data::Dumper;<\/p>\n<p>print &#8220;Creating FTP object\\n&#8221;;<\/p>\n<p>$ftp = Net::FTP->new($host, Debug => 0) || die &#8220;Can&#8217;t connect to tascam&#8221;;<br \/>\nprint &#8220;Logging in\\n&#8221;;<\/p>\n<p>$ftp->login(&#8220;DA-6400&#8243;,&#8221;DA-6400&#8221;) || die &#8220;Can&#8217;t login &#8221; , $ftp->message;<br \/>\nprint &#8220;CWD\\n&#8221;;<br \/>\n$ftp->cwd(&#8220;\/ssd\/DA Files&#8221;) || die &#8220;Cannot CWD: &#8221; . $ftp->message;<br \/>\nprint &#8220;BIN\\n&#8221;;<br \/>\n$ftp->binary() || die &#8220;Cannot set to bin mode: &#8221; . $ftp->message;<\/p>\n<p>my $list = $ftp->ls();<\/p>\n<p>my $maxtime = 0;<br \/>\nmy $timestamps = {};<\/p>\n<p># determine newest date<br \/>\nforeach $file (@{$list}) {<br \/>\n        next if($file eq &#8220;.&#8221;);<br \/>\n        next if($file eq &#8220;..&#8221;);<br \/>\n        next if(!($file =~ \/.*.wav\/));<\/p>\n<p>        my $unixtime = getFileTimestamp($file);<br \/>\n        my $ts = getTimestamp($unixtime);<\/p>\n<p>        print &#8220;file: [$file] ts: $ts\\n&#8221;;<br \/>\n        $maxtime = $unixtime if($unixtime > $maxtime);<br \/>\n        $timestamps->{$unixtime} = 1;<br \/>\n}<br \/>\nforeach $ts (keys %{$timestamps}) {<\/p>\n<p>        $targetstub = getTargetDir($ts);<br \/>\n        $targetdir = $targetbase . &#8216;\/&#8217; . $targetstub;<br \/>\n        if(! -d $targetdir) {<br \/>\n                mkdir $targetdir;<br \/>\n        } else {<br \/>\n                next;<br \/>\n        }<\/p>\n<p>        $targetdir .= &#8220;\/ftp&#8221;;<br \/>\n        if(! -d $targetdir) {<br \/>\n                mkdir $targetdir;<br \/>\n        }<\/p>\n<p>        chdir $targetdir;<br \/>\n        print &#8220;$ts &#8211; Writing to $targetdir\\n&#8221;;<\/p>\n<p>        foreach $file (@{$list}) {<br \/>\n                next if($file eq &#8220;.&#8221;);<br \/>\n                next if($file eq &#8220;..&#8221;);<br \/>\n                next if(!($file =~ \/.*.wav\/));<\/p>\n<p>                my $unixtime = getFileTimestamp($file);<br \/>\n                if($unixtime == $ts) {<br \/>\n                        print &#8220;Fetching $file ..&#8221;;<br \/>\n                        $ftp->get($file);<br \/>\n                        print (-s $file);<br \/>\n                        print &#8220;\\n&#8221;;<br \/>\n                }<br \/>\n        }<br \/>\n}<\/p>\n<p>sub getTargetDir<br \/>\n{<br \/>\n        my $time = shift;<br \/>\n        my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time);<br \/>\n        return sprintf(&#8220;%02d%02d%04d&#8221;,$mon+1,$mday,$year+1900);<br \/>\n}<\/p>\n<p>sub getTimestamp<br \/>\n{<br \/>\n        my $time = shift || time();<\/p>\n<p>        my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time);<br \/>\n        return sprintf(&#8220;%02d\/%02d\/%04d-%02d:%02d:%02d&#8221;,$mon+1,$mday,$year+1900,$hour,$min,$sec);<br \/>\n}<\/p>\n<p>sub getFileTimestamp<br \/>\n{<br \/>\n        my $file = shift;<br \/>\n        my ($prefix, $datetime, $take, $channel, $name) = split(\/_\/, $file);<\/p>\n<p>        print &#8220;Datetime: [$datetime]\\n&#8221; if($main::debug);<\/p>\n<p>        my ($date, $time) = split(\/-\/, $datetime);<br \/>\n        print &#8220;Date: [$date]\\n&#8221; if($main::debug);<\/p>\n<p>        my ($yy, $MM, $dd) = $date =~ \/(\\d{4})(\\d{2})(\\d{2})\/;<br \/>\n        my ($hh, $mm, $ss) = $time =~ \/(\\d{2})(\\d{2})(\\d{2})\/;<\/p>\n<p>        print &#8220;yy: [$yy] mm: $mm dd: $dd\\n&#8221; if($main::debug);<\/p>\n<p>        $MM -= 1;<br \/>\n        $yy -= 1900;<\/p>\n<p>        my $unixtime = timelocal($ss, $mm, $hh, $dd, $MM, $yy);<\/p>\n<p>        return $unixtime;<br \/>\n}<br \/>\n<\/PRE><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 = &#8220;~\/DownloadLocation&#8221;; $host = &#8220;tascam&#8221;; use Net::FTP; use Time::Local qw ( timelocal ); use Data::Dumper; print &#8220;Creating FTP object\\n&#8221;; $ftp = Net::FTP->new($host, Debug => 0) [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,3],"tags":[],"_links":{"self":[{"href":"https:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/posts\/4583"}],"collection":[{"href":"https:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/comments?post=4583"}],"version-history":[{"count":2,"href":"https:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/posts\/4583\/revisions"}],"predecessor-version":[{"id":4585,"href":"https:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/posts\/4583\/revisions\/4585"}],"wp:attachment":[{"href":"https:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/media?parent=4583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/categories?post=4583"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/tags?post=4583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}