Initial commit

This commit is contained in:
Guillaume Tâche
2024-07-27 17:45:46 +02:00
commit 75829244b9
66 changed files with 2906 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
package com.github.gtache.autosubtitle;
import java.io.IOException;
import java.io.InputStream;
/**
* Represents an audio
*/
public interface Audio {
/**
* @return The audio input stream
* @throws IOException If an I/O error occurs
*/
InputStream getInputStream() throws IOException;
/**
* @return The audio info
*/
AudioInfo info();
}

View File

@@ -0,0 +1,11 @@
package com.github.gtache.autosubtitle;
/**
* Represents info about an audio
*/
public interface AudioInfo {
/**
* @return The audio extension (mp3, etc.)
*/
String videoFormat();
}

View File

@@ -0,0 +1,14 @@
package com.github.gtache.autosubtitle;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
public interface File {
default InputStream getInputStream() throws IOException {
return Files.newInputStream(path());
}
Path path();
}

View File

@@ -0,0 +1,20 @@
package com.github.gtache.autosubtitle;
import com.github.gtache.autosubtitle.subtitle.Subtitle;
import java.util.Locale;
public interface Translator {
String translate(String text, Locale to);
default String translate(final String text, final String to) {
return translate(text, Locale.forLanguageTag(to));
}
Subtitle translate(Subtitle subtitle, Locale to);
default Subtitle translate(final Subtitle subtitle, final String to) {
return translate(subtitle, Locale.forLanguageTag(to));
}
}

View File

@@ -0,0 +1,21 @@
package com.github.gtache.autosubtitle;
import java.io.IOException;
import java.io.InputStream;
/**
* Represents a video
*/
public interface Video {
/**
* @return The video input stream
* @throws IOException If an I/O error occurs
*/
InputStream getInputStream() throws IOException;
/**
* @return The video info
*/
VideoInfo info();
}

View File

@@ -0,0 +1,15 @@
package com.github.gtache.autosubtitle;
import com.github.gtache.autosubtitle.subtitle.SubtitleCollection;
import java.io.IOException;
import java.util.Collection;
public interface VideoConverter {
Video addSoftSubtitles(final Video video, final Collection<SubtitleCollection> subtitles) throws IOException;
Video addHardSubtitles(final Video video, final SubtitleCollection subtitles) throws IOException;
Audio getAudio(final Video video) throws IOException;
}

View File

@@ -0,0 +1,11 @@
package com.github.gtache.autosubtitle;
/**
* Info about a video
*/
public interface VideoInfo {
/**
* @return The video extension (mp4, etc.)
*/
String videoFormat();
}

View File

@@ -0,0 +1,19 @@
package com.github.gtache.autosubtitle.process;
import java.util.List;
/**
* Represents the result of running a process
*/
public interface ProcessResult {
/**
* @return the exit code of the process
*/
int exitCode();
/**
* @return the output of the process
*/
List<String> output();
}

View File

@@ -0,0 +1,31 @@
package com.github.gtache.autosubtitle.process;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
/**
* Runs processes
*/
public interface ProcessRunner {
/**
* Runs a command
*
* @param args the command
* @return the result
* @throws IOException if something goes wrong
*/
default ProcessResult run(final String... args) throws IOException {
return run(Arrays.asList(args));
}
/**
* Runs a command
*
* @param args the command
* @return the result
* @throws IOException if something goes wrong
*/
ProcessResult run(final List<String> args) throws IOException;
}

View File

@@ -0,0 +1,16 @@
package com.github.gtache.autosubtitle.setup;
public class SetupException extends Exception {
public SetupException(final String message) {
super(message);
}
public SetupException(final String message, final Throwable cause) {
super(message, cause);
}
public SetupException(final Throwable cause) {
super(cause);
}
}

View File

