Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
b049581632 | |||
5bde5bfee0 | |||
347211d566 | |||
204a5e15f1 |
@ -1,4 +1,9 @@
|
|||||||
pipeline:
|
pipeline:
|
||||||
|
test:
|
||||||
|
image: maven:3-jdk-11
|
||||||
|
commands:
|
||||||
|
- mvn test
|
||||||
|
|
||||||
build:
|
build:
|
||||||
image: maven:3-jdk-11
|
image: maven:3-jdk-11
|
||||||
commands:
|
commands:
|
||||||
|
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>tech.bitgoblin</groupId>
|
<groupId>tech.bitgoblin</groupId>
|
||||||
<artifactId>Dragoon</artifactId>
|
<artifactId>Dragoon</artifactId>
|
||||||
<version>0.1.1</version>
|
<version>0.2.0</version>
|
||||||
|
|
||||||
<name>Dragoon</name>
|
<name>Dragoon</name>
|
||||||
<url>https://www.bitgoblin.tech</url>
|
<url>https://www.bitgoblin.tech</url>
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package tech.bitgoblin;
|
package tech.bitgoblin;
|
||||||
|
|
||||||
import tech.bitgoblin.config.Config;
|
import tech.bitgoblin.config.Config;
|
||||||
import tech.bitgoblin.video.Transcoder;
|
import tech.bitgoblin.transcoder.RunTranscoderTask;
|
||||||
|
import tech.bitgoblin.transcoder.Transcoder;
|
||||||
|
|
||||||
|
import java.util.Timer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Bit Goblin video transcoder service.
|
* The Bit Goblin video transcoder service.
|
||||||
@ -16,7 +19,8 @@ public class App {
|
|||||||
Config c = new Config(configFile);
|
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(c);
|
Transcoder t = new Transcoder(c);
|
||||||
t.transcode();
|
Timer timer = new Timer();
|
||||||
|
timer.scheduleAtFixedRate(new RunTranscoderTask(t), 2500, 120 * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,8 @@ 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;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.tomlj.Toml;
|
import org.tomlj.Toml;
|
||||||
import org.tomlj.TomlParseResult;
|
import org.tomlj.TomlParseResult;
|
||||||
import tech.bitgoblin.io.IOUtils;
|
import tech.bitgoblin.io.IOUtils;
|
||||||
@ -28,6 +30,10 @@ public class Config {
|
|||||||
return this.result.getString(key);
|
return this.result.getString(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getInt(String key) {
|
||||||
|
return Objects.requireNonNull(this.result.getDouble(key)).intValue();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean contains(String key) {
|
public boolean contains(String key) {
|
||||||
return this.result.contains(key);
|
return this.result.contains(key);
|
||||||
}
|
}
|
||||||
|
@ -14,9 +14,9 @@ public class IOUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String resolveTilda(String path) {
|
public static String resolveTilda(String path) {
|
||||||
if (path.startsWith("~" + File.separator)) {
|
if (path.startsWith("~" + File.separator) || path.equals("~")) {
|
||||||
path = System.getProperty("user.home") + path.substring(1);
|
path = System.getProperty("user.home") + path.substring(1);
|
||||||
} else if (path.startsWith("~")) {
|
} else if ((!path.equals("~")) && path.startsWith("~")) {
|
||||||
// here you can implement reading homedir of other users if you care
|
// here you can implement reading homedir of other users if you care
|
||||||
throw new UnsupportedOperationException("Home dir expansion not implemented for explicit usernames");
|
throw new UnsupportedOperationException("Home dir expansion not implemented for explicit usernames");
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
package tech.bitgoblin.transcoder;
|
||||||
|
|
||||||
|
import java.util.TimerTask;
|
||||||
|
|
||||||
|
public class RunTranscoderTask extends TimerTask {
|
||||||
|
|
||||||
|
private Transcoder transcoder;
|
||||||
|
|
||||||
|
public RunTranscoderTask(Transcoder t) {
|
||||||
|
this.transcoder = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
// archive the files
|
||||||
|
transcoder.archive();
|
||||||
|
// run the transcoder
|
||||||
|
transcoder.transcode();
|
||||||
|
// clean up ingest
|
||||||
|
transcoder.cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,16 +1,14 @@
|
|||||||
package tech.bitgoblin.video;
|
package tech.bitgoblin.transcoder;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.InterruptedException;
|
import java.lang.InterruptedException;
|
||||||
import java.lang.Process;
|
import java.lang.Process;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.function.Consumer;
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.Timer;
|
||||||
|
|
||||||
import tech.bitgoblin.config.Config;
|
import tech.bitgoblin.config.Config;
|
||||||
import tech.bitgoblin.io.IOUtils;
|
import tech.bitgoblin.io.IOUtils;
|
||||||
@ -31,6 +29,12 @@ public class Transcoder {
|
|||||||
this.initDirectory();
|
this.initDirectory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// create a periodic timer task and start it
|
||||||
|
public void start() {
|
||||||
|
Timer timer = new Timer();
|
||||||
|
timer.scheduleAtFixedRate(new RunTranscoderTask(this), 10000, this.config.getInt("transcoder.interval") * 60 * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
// transcode files in the working directory
|
// transcode files in the working directory
|
||||||
public void transcode() {
|
public void transcode() {
|
||||||
// search for files
|
// search for files
|
||||||
@ -38,6 +42,11 @@ public class Transcoder {
|
|||||||
File repo = new File(Paths.get(this.repo_dir, "ingest").toString());
|
File repo = new File(Paths.get(this.repo_dir, "ingest").toString());
|
||||||
File[] sourceFiles = repo.listFiles();
|
File[] sourceFiles = repo.listFiles();
|
||||||
|
|
||||||
|
if (sourceFiles.length == 0) {
|
||||||
|
System.out.println("There is nothing to transcode in " + this.repo_dir + "/ingest.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// transcode
|
// transcode
|
||||||
System.out.println("Transcoding files in " + this.repo_dir + "/ingest...");
|
System.out.println("Transcoding files in " + this.repo_dir + "/ingest...");
|
||||||
for (File f : sourceFiles) {
|
for (File f : sourceFiles) {
|
||||||
@ -74,6 +83,34 @@ public class Transcoder {
|
|||||||
System.out.println();
|
System.out.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// copies sources files to the archive directory
|
||||||
|
public void archive() {
|
||||||
|
File repo = new File(Paths.get(this.repo_dir, "ingest").toString());
|
||||||
|
File[] sourceFiles = repo.listFiles();
|
||||||
|
|
||||||
|
for (File f : sourceFiles) {
|
||||||
|
Path filePath = Path.of(f.toString());
|
||||||
|
String filename = filePath.getFileName().toString();
|
||||||
|
String archivePath = Paths.get(this.repo_dir, "archive", filename).toString();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Files.copy(filePath, Paths.get(archivePath), StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// clean up the ingest directory once we're done
|
||||||
|
public void cleanup() {
|
||||||
|
File repo = new File(Paths.get(this.repo_dir, "ingest").toString());
|
||||||
|
File[] sourceFiles = repo.listFiles();
|
||||||
|
|
||||||
|
for (File f : sourceFiles) {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ensures the transcoder's working directory is available
|
// ensures the transcoder's working directory is available
|
||||||
private void initDirectory() {
|
private void initDirectory() {
|
||||||
// create transcoder directory
|
// create transcoder directory
|
36
src/test/java/tech/bitgoblin/io/IOUtilsTest.java
Normal file
36
src/test/java/tech/bitgoblin/io/IOUtilsTest.java
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package tech.bitgoblin.io;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class IOUtilsTest {
|
||||||
|
|
||||||
|
private static String testDir = "test-temp";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldCreateDirectory() {
|
||||||
|
IOUtils.createDirectory(testDir);
|
||||||
|
assertTrue(new File(testDir).exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldExpandTilda() {
|
||||||
|
String homeExpanded = IOUtils.resolveTilda("~");
|
||||||
|
assertTrue(!homeExpanded.equals("~"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected=UnsupportedOperationException.class)
|
||||||
|
public void shouldFailExpandExplicitTilda() {
|
||||||
|
IOUtils.resolveTilda("~test");
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void cleanup() {
|
||||||
|
new File(testDir).delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user