2 # Author: Alan J. Pippin
3 # Description: Find videos from a watched dir and copy 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 copied (to).\n";
31 print " -t test; print what will happen, but don't do anything\n";
35 # Sanity checks / Option processing
36 if(defined $opt_h) { usage(); exit 1; }
38 # Our srcpathname is actually our dstpathname
39 $dstpathname = $srcpathname;
40 $srcpathname = $watchpathname;
42 # Only proceed if there are video files to organize
43 $video_files_found=`find \"$srcpathname/\" $movie_file_ext -o -iregex \".*\.mkv\"`;
44 if(!$video_files_found) { exit 0; }
46 # Only one instance of this script running at a time
47 my $pidfile = File::Pid->new({file => "$pid_file", pid => "$$"});
48 exit if $pidfile->running();
54 # Merge videos prior to copying them over to the destination path
57 # Copy the videos over to the destination path
59 print "$video_files_found\n" if($opt_v);
60 foreach $file (`find \"$srcpathname/\" $movie_file_ext -o -iregex \".*\.mkv\"`) {
63 $srcdir = dirname($file);
64 $file = basename($file);
66 $dstfile = "$dstpathname/$file";
68 print "-> Copying \"$srcdir/$srcfile\" to \"$dstfile\"\n";
71 # Make sure the dstfile doesn't exist, if it does, don't do the copy
73 $errno=system("cp -p \"$srcdir/$srcfile\" \"$dstfile\" 2>/dev/null");
74 if($errno) { print "-E- Error copying srcfile to dstfile: $srcdir/$srcfile -> $dstfile\n"; next; }
76 print "-> Skipping \"$srcdir/$srcfile\". Destfile \"$dstfile\" already exists.\n";
79 system("chown $owner \"$dstfile\"");
80 system("chgrp $group \"$dstfile\"");
81 system("chmod $mode \"$dstfile\"");