Added a check for the config file
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Gregory Ballantine 2022-05-01 23:02:31 -04:00
parent 3742c44c40
commit ffb7d2d9f1
3 changed files with 16 additions and 5 deletions

View File

@ -9,9 +9,11 @@ import tech.bitgoblin.video.Transcoder;
*/ */
public class App { public class App {
private static final String configFile = "~/.config/dragoon.toml";
public static void main(String[] args) { public static void main(String[] args) {
// read our config file // read our config file
Config c = new Config("~/dragoon/config.toml"); Config c = new Config(configFile);
// create new Transcoder object and start the service // create new Transcoder object and start the service
//Transcoder t = new Transcoder("~/dragoon"); //Transcoder t = new Transcoder("~/dragoon");
//t.transcode(); //t.transcode();

View File

@ -1,5 +1,6 @@
package tech.bitgoblin.config; package tech.bitgoblin.config;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
@ -17,13 +18,18 @@ public class Config {
// parse config file // parse config file
try { try {
this.parseConfig(); this.parseConfig();
String value = result.getString("repo"); String value = this.result.getString("repo");
System.out.println(value); System.out.println(value);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); System.out.println("Unable to read config file; please check that " + this.configPath + " is available.");
System.exit(1);
} }
} }
public String getString(String key) {
return this.result.getString(key);
}
private void parseConfig() throws IOException { private void parseConfig() throws IOException {
// parse config file // parse config file
Path source = Paths.get(this.configPath); Path source = Paths.get(this.configPath);

View File

@ -12,16 +12,19 @@ import java.nio.file.Paths;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import tech.bitgoblin.config.Config;
import tech.bitgoblin.io.IOUtils; import tech.bitgoblin.io.IOUtils;
public class Transcoder { public class Transcoder {
private String repo_dir; private String repo_dir;
private Config config;
private String ffmpeg_path = "/usr/bin/ffmpeg"; private String ffmpeg_path = "/usr/bin/ffmpeg";
// only define the working directory; use default FFMPEG path // only define the working directory; use default FFMPEG path
public Transcoder(String repo_dir) { public Transcoder(Config config) {
this.repo_dir = IOUtils.resolveTilda(repo_dir); this.config = config;
this.repo_dir = IOUtils.resolveTilda(config.getString("transcoder.repo_path"));
this.initDirectory(); this.initDirectory();
} }
// define a custom FFMPEG binary path // define a custom FFMPEG binary path