Moves some modules and files, adds save subtitles
This commit is contained in:
@@ -9,6 +9,11 @@ import java.util.Collection;
|
||||
*/
|
||||
public interface SubtitleCollection {
|
||||
|
||||
/**
|
||||
* @return The whole text of the subtitles
|
||||
*/
|
||||
String text();
|
||||
|
||||
/**
|
||||
* @return The subtitles
|
||||
*/
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
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();
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.github.gtache.autosubtitle.subtitle.converter;
|
||||
|
||||
/**
|
||||
* Exception thrown when an error occurs during subtitle parsing
|
||||
*/
|
||||
public class ParseException extends Exception {
|
||||
|
||||
public ParseException(final String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ParseException(final String message, final Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public ParseException(final Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.github.gtache.autosubtitle.subtitle.converter;
|
||||
|
||||
import com.github.gtache.autosubtitle.subtitle.SubtitleCollection;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
/**
|
||||
* Converts subtitles to a specific format (e.g. srt, ssa, ass, ...) and vice-versa
|
||||
*/
|
||||
public interface SubtitleConverter {
|
||||
|
||||
/**
|
||||
* Converts the subtitle collection
|
||||
*
|
||||
* @param collection The collection
|
||||
* @return The converted subtitles as the content of a file
|
||||
*/
|
||||
String format(final SubtitleCollection collection);
|
||||
|
||||
/**
|
||||
* Parses a subtitle collection
|
||||
*
|
||||
* @param file The path to the file
|
||||
* @return The subtitle collection
|
||||
* @throws ParseException If an error occurred
|
||||
*/
|
||||
default SubtitleCollection parse(final Path file) throws ParseException {
|
||||
try {
|
||||
final var content = Files.readString(file);
|
||||
return parse(content);
|
||||
} catch (final IOException e) {
|
||||
throw new ParseException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a subtitle collection
|
||||
*
|
||||
* @param content The content of the file
|
||||
* @return The subtitle collection
|
||||
* @throws ParseException If an error occurred
|
||||
*/
|
||||
SubtitleCollection parse(String content) throws ParseException;
|
||||
|
||||
/**
|
||||
* Check if the parser can parse the given file
|
||||
*
|
||||
* @param file The path to the file
|
||||
* @return True if the parser can parse the file
|
||||
*/
|
||||
default boolean canParse(final Path file) {
|
||||
final var fileName = file.getFileName().toString();
|
||||
return fileName.substring(fileName.lastIndexOf('.') + 1).equals(formatName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The name of the format
|
||||
*/
|
||||
String formatName();
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.github.gtache.autosubtitle.subtitle;
|
||||
package com.github.gtache.autosubtitle.subtitle.extractor;
|
||||
|
||||
/**
|
||||
* Events that can be triggered by {@link SubtitleExtractor}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.github.gtache.autosubtitle.subtitle;
|
||||
package com.github.gtache.autosubtitle.subtitle.extractor;
|
||||
|
||||
/**
|
||||
* Exception thrown when an error occurs during subtitle extraction
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.github.gtache.autosubtitle.subtitle;
|
||||
package com.github.gtache.autosubtitle.subtitle.extractor;
|
||||
|
||||
/**
|
||||
* An extraction model
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.github.gtache.autosubtitle.subtitle;
|
||||
package com.github.gtache.autosubtitle.subtitle.extractor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package com.github.gtache.autosubtitle.subtitle;
|
||||
package com.github.gtache.autosubtitle.subtitle.extractor;
|
||||
|
||||
import com.github.gtache.autosubtitle.Audio;
|
||||
import com.github.gtache.autosubtitle.Language;
|
||||
import com.github.gtache.autosubtitle.Video;
|
||||
import com.github.gtache.autosubtitle.subtitle.SubtitleCollection;
|
||||
|
||||
/**
|
||||
* Extracts subtitles from a video or audio
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.github.gtache.autosubtitle.subtitle;
|
||||
package com.github.gtache.autosubtitle.subtitle.extractor;
|
||||
|
||||
/**
|
||||
* Listener for {@link SubtitleExtractor}
|
||||
@@ -6,4 +6,6 @@ module com.github.gtache.autosubtitle.api {
|
||||
exports com.github.gtache.autosubtitle.process;
|
||||
exports com.github.gtache.autosubtitle.setup;
|
||||
exports com.github.gtache.autosubtitle.subtitle;
|
||||
exports com.github.gtache.autosubtitle.subtitle.extractor;
|
||||
exports com.github.gtache.autosubtitle.subtitle.converter;
|
||||
}
|
||||
Reference in New Issue
Block a user