- # 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
-my $last_dstnum = 0;
-my $changed_dst = 0;
-foreach $ext (sort keys %videos) {
- #print "checking: $ext\n";
- foreach $video (sort keys %{$videos{$ext}}) {
- #print "checking: $ext $video\n";
- # Make sure this video name is not in use as a destination for any other ext
- foreach $checkext (sort keys %videos) {
- #print "checking: $ext $video $checkext\n";
- if($checkext eq $ext) { next; }
- foreach $checkvideo (sort keys %{$videos{$checkext}}) {
- #print "checking: $ext $video $checkext $checkvideo\n";
- if("$video" eq "$checkvideo") {
- if($video =~ /(.*?)\.(\d+)\.(\w+)$/) {
- $dstfile = $1;
- $dstnum = $2;
- $dstext = $3;
- }
- foreach $i ($last_dstnum .. '999') {
- $last_dstnum = $i + 1;
- $newfile = $dstfile . "." . sprintf("%03d",$i);
- if("$video" ne "$newfile.$dstext") { last; }
- }
- $videos{$ext}{"$newfile.$dstext"} = $videos{$ext}{$video};
- #print "for ext $ext changed destination to: $newfile.$dstext: $videos{$ext}{$video};\n";
- delete $videos{$ext}{$video};
- $changed_dst = 1;
- last;
- }
- }
- if($changed_dst) { last; }
- }
- if($changed_dst) { last; }
- }
- $changed_dst = 0;