Properly fixes conversion of files with filenames containing square brackets
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				KnarCraft/FFmpegConvert/pipeline/head This commit looks good
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	KnarCraft/FFmpegConvert/pipeline/head This commit looks good
				
			Unknown whether this breaks conversion of filenames containing semicolons or apostrophes
This commit is contained in:
		@@ -50,7 +50,8 @@ public class AnimeConverter extends Converter {
 | 
			
		||||
        if (streams.isEmpty()) {
 | 
			
		||||
            throw new IllegalArgumentException("The file has no valid streams. Please make sure the file exists and is not corrupt.");
 | 
			
		||||
        }
 | 
			
		||||
        String newPath = fileCollisionPrevention(folder.getAbsolutePath() + File.separator + stripExtension(file) + ".mp4", "mp4");
 | 
			
		||||
        String newPath = fileCollisionPrevention(folder.getAbsolutePath() + File.separator +
 | 
			
		||||
                stripExtension(file) + ".mp4", "mp4");
 | 
			
		||||
        printl("Preparing to start process...");
 | 
			
		||||
        String[] command = builderCommand(ffmpegPath, file.getName(), streams, newPath);
 | 
			
		||||
        ProcessBuilder processBuilder = new ProcessBuilder(command);
 | 
			
		||||
@@ -108,17 +109,20 @@ public class AnimeConverter extends Converter {
 | 
			
		||||
 | 
			
		||||
        if (subtitleStream != null && subtitleStream.getIsImageSubtitle()) {
 | 
			
		||||
            command.add("-filter_complex");
 | 
			
		||||
            command.add("[0:v:" + videoStream.getAbsoluteIndex() + "][0:" + subtitleStream.getAbsoluteIndex() + "]overlay");
 | 
			
		||||
            String filter = String.format("[0:v:%d][0:%d]overlay", videoStream.getAbsoluteIndex(),
 | 
			
		||||
                    subtitleStream.getAbsoluteIndex());
 | 
			
		||||
            command.add(filter);
 | 
			
		||||
        } else if (subtitleStream != null) {
 | 
			
		||||
            command.add("-map");
 | 
			
		||||
            command.add("0:" + videoStream.getAbsoluteIndex());
 | 
			
		||||
            command.add(String.format("0:%d", videoStream.getAbsoluteIndex()));
 | 
			
		||||
            command.add("-vf");
 | 
			
		||||
            String safeFileName = escapeSpecialCharactersInFileName(fileName);
 | 
			
		||||
            String subtitleCommand = String.format("subtitles=\"%s\"", safeFileName);
 | 
			
		||||
            String subtitleCommand = String.format("subtitles='%s':si=%d", safeFileName, 
 | 
			
		||||
                    subtitleStream.getRelativeIndex());
 | 
			
		||||
            command.add(subtitleCommand);
 | 
			
		||||
        } else {
 | 
			
		||||
            command.add("-map");
 | 
			
		||||
            command.add("0:" + videoStream.getAbsoluteIndex());
 | 
			
		||||
            command.add(String.format("0:%d", videoStream.getAbsoluteIndex()));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        command.add(outFile);
 | 
			
		||||
 
 | 
			
		||||
@@ -427,9 +427,9 @@ public abstract class Converter {
 | 
			
		||||
    static String escapeSpecialCharactersInFileName(String fileName) {
 | 
			
		||||
        return fileName.replace("'", "\\\\\\'")
 | 
			
		||||
                .replace(",", "\\\\\\,")
 | 
			
		||||
                .replace(";", "\\\\\\;");
 | 
			
		||||
                /*.replace("]", "\\]") //Not sure whether these should be escaped or not
 | 
			
		||||
                .replace("[", "\\[");*/
 | 
			
		||||
                .replace(";", "\\\\\\;")
 | 
			
		||||
                .replace("]", "\\]")
 | 
			
		||||
                .replace("[", "\\[");
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    static void print(String input) throws IOException {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user