Adds a video downscaler
All checks were successful
KnarCraft/FFmpegConvert/pipeline/head This commit looks good
All checks were successful
KnarCraft/FFmpegConvert/pipeline/head This commit looks good
This commit is contained in:
@ -25,17 +25,7 @@ public final class FileUtil {
|
||||
*/
|
||||
public static String getNonCollidingPath(File folder, File file, String outExtension) {
|
||||
return FileUtil.getNonCollidingFilename(folder.getAbsolutePath() + File.separator +
|
||||
FileUtil.stripExtension(file) + "." + outExtension, outExtension);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the extension from a file name
|
||||
*
|
||||
* @param file <p>A filename.</p>
|
||||
* @return <p>A filename without its extension.</p>
|
||||
*/
|
||||
static String stripExtension(String file) {
|
||||
return file.substring(0, file.lastIndexOf('.'));
|
||||
FileUtil.stripExtension(file.getName()) + "." + outExtension, outExtension);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -117,7 +107,7 @@ public final class FileUtil {
|
||||
*/
|
||||
private static String getNonCollidingFilename(String targetPath, String extension) {
|
||||
File newFile = new File(targetPath);
|
||||
String fileName = stripExtension(targetPath);
|
||||
String fileName = stripExtension(targetPath).replaceAll("\\([0-9]+\\)$", "");
|
||||
int i = 1;
|
||||
while (newFile.exists()) {
|
||||
newFile = new File(fileName + "(" + i++ + ")" + "." + extension);
|
||||
@ -126,13 +116,27 @@ public final class FileUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets filename without extension from File object
|
||||
* Gets the extension of the given filename
|
||||
*
|
||||
* @param file <p>A file object.</p>
|
||||
* @return <p>A filename.</p>
|
||||
* @param file <p>The filename to check</p>
|
||||
* @return <p>The file's extension</p>
|
||||
*/
|
||||
private static String stripExtension(File file) {
|
||||
return file.getName().substring(0, file.getName().lastIndexOf('.'));
|
||||
public static String getExtension(String file) {
|
||||
if (file.contains(".")) {
|
||||
return file.substring(file.lastIndexOf('.') + 1);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the extension from a file name
|
||||
*
|
||||
* @param file <p>A filename.</p>
|
||||
* @return <p>A filename without its extension.</p>
|
||||
*/
|
||||
public static String stripExtension(String file) {
|
||||
return file.substring(0, file.lastIndexOf('.'));
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user