Adds a video downscaler
All checks were successful
KnarCraft/FFmpegConvert/pipeline/head This commit looks good

This commit is contained in:
2024-03-15 01:20:26 +01:00
parent 346a5e0606
commit 6c614b2f17
4 changed files with 127 additions and 21 deletions

View File

@ -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('.'));
}
}