Initial commit
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package com.github.gtache.autosubtitle.impl;
|
||||
|
||||
import com.github.gtache.autosubtitle.AudioInfo;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Implementation of {@link AudioInfo}
|
||||
*/
|
||||
public record AudioInfoImpl(String audioFormat) implements AudioInfo {
|
||||
|
||||
public AudioInfoImpl {
|
||||
Objects.requireNonNull(audioFormat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String videoFormat() {
|
||||
return audioFormat;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.github.gtache.autosubtitle.impl;
|
||||
|
||||
import com.github.gtache.autosubtitle.Audio;
|
||||
import com.github.gtache.autosubtitle.AudioInfo;
|
||||
import com.github.gtache.autosubtitle.File;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
/**
|
||||
* Implementation of {@link Audio} with a {@link File}
|
||||
*/
|
||||
public record FileAudioImpl(Path path, AudioInfo info) implements Audio, File {
|
||||
|
||||
public FileAudioImpl {
|
||||
requireNonNull(path);
|
||||
requireNonNull(info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() throws IOException {
|
||||
return File.super.getInputStream();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.github.gtache.autosubtitle.impl;
|
||||
|
||||
import com.github.gtache.autosubtitle.File;
|
||||
import com.github.gtache.autosubtitle.Video;
|
||||
import com.github.gtache.autosubtitle.VideoInfo;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
/**
|
||||
* Implementation of {@link Video} with a {@link File}
|
||||
*/
|
||||
public record FileVideoImpl(Path path, VideoInfo info) implements Video, File {
|
||||
|
||||
public FileVideoImpl {
|
||||
requireNonNull(path);
|
||||
requireNonNull(info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() throws IOException {
|
||||
return File.super.getInputStream();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.github.gtache.autosubtitle.impl;
|
||||
|
||||
import com.github.gtache.autosubtitle.Audio;
|
||||
import com.github.gtache.autosubtitle.AudioInfo;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
/**
|
||||
* In-memory implementation of {@link Audio}
|
||||
*/
|
||||
public record MemoryAudioImpl(Supplier<InputStream> inputStreamSupplier, AudioInfo info) implements Audio {
|
||||
|
||||
public MemoryAudioImpl {
|
||||
requireNonNull(inputStreamSupplier);
|
||||
requireNonNull(info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() {
|
||||
return inputStreamSupplier.get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.github.gtache.autosubtitle.impl;
|
||||
|
||||
import com.github.gtache.autosubtitle.Video;
|
||||
import com.github.gtache.autosubtitle.VideoInfo;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
/**
|
||||
* In-memory implementation of {@link Video}
|
||||
*/
|
||||
public record MemoryVideoImpl(Supplier<InputStream> inputStreamSupplier, VideoInfo info) implements Video {
|
||||
|
||||
public MemoryVideoImpl {
|
||||
requireNonNull(inputStreamSupplier);
|
||||
requireNonNull(info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() {
|
||||
return inputStreamSupplier.get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.github.gtache.autosubtitle.impl;
|
||||
|
||||
import com.github.gtache.autosubtitle.VideoInfo;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Implementation of {@link VideoInfo}
|
||||
*/
|
||||
public record VideoInfoImpl(String videoFormat) implements VideoInfo {
|
||||
|
||||
public VideoInfoImpl {
|
||||
Objects.requireNonNull(videoFormat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String videoFormat() {
|
||||
return videoFormat;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.github.gtache.autosubtitle.process.impl;
|
||||
|
||||
import com.github.gtache.autosubtitle.process.ProcessResult;
|
||||
import com.github.gtache.autosubtitle.process.ProcessRunner;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Base implementation of {@link ProcessRunner}
|
||||
*/
|
||||
public abstract class AbstractProcessRunner implements ProcessRunner {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(AbstractProcessRunner.class);
|
||||
|
||||
@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(() -> {
|
||||
try (final var in = new BufferedReader(new InputStreamReader(new BufferedInputStream(process.getInputStream()), StandardCharsets.UTF_8))) {
|
||||
while (in.ready()) {
|
||||
output.add(in.readLine());
|
||||
}
|
||||
} catch (final IOException e) {
|
||||
logger.error("Error listening to process output of {}", args, e);
|
||||
}
|
||||
}).start();
|
||||
try {
|
||||
process.waitFor(1, TimeUnit.HOURS);
|
||||
} catch (final InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
process.destroy();
|
||||
}
|
||||
return new ProcessResultImpl(process.exitValue(), output);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.github.gtache.autosubtitle.process.impl;
|
||||
|
||||
import com.github.gtache.autosubtitle.process.ProcessResult;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Implementation of {@link ProcessResult}
|
||||
*/
|
||||
public record ProcessResultImpl(int exitCode, List<String> output) implements ProcessResult {
|
||||
|
||||
public ProcessResultImpl {
|
||||
output = List.copyOf(output);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.github.gtache.autosubtitle.setup.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.TYPE_USE, ElementType.METHOD, ElementType.FIELD})
|
||||
public @interface SubtitleExtractor {
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.github.gtache.autosubtitle.setup.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.TYPE_USE, ElementType.METHOD, ElementType.FIELD})
|
||||
public @interface Translator {
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.github.gtache.autosubtitle.setup.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.TYPE_USE, ElementType.METHOD, ElementType.FIELD})
|
||||
public @interface VideoConverter {
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.github.gtache.autosubtitle.subtitle.impl;
|
||||
|
||||
import com.github.gtache.autosubtitle.subtitle.Bounds;
|
||||
|
||||
/**
|
||||
* Implementation of {@link Bounds}
|
||||
*/
|
||||
public record BoundsImpl(double x, double y, double width, double height) implements Bounds {
|
||||
|
||||
public BoundsImpl {
|
||||
if (x < 0) {
|
||||
throw new IllegalArgumentException("x must be >= 0 : " + x);
|
||||
}
|
||||
if (y < 0) {
|
||||
throw new IllegalArgumentException("y must be >= 0 : " + y);
|
||||
}
|
||||
if (width < 0) {
|
||||
throw new IllegalArgumentException("width must be >= 0 : " + width);
|
||||
}
|
||||
if (height < 0) {
|
||||
throw new IllegalArgumentException("height must be >= 0 : " + height);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.github.gtache.autosubtitle.subtitle.impl;
|
||||
|
||||
import com.github.gtache.autosubtitle.subtitle.Font;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Implementation of {@link Font}
|
||||
* @param name
|
||||
* @param size
|
||||
*/
|
||||
public record FontImpl(String name, int size) implements Font {
|
||||
|
||||
public FontImpl {
|
||||
Objects.requireNonNull(name);
|
||||
if (size <= 0) {
|
||||
throw new IllegalArgumentException("Size must be greater than 0 : " + size);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.github.gtache.autosubtitle.subtitle.impl;
|
||||
|
||||
import com.github.gtache.autosubtitle.subtitle.SubtitleCollection;
|
||||
import com.github.gtache.autosubtitle.subtitle.SubtitleConverter;
|
||||
|
||||
/**
|
||||
* Converts subtitles to SRT format
|
||||
*/
|
||||
public class SRTSubtitleConverter implements SubtitleConverter {
|
||||
|
||||
public String convert(final SubtitleCollection collection) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatName() {
|
||||
return "srt";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.github.gtache.autosubtitle.subtitle.impl;
|
||||
|
||||
import com.github.gtache.autosubtitle.subtitle.Subtitle;
|
||||
import com.github.gtache.autosubtitle.subtitle.SubtitleCollection;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
/**
|
||||
* Implementation of {@link SubtitleCollection}
|
||||
*/
|
||||
public record SubtitleCollectionImpl(Collection<? extends Subtitle> subtitles,
|
||||
String language) implements SubtitleCollection {
|
||||
|
||||
public SubtitleCollectionImpl {
|
||||
subtitles = List.copyOf(subtitles);
|
||||
requireNonNull(language);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user