-
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathPathLocator.java
More file actions
49 lines (39 loc) · 1.36 KB
/
PathLocator.java
File metadata and controls
49 lines (39 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.github.stickerifier.stickerify.process;
import com.github.stickerifier.stickerify.exception.ProcessException;
import org.slf4j.LoggerFactory;
import ws.schild.jave.process.ProcessLocator;
import ws.schild.jave.process.ProcessWrapper;
import ws.schild.jave.process.ffmpeg.FFMPEGProcess;
import java.util.Objects;
/**
* Custom locator class to be used by Jave to find the path where FFmpeg is installed at in the system.
*
* @see ProcessLocator
*/
public enum PathLocator implements ProcessLocator {
INSTANCE;
private final String ffmpegLocation;
PathLocator() {
var logger = LoggerFactory.getLogger(PathLocator.class);
var ffmpegLocation = System.getenv("FFMPEG_PATH");
try {
if (ffmpegLocation == null || ffmpegLocation.isBlank()) {
ffmpegLocation = ProcessHelper.executeCommand(OsConstants.FIND_EXECUTABLE, "ffmpeg").getFirst();
}
logger.atInfo().log("FFmpeg is installed at {}", ffmpegLocation);
} catch (ProcessException e) {
logger.atError().setCause(e).log("Unable to detect FFmpeg's installation path");
} catch (InterruptedException _) {
Thread.currentThread().interrupt();
}
this.ffmpegLocation = Objects.requireNonNull(ffmpegLocation);
}
@Override
public String getExecutablePath() {
return ffmpegLocation;
}
@Override
public ProcessWrapper createExecutor() {
return new FFMPEGProcess(ffmpegLocation);
}
}