- # Check for duplicate filenames at the destination
- $newfile = $dstfile . "." . $video_suffix;
- if(-e "$newfile.$ext") {
- foreach $i ($video_suffix+1 .. '999') {
- $newfile = $dstfile . "." . sprintf("%03d",$i);
- if(! -e "$newfile.$ext") { last; }
- }
- $dstfile = $newfile;
- }
-
- # Set the name of our unique destination file
- $dstfile = "$newfile.$ext";
-
- # You can only merge videos into a single destination that have the same extension/type
- push(@{$videos{"$srcext"}{"$dstfile"}}, "\"$srcdir/$srcfile\"");
-}
-
-# 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};
- }
- }
- }
- }