OSDN Git Service

add reclogrm.pl, a tool to maintain recording temp folder
authorlonginus <longinus@4e526526-5e11-4fc0-8910-f8fd03428081>
Fri, 4 Jan 2013 16:24:43 +0000 (16:24 +0000)
committerlonginus <longinus@4e526526-5e11-4fc0-8910-f8fd03428081>
Fri, 4 Jan 2013 16:24:43 +0000 (16:24 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/rec10@953 4e526526-5e11-4fc0-8910-f8fd03428081

rectool/trunk/reclogrm.pl [new file with mode: 0755]

diff --git a/rectool/trunk/reclogrm.pl b/rectool/trunk/reclogrm.pl
new file mode 100755 (executable)
index 0000000..a0515bd
--- /dev/null
@@ -0,0 +1,52 @@
+#!/usr/bin/perl
+
+use utf8;
+use Config::Simple;
+use Data::Dumper::Concise;
+
+my $exps = qq/.log .log.zip .command.log .b25.log .mencoder.log .x264.log .mp4box.log .ts.b25 .ts.tsmix .ts .mp4 .264 .mp3 .aac .wav .m2v/;
+$exps =~ s/ /|/g;
+$exps =~ s/\./\\./g;
+
+my $cfg = new Config::Simple;
+$cfg->read('/etc/rec10.conf');
+
+my $recording = $cfg->param('path.recpath');
+opendir(DIR, $recording);
+my @files = readdir(DIR);
+closedir(DIR);
+
+my @failed;
+my %files;
+
+foreach (@files) {
+       next if ($_ eq '.' || $_ eq '..' || -d "$recording/$_");
+       my ($file, $exp) = $_ =~ /(.+?)($exps)\Z/;
+       if ($file eq '' || $file =~ /\.\w+\Z/) {
+               push(@failed, $_);
+       }
+       $files{$file}->{$exp} = '';
+}
+
+if (@failed) {
+       die "Unknown exps: @failed";
+}
+
+foreach (keys %files) {
+       my @existing_exps = keys %{$files{$_}};
+       my @existing_exps_with_log    = grep( /log/, @existing_exps);
+       my @existing_exps_without_log = grep(!/log/, @existing_exps);
+       if ( @existing_exps_with_log == @existing_exps ) {
+               print "$_ @existing_exps\n";
+               foreach my $exp (@existing_exps) {
+                       system "mv '$recording/$_$exp' '$recording/log/$_$exp'\n";
+               }
+       }
+       elsif ( @existing_exps_without_log == 1 and $existing_exps_without_log[0] eq '.mp4' ) {
+               print "only mp4 remaining: $_\n";
+               foreach my $exp (@existing_exps_with_log) {
+                       system "mv '$recording/$_$exp' '$recording/log/$_$exp'\n";
+               }
+       }
+}
+