Can playback video with controls, need to fix performance and reducing window size

This commit is contained in:
Guillaume Tâche
2024-08-01 19:42:25 +02:00
parent 75829244b9
commit a94eaff9ad
102 changed files with 2921 additions and 423 deletions

View File

@@ -1,20 +1,90 @@
package com.github.gtache.autosubtitle;
import com.github.gtache.autosubtitle.subtitle.Subtitle;
import com.github.gtache.autosubtitle.subtitle.SubtitleCollection;
import java.util.Locale;
/**
* Translates texts and subtitles
*/
public interface Translator {
/**
* Guesses the locale of the given text
*
* @param text The text
* @return The guessed locale
*/
Locale getLocale(final String text);
/**
* Guesses the locale of the given subtitle
*
* @param subtitle The subtitle
* @return The guessed locale
*/
default Locale getLocale(final Subtitle subtitle) {
return getLocale(subtitle.content());
}
/**
* Translates the given text to the given locale
*
* @param text The text to translate
* @param to The target locale
* @return The translated text
*/
String translate(String text, Locale to);
/**
* Translates the given text to the given locale
*
* @param text The text to translate
* @param to The target locale
* @return The translated text
*/
default String translate(final String text, final String to) {
return translate(text, Locale.forLanguageTag(to));
}
/**
* Translates the given subtitle to the given locale
*
* @param subtitle The subtitle to translate
* @param to The target locale
* @return The translated subtitle
*/
Subtitle translate(Subtitle subtitle, Locale to);
/**
* Translates the given subtitle to the given locale
*
* @param subtitle The subtitle to translate
* @param to The target locale
* @return The translated subtitle
*/
default Subtitle translate(final Subtitle subtitle, final String to) {
return translate(subtitle, Locale.forLanguageTag(to));
}
/**
* Translates the given subtitles collection to the given locale
*
* @param collection The subtitles collection to translate
* @param to The target locale
* @return The translated subtitles collection
*/
default SubtitleCollection translate(final SubtitleCollection collection, final String to) {
return translate(collection, Locale.forLanguageTag(to));
}
/**
* Translates the given subtitles collection to the given locale
*
* @param collection The subtitles collection to translate
* @param to The target locale
* @return The translated subtitles collection
*/
SubtitleCollection translate(SubtitleCollection collection, Locale to);
}

View File

@@ -18,4 +18,5 @@ public interface Video {
* @return The video info
*/
VideoInfo info();
}

View File

@@ -8,4 +8,27 @@ public interface VideoInfo {
* @return The video extension (mp4, etc.)
*/
String videoFormat();
/**
* @return The video width in pixels
*/
int width();
/**
* @return The video height in pixels
*/
int height();
/**
* @return The video duration in milliseconds
*/
long duration();
/**
* @return The aspect ratio of the video
*/
default double aspectRatio() {
return (double) width() / height();
}
}

View File

@@ -0,0 +1,20 @@
package com.github.gtache.autosubtitle;
import java.io.IOException;
import java.nio.file.Path;
/**
* Loads videos
*/
@FunctionalInterface
public interface VideoLoader {
/**
* Loads a video
*
* @param path The path to the video
* @return The loaded video
* @throws IOException If an error occurred
*/
Video loadVideo(final Path path) throws IOException;
}

View File

@@ -1,5 +1,8 @@
package com.github.gtache.autosubtitle.setup;
/**
* Exception thrown when an error occurs during setup
*/
public class SetupException extends Exception {
public SetupException(final String message) {

View File

@@ -20,7 +20,7 @@ public interface SetupManager {
* @throws SetupException if an error occurred during the check
*/
default boolean isInstalled() throws SetupException {
return status() != SetupStatus.NOT_INSTALLED;
return status().isInstalled();
}
/**

View File

@@ -4,5 +4,9 @@ package com.github.gtache.autosubtitle.setup;
* The status of a setup
*/
public enum SetupStatus {
NOT_INSTALLED, INSTALLED, UPDATE_AVAILABLE
ERRORED, NOT_INSTALLED, INSTALLED, UPDATE_AVAILABLE;
public boolean isInstalled() {
return this == INSTALLED || this == UPDATE_AVAILABLE;
}
}

View File

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

View File

@@ -10,7 +10,7 @@ import java.util.Collection;
*/
public interface SubtitleExtractor {
Collection<EditableSubtitle> extract(final Video in);
Collection<? extends EditableSubtitle> extract(final Video in);
Collection<EditableSubtitle> extract(final Audio in);
Collection<? extends EditableSubtitle> extract(final Audio in);
}

View File

@@ -0,0 +1,9 @@
/**
* API module for auto-subtitle
*/
module com.github.gtache.autosubtitle.api {
exports com.github.gtache.autosubtitle;
exports com.github.gtache.autosubtitle.process;
exports com.github.gtache.autosubtitle.setup;
exports com.github.gtache.autosubtitle.subtitle;
}