Added some required binary checks. Added save originals functionality.
[videoscripts/.git] / merge_videos_by_day
index 6e7998cd147db91ea96fefffe6a84716193b1365..e164bee42d08f452c22076478943caa52fdbb35e 100755 (executable)
@@ -94,7 +94,7 @@ foreach $file (sort `$find_cmd`) {
     $date_taken = ctime(stat("$srcdir/$srcfile")->mtime);
 
     # Get the date taken from the filename
-    if($srcfile =~ /^(\d+)-(\d+)-(\d+)/) {
+    if(!$merge_by_modification_date && $srcfile =~ /^(\d+)-(\d+)-(\d+)/) {
        $year = $1;
        $month = $2;
        $day = sprintf("%02d",$3);
@@ -194,7 +194,16 @@ foreach $ext (sort keys %videos) {
            print "$cmd\n";
            if(!defined $opt_k) { 
                foreach $video (@{$videos{$ext}{$video}}) {
-                   print("rm -f $video\n");
+                   if($save_originals) {
+                       print "-> Saving the original video $video\n";
+                       if($video =~ /\.$originals_file_ext/) {
+                           print("mv $video \"$origpathname/".basename(dirname($video))."_".basename($video)."\n");
+                           $video = "";
+                       }
+                   }
+                   if(-e $video) { 
+                       print("rm -f $video\n");
+                   }
                }
            }
        } else {
@@ -210,7 +219,16 @@ foreach $ext (sort keys %videos) {
            # Remove the individual video files
            if(!defined $opt_k) { 
                foreach $srcvideo (@{$videos{$ext}{$video}}) {
-                   system("rm -f $srcvideo");
+                   if($save_originals) {
+                       print "-> Saving the original video $srcvideo to $origpathname\n";
+                       if($srcvideo =~ /\.$originals_file_ext/) {
+                           system("mv $srcvideo \"$origpathname/".basename(dirname($srcvideo))."_".basename($srcvideo));
+                           $srcvideo = "";
+                       }
+                   }
+                   if(-e $srcvideo) { 
+                       system("rm -f $srcvideo");
+                   }
                }
            }
        }