-# Tell the user which videos we are going to merge
-foreach $video (sort keys %videos) {
- # Only merge the videos if there is more than 1
- my $num_videos = $#{$videos{$video}} + 1;
- if($num_videos <= 1) { next; }
+# Only merge the videos if there is more than 1 video to merge on a given day for a given ext
+foreach $ext (sort keys %videos) {
+ foreach $video (sort keys %{$videos{$ext}}) {
+ my $num_videos = $#{$videos{$ext}{$video}} + 1;
+ if($num_videos <= 1) {
+ delete $videos{$ext}{$video};
+ next;
+ }
+ }
+}
+
+# Check for duplicate filenames in the dstfiles being created for other exts
+foreach $ext (sort keys %videos) {
+ foreach $video (sort keys %{$videos{$ext}}) {
+ # Make sure this video name is not in use as a destination for any other ext
+ foreach $checkext (sort keys %videos) {
+ if($checkext eq $ext) { next; }
+ foreach $checkvideo (sort keys %{$videos{$checkext}}) {
+ if("$video" eq "$checkvideo") {
+ if($video =~ /(.*?)\.(\d+)\.(\w+)$/) {
+ $dstfile = $1;
+ $dstnum = $2;
+ $dstext = $3;
+ }
+ foreach $i ($dstnum .. '999') {
+ $newfile = $dstfile . "." . sprintf("%03d",$i);
+ if("$video" ne "$newfile.$dstext") { last; }
+ }
+ $videos{$ext}{"$newfile.$dstext"} = $videos{$ext}{$video};
+ delete $videos{$ext}{$video};
+ }
+ }
+ }
+ }
+}