+ # Our srcpathname is actually our dstpathname
+ $new_find_changed_cmd = $find_changed_cmd;
+ $new_find_cmd_with_mkv = $find_cmd_with_mkv;
+ $new_find_changed_cmd =~ s/$srcpathname/$watchpath/g;
+ $new_find_cmd_with_mkv =~ s/$srcpathname/$watchpath/g;
+ $dstpathname = $srcpathname;
+
+ # Only proceed if no files have changed in the past $cmin minutes
+ $changed_files_found=`$new_find_changed_cmd`;
+ print "finding videos: $new_find_changed_cmd\n" if($opt_v);
+ if(!$opt_f && $changed_files_found) { next; }
+
+ # Only proceed if there are video files to organize
+ $video_files_found=`$new_find_cmd_with_mkv`;
+ print "finding videos: $new_find_cmd_with_mkv\n" if($opt_v);
+ if(!$video_files_found) { next; }
+
+ # Print the date
+ system("date");
+ my $errno = 0;
+
+ # Move the videos over to the destination path
+ chdir "$watchpath";
+ print "found: $video_files_found\n" if($opt_v);
+ foreach $file (`$new_find_cmd_with_mkv`) {
+
+ chomp($file);
+ $srcdir = dirname($file);
+ $file = basename($file);
+ $srcfile = $file;
+ $dstfile = "$dstpathname/$file";
+
+ # Make sure srcdir is group writable
+ if(not -w "$srcdir") {
+ print "-W- srcdir is not group writable, can't move videos out of it: $srcdir\n";
+ next;
+ }
+
+ # Make sure we have a unique dstfile
+ if($overwrite_dest == 0 && -f "$dstfile") {
+ $video_ext = $srcfile;
+ $video_ext =~ s/.*\.(\S+)$/$1/;
+ $suffix = 0;
+ $newdstfile_base = $dstfile;
+ $newdstfile_base =~ s/\.[^.]*$//;
+ do {
+ $newdstfile = "${newdstfile_base}_${suffix}.${video_ext}";
+ $suffix++;
+ } while(-f "$newdstfile");
+ $dstfile = $newdstfile;
+ }
+
+ print "-> Moving \"$srcdir/$srcfile\" to \"$dstfile\"\n";