Major changes to support interlaced/progressive content
[videoscripts/.git] / organize_videos
index d0c74586769bab09fd28677dd4187048db80d51d..e8b02db03b4cc8a213912178f0d829e559be1985 100755 (executable)
@@ -14,13 +14,15 @@ use File::Pid;
 my $srcpathname = "/naspool/pictures/New Photos"; # Path to look for videos to move from
 my $dstpathname = "/naspool/videos/HomeVideos"; # Path to move the videos to
 my $merge_videos_by_day = "/naspool/videos/bin/merge_videos_by_day";
-my $minage = "+10"; # File creation dates must be older than X minutes to move
+my $minage = "+0"; # Video file creation dates must not have changed in the last X minutes to process any of the video files
 my $owner = "ajp"; # The owner of the files after they are moved
 my $group = "pip"; # The group of the files after they are moved
 my $mode = "664"; # The mode to set on each file after they are moved
 my $playlist_extension = "pls"; # The extension to use when creating playlist files
 my $video_suffix = "000"; # What number to start with when adding an incrementing suffix to the end of the final video clip to avoid name collisions
-my $find_cmd = "find \"$srcpathname/\" -cmin $minage -a \\( -iregex \".*\.mov\" -o -iregex \".*\.3gp\" -o -iregex \".*\.mp4\" -o -iregex \".*\.mts\" -o -iregex \".*\.mkv\" \\)";
+my $movie_file_ext = "-iregex \".*\.mov\" -o -iregex \".*\.3gp\" -o -iregex \".*\.mp4\" -o -iregex \".*\.mts\" -o -iregex \".*\.mkv\"";
+my $find_changed_cmd = "find  \"$srcpathname/\" -not -cmin $minage -a \\( $movie_file_ext \\)";
+my $find_cmd = "find \"$srcpathname/\" $movie_file_ext";
 ####################################################################################################
 
 # Sanity check
@@ -123,6 +125,10 @@ if(defined $opt_p) {
 $video_files_found=`$find_cmd`;
 if(!$video_files_found) { exit 0; }
 
+# Only proceed if no files have changed in the past $cmin minutes
+$changed_files_found=`$find_changed_cmd`;
+if($changed_files_found) { exit 0; }
+
 # Only one instance of this script running at a time
 my $pidfile = File::Pid->new({file => "/tmp/organize_videos.pid"});
 exit if $pidfile->running();
@@ -136,8 +142,8 @@ my $errno = 0;
 my $merge_opts = "";
 if(defined $opt_t) { $merge_opts .= "-t "; }
 if(defined $opt_r) { $merge_opts .= "-r "; }
-$errno=system("$merge_videos_by_day -s \"$srcpathname\" $merge_opts");
-if($errno > 0) { $errno = $errno - 255; }
+$errno=system("$merge_videos_by_day -q -s \"$srcpathname\" $merge_opts");
+$errno = $errno >> 8;
 if($errno) { die "-E- $merge_videos_by_day encountered some errors with exit code $errno\n"; }
 
 # Copy the videos over to the destination path
@@ -224,7 +230,8 @@ foreach $file (`$find_cmd`) {
          if(! defined $opt_t) { 
              $tmpdir=`tempfile`;
              system("rm $tmpdir");
-             system("mv \"$srcdir\" $tmpdir > /dev/null 2>/dev/null");
+             system("cp -R \"$srcdir\" $tmpdir > /dev/null 2>/dev/null");
+             system("rm -rf \"$srcdir\"");
              print "-> Moved empty subdir $srcdir to $tmpdir\n" if($opt_v);
          }
       }