Can playback video with controls, need to fix performance and reducing window size
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package com.github.gtache.autosubtitle.impl;
|
||||
|
||||
/**
|
||||
* The list of possible operating systems
|
||||
*/
|
||||
public enum Architecture {
|
||||
I386, I486, I586, I686, PPC, POWERPC, X86, X86_32, X86_64, AMD64, ARM, ARM32, ARM64, AARCH64, UNKNOWN;
|
||||
|
||||
public static Architecture getArchitecture(final String name) {
|
||||
try {
|
||||
return valueOf(name.toUpperCase());
|
||||
} catch (final IllegalArgumentException e) {
|
||||
return UNKNOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.github.gtache.autosubtitle.impl;
|
||||
|
||||
/**
|
||||
* The list of possible operating systems
|
||||
*/
|
||||
public enum OS {
|
||||
WINDOWS, LINUX, MAC
|
||||
}
|
||||
@@ -7,10 +7,19 @@ import java.util.Objects;
|
||||
/**
|
||||
* Implementation of {@link VideoInfo}
|
||||
*/
|
||||
public record VideoInfoImpl(String videoFormat) implements VideoInfo {
|
||||
public record VideoInfoImpl(String videoFormat, int width, int height, long duration) implements VideoInfo {
|
||||
|
||||
public VideoInfoImpl {
|
||||
Objects.requireNonNull(videoFormat);
|
||||
if (width <= 0) {
|
||||
throw new IllegalArgumentException("Width must be greater than 0 : " + width);
|
||||
}
|
||||
if (height <= 0) {
|
||||
throw new IllegalArgumentException("Height must be greater than 0 : " + height);
|
||||
}
|
||||
if (duration <= 0) {
|
||||
throw new IllegalArgumentException("Duration must be greater than 0 : " + duration);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.github.gtache.autosubtitle.modules.impl;
|
||||
|
||||
import com.github.gtache.autosubtitle.impl.Architecture;
|
||||
import com.github.gtache.autosubtitle.impl.OS;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
@Module
|
||||
public abstract class CoreModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
static OS providesOS() {
|
||||
final var name = System.getProperty("os.name");
|
||||
if (name.contains("Windows")) {
|
||||
return OS.WINDOWS;
|
||||
} else if (name.contains("Mac")) {
|
||||
return OS.MAC;
|
||||
} else {
|
||||
return OS.LINUX;
|
||||
}
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
static Architecture providesArchitecture() {
|
||||
final var arch = System.getProperty("os.arch");
|
||||
return Architecture.getArchitecture(arch);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@ExecutableExtension
|
||||
static String providesExecutableExtension(final OS os) {
|
||||
return os == OS.WINDOWS ? ".exe" : "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.github.gtache.autosubtitle.modules.impl;
|
||||
|
||||
import javax.inject.Qualifier;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
@Qualifier
|
||||
@Documented
|
||||
@Retention(RUNTIME)
|
||||
@Target({ElementType.PARAMETER, ElementType.METHOD, ElementType.FIELD})
|
||||
public @interface ExecutableExtension {
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
@@ -24,25 +25,28 @@ public abstract class AbstractProcessRunner implements ProcessRunner {
|
||||
@Override
|
||||
public ProcessResult run(final List<String> args) throws IOException {
|
||||
final var builder = new ProcessBuilder(args);
|
||||
builder.inheritIO();
|
||||
builder.redirectErrorStream(true);
|
||||
final var process = builder.start();
|
||||
final var output = new ArrayList<String>();
|
||||
new Thread(() -> {
|
||||
final var readFuture = CompletableFuture.supplyAsync(() -> {
|
||||
final var output = new ArrayList<String>();
|
||||
try (final var in = new BufferedReader(new InputStreamReader(new BufferedInputStream(process.getInputStream()), StandardCharsets.UTF_8))) {
|
||||
while (in.ready()) {
|
||||
output.add(in.readLine());
|
||||
var line = in.readLine();
|
||||
while (line != null) {
|
||||
output.add(line);
|
||||
line = in.readLine();
|
||||
}
|
||||
} catch (final IOException e) {
|
||||
logger.error("Error listening to process output of {}", args, e);
|
||||
}
|
||||
}).start();
|
||||
return output;
|
||||
});
|
||||
try {
|
||||
process.waitFor(1, TimeUnit.HOURS);
|
||||
} catch (final InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
process.destroy();
|
||||
}
|
||||
final var output = readFuture.join();
|
||||
return new ProcessResultImpl(process.exitValue(), output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,6 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
@Qualifier
|
||||
@Documented
|
||||
@Retention(RUNTIME)
|
||||
@Target({ElementType.TYPE_USE, ElementType.METHOD, ElementType.FIELD})
|
||||
public @interface VideoConverter {
|
||||
@Target({ElementType.PARAMETER, ElementType.METHOD, ElementType.FIELD})
|
||||
public @interface SubtitleExtractorSetup {
|
||||
}
|
||||
@@ -11,6 +11,6 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
@Qualifier
|
||||
@Documented
|
||||
@Retention(RUNTIME)
|
||||
@Target({ElementType.TYPE_USE, ElementType.METHOD, ElementType.FIELD})
|
||||
public @interface Translator {
|
||||
@Target({ElementType.PARAMETER, ElementType.METHOD, ElementType.FIELD})
|
||||
public @interface TranslatorSetup {
|
||||
}
|
||||
@@ -11,6 +11,6 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
@Qualifier
|
||||
@Documented
|
||||
@Retention(RUNTIME)
|
||||
@Target({ElementType.TYPE_USE, ElementType.METHOD, ElementType.FIELD})
|
||||
public @interface SubtitleExtractor {
|
||||
@Target({ElementType.PARAMETER, ElementType.METHOD, ElementType.FIELD})
|
||||
public @interface VideoConverterSetup {
|
||||
}
|
||||
@@ -3,13 +3,21 @@ package com.github.gtache.autosubtitle.subtitle.impl;
|
||||
import com.github.gtache.autosubtitle.subtitle.SubtitleCollection;
|
||||
import com.github.gtache.autosubtitle.subtitle.SubtitleConverter;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* Converts subtitles to SRT format
|
||||
*/
|
||||
@Singleton
|
||||
public class SRTSubtitleConverter implements SubtitleConverter {
|
||||
|
||||
public String convert(final SubtitleCollection collection) {
|
||||
@Inject
|
||||
SRTSubtitleConverter() {
|
||||
}
|
||||
|
||||
public String convert(final SubtitleCollection collection) {
|
||||
throw new UnsupportedOperationException("TODO");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.github.gtache.autosubtitle.subtitle.SubtitleCollection;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
@@ -12,10 +13,10 @@ import static java.util.Objects.requireNonNull;
|
||||
* Implementation of {@link SubtitleCollection}
|
||||
*/
|
||||
public record SubtitleCollectionImpl(Collection<? extends Subtitle> subtitles,
|
||||
String language) implements SubtitleCollection {
|
||||
Locale locale) implements SubtitleCollection {
|
||||
|
||||
public SubtitleCollectionImpl {
|
||||
subtitles = List.copyOf(subtitles);
|
||||
requireNonNull(language);
|
||||
requireNonNull(locale);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.github.gtache.autosubtitle.subtitle.modules.impl;
|
||||
|
||||
import com.github.gtache.autosubtitle.subtitle.SubtitleConverter;
|
||||
import com.github.gtache.autosubtitle.subtitle.impl.SRTSubtitleConverter;
|
||||
import dagger.Binds;
|
||||
import dagger.Module;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* Dagger module for subtitle converter
|
||||
*/
|
||||
@Module
|
||||
public interface ConverterModule {
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
SubtitleConverter bindsSubtitleConverter(final SRTSubtitleConverter converter);
|
||||
}
|
||||
16
core/src/main/java/module-info.java
Normal file
16
core/src/main/java/module-info.java
Normal file
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Core module for auto-subtitle
|
||||
*/
|
||||
module com.github.gtache.autosubtitle.core {
|
||||
requires transitive com.github.gtache.autosubtitle.api;
|
||||
requires transitive dagger;
|
||||
requires transitive javax.inject;
|
||||
requires org.apache.logging.log4j;
|
||||
|
||||
exports com.github.gtache.autosubtitle.impl;
|
||||
exports com.github.gtache.autosubtitle.modules.impl;
|
||||
exports com.github.gtache.autosubtitle.process.impl;
|
||||
exports com.github.gtache.autosubtitle.subtitle.impl;
|
||||
exports com.github.gtache.autosubtitle.setup.modules.impl;
|
||||
exports com.github.gtache.autosubtitle.subtitle.modules.impl;
|
||||
}
|
||||
Reference in New Issue
Block a user