OSDN Git Service

add reclogrm.pl, a tool to maintain recording temp folder
[rec10/rec10-git.git] / rectool / trunk / reclogrm.pl
1 #!/usr/bin/perl
2
3 use utf8;
4 use Config::Simple;
5 use Data::Dumper::Concise;
6
7 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/;
8 $exps =~ s/ /|/g;
9 $exps =~ s/\./\\./g;
10
11 my $cfg = new Config::Simple;
12 $cfg->read('/etc/rec10.conf');
13
14 my $recording = $cfg->param('path.recpath');
15 opendir(DIR, $recording);
16 my @files = readdir(DIR);
17 closedir(DIR);
18
19 my @failed;
20 my %files;
21
22 foreach (@files) {
23         next if ($_ eq '.' || $_ eq '..' || -d "$recording/$_");
24         my ($file, $exp) = $_ =~ /(.+?)($exps)\Z/;
25         if ($file eq '' || $file =~ /\.\w+\Z/) {
26                 push(@failed, $_);
27         }
28         $files{$file}->{$exp} = '';
29 }
30
31 if (@failed) {
32         die "Unknown exps: @failed";
33 }
34
35 foreach (keys %files) {
36         my @existing_exps = keys %{$files{$_}};
37         my @existing_exps_with_log    = grep( /log/, @existing_exps);
38         my @existing_exps_without_log = grep(!/log/, @existing_exps);
39         if ( @existing_exps_with_log == @existing_exps ) {
40                 print "$_ @existing_exps\n";
41                 foreach my $exp (@existing_exps) {
42                         system "mv '$recording/$_$exp' '$recording/log/$_$exp'\n";
43                 }
44         }
45         elsif ( @existing_exps_without_log == 1 and $existing_exps_without_log[0] eq '.mp4' ) {
46                 print "only mp4 remaining: $_\n";
47                 foreach my $exp (@existing_exps_with_log) {
48                         system "mv '$recording/$_$exp' '$recording/log/$_$exp'\n";
49                 }
50         }
51 }
52