@@ -0,0 +1,66 @@
package com.github.gtache.autosubtitle.setup;
/**
* Manages the setup of a component
*/
public interface SetupManager {
/**
* @return the name of the component
*/
String name();
/**
* @return the status of the component setup
*/
SetupStatus status();
/**
* @return whether the component is installed
* @throws SetupException if an error occurred during the check
*/
default boolean isInstalled() throws SetupException {
return status() != SetupStatus.NOT_INSTALLED;
}
/**
* Installs the component
*
* @throws SetupException if an error occurred during the installation
*/
void install() throws SetupException;
/**
* Uninstalls the component
*
* @throws SetupException if an error occurred during the uninstallation
*/
void uninstall() throws SetupException;
/**
* Reinstalls the component
*
* @throws SetupException if an error occurred during the reinstallation
*/
default void reinstall() throws SetupException {
uninstall();
install();
}
/**
* Checks if an update is available for the component
*
* @return whether an update is available
* @throws SetupException if an error occurred during the check
*/
default boolean isUpdateAvailable() throws SetupException {
return status() == SetupStatus.UPDATE_AVAILABLE;
}
/**
* Updates the component
*
* @throws SetupException if an error occurred during the update
*/
void update() throws SetupException;
}

View File

@@ -0,0 +1,8 @@
package com.github.gtache.autosubtitle.setup;
/**
* The status of a setup
*/
public enum SetupStatus {
NOT_INSTALLED, INSTALLED, UPDATE_AVAILABLE
}

View File

@@ -0,0 +1,28 @@
package com.github.gtache.autosubtitle.subtitle;
/**
* Represents the bounds of an object
*/
public interface Bounds {
/**
* @return the x coordinate
*/
double x();
/**
* @return the y coordinate
*/
double y();
/**
* @return the width
*/
double width();
/**
* @return the height
*/
double height();
}

View File

@@ -0,0 +1,42 @@
package com.github.gtache.autosubtitle.subtitle;
/**
* Subtitle that can be edited
*/
public interface EditableSubtitle extends Subtitle {
/**
* Sets the content of the subtitle
*
* @param content the new content
*/
void setContent(String content);
/**
* Sets the start time of the subtitle
*
* @param start the new start time (in milliseconds)
*/
void setStart(final long start);
/**
* Sets the end time of the subtitle
*
* @param end the new end time (in milliseconds)
*/
void setEnd(final long end);
/**
* Sets the font of the subtitle
*
* @param font the new font
*/
void setFont(final Font font);
/**
* Sets the location of the subtitle
*
* @param bounds the new location
*/
void setBounds(final Bounds bounds);
}

View File

@@ -0,0 +1,8 @@
package com.github.gtache.autosubtitle.subtitle;
public interface Font {
String name();
int size();
}

View File

@@ -0,0 +1,41 @@
package com.github.gtache.autosubtitle.subtitle;
import java.time.Duration;
/**
* Represents a subtitle
*/
public interface Subtitle {
/**
* @return the content of the subtitle
*/
String content();
/**
* @return the start time of the subtitle in milliseconds
*/
long start();
/**
* @return the end time of the subtitle in milliseconds
*/
long end();
/**
* @return the duration of the subtitle
*/
default Duration duration() {
return Duration.ofMillis(end() - start());
}
/**
* @return the font of the subtitle
*/
Font font();
/**
* @return the location and size of the subtitle
*/
Bounds bounds();
}

View File

@@ -0,0 +1,19 @@
package com.github.gtache.autosubtitle.subtitle;
import java.util.Collection;
/**
* Represents a collection of {@link Subtitle}
*/
public interface SubtitleCollection {
/**
* @return The subtitles
*/
Collection<? extends Subtitle> subtitles();
/**
* @return The language of the subtitles
*/
String language();
}

View File

@@ -0,0 +1,20 @@
package com.github.gtache.autosubtitle.subtitle;
/**
* Converts subtitles to a specific format (e.g. srt, ssa, ass, ...)
*/
public interface SubtitleConverter {
/**
* Converts the subtitle collection
*
* @param collection The collection
* @return The converted subtitles as the content of a file
*/
String convert(final SubtitleCollection collection);
/**
* @return The name of the format
*/
String formatName();
}

View File

@@ -0,0 +1,16 @@
package com.github.gtache.autosubtitle.subtitle;
import com.github.gtache.autosubtitle.Audio;
import com.github.gtache.autosubtitle.Video;
import java.util.Collection;
/**
* Extracts subtitles from a video or audio
*/
public interface SubtitleExtractor {
Collection<EditableSubtitle> extract(final Video in);
Collection<EditableSubtitle> extract(final Audio in);
}