2 # Author: Alan J. Pippin
3 # Description: Find videos from a watched dir and move them to the video processing destination directory
12 ####################################################################################################
13 # Configuration parameters
14 $mydir = `cd \$(dirname $0) 2>/dev/null; pwd`; chomp($mydir); unshift @INC,("$mydir");
15 # Default configuration values
16 require "organize_videos.conf";
17 # Override defaults with local customizations
18 if( -f "$mydir/organize_videos.conf.local") { require "organize_videos.conf.local"; }
20 ####################################################################################################
23 if(! -d $srcpathname) { print "-E- Can't find srcpath: $srcpathname\n"; exit 1; }
24 if(! -d $watchpathname) { print "-E- Can't find watchpath: $watchpathname\n"; exit 1; }
29 print "usage: $0 [-v] [-t]\n";
30 print " -v verbose; print file being moved (to).\n";
31 print " -f force it to run by ignoring the \$minage setting in organize_videos.conf\n";
32 print " -t test; print what will happen, but don't do anything\n";
36 # Sanity checks / Option processing
37 if(defined $opt_h) { usage(); exit 1; }
39 # Our srcpathname is actually our dstpathname
40 $find_changed_cmd =~ s/$srcpathname/$watchpathname/g;
41 $find_cmd_with_mkv =~ s/$srcpathname/$watchpathname/g;
42 $dstpathname = $srcpathname;
43 $srcpathname = $watchpathname;
45 # Only proceed if no files have changed in the past $cmin minutes
46 $changed_files_found=`$find_changed_cmd`;
47 if(!$opt_f && $changed_files_found) { exit 0; }
49 # Only proceed if there are video files to organize
50 $video_files_found=`$find_cmd_with_mkv`;
51 if(!$video_files_found) { exit 0; }
53 # Only one instance of this script running at a time
54 my $pidfile = File::Pid->new({file => "$pid_file", pid => "$$"});
55 print "pid_file: $pid_file\n" if($opt_v);
56 exit if $pidfile->running();
62 # Merge videos prior to copying them over to the destination path
65 # Move the videos over to the destination path
67 print "$video_files_found\n" if($opt_v);
68 foreach $file (`$find_cmd_with_mkv`) {
71 $srcdir = dirname($file);
72 $file = basename($file);
74 $dstfile = "$dstpathname/$file";
76 # only move files that have been organized
77 if($srcfile !~ /\d\d\d\d-\d\d-\d\d/) { next; }
79 print "-> Moving \"$srcdir/$srcfile\" to \"$dstfile\"\n";
82 # Make sure the dstfile doesn't exist, if it does, don't do the move
84 $errno=system("mv \"$srcdir/$srcfile\" \"$dstfile\" 2>/dev/null");
85 if($errno) { print "-E- Error moving srcfile to dstfile: $srcdir/$srcfile -> $dstfile\n"; next; }
87 print "-> Skipping \"$srcdir/$srcfile\". Destfile \"$dstfile\" already exists.\n";
90 system("chown $owner \"$dstfile\"");
91 system("chgrp $group \"$dstfile\"");
92 system("chmod $mode \"$dstfile\"");