Skip to content

Commit

Permalink
Added support for SRT subtitles
Browse files Browse the repository at this point in the history
  • Loading branch information
Keksuccino committed Oct 22, 2024
1 parent 470f420 commit 2aa06a5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class Backend {
//TODO Wenn möglich, irgendwann support für Llama-2 GenAI model adden (self-hosted)

private static final SimpleLogger LOGGER = LogHandler.getLogger();
public static final String VERSION = "1.1.2";
public static final String VERSION = "1.2.0";
public static final File TEMP_DIRECTORY = new File("temp_data");

private static Options options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public static String getFileExtension(@NotNull VideoStream subtitleTrack) {
if (subtitleTrack.isSubtitle()) {
//ASS
if ("ass".equals(subtitleTrack.getSubtitleType())) return "ass";
//SRT
if ("srt".equals(subtitleTrack.getSubtitleType())) return "srt";
//SRT (SubRip)
if ("subrip".equals(subtitleTrack.getSubtitleType())) return "srt";
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ protected void parseSrtFile(@NotNull File srtFile) {

for (String line : FileUtils.readTextLinesFrom(srtFile)) {

//Remove UTF-8 BOM
if (line.startsWith(FileUtils.UTF8_BOM_CHAR)) {
line = line.substring(1);
}

lineCounter++;

boolean subtitleLineNumberUpdated = false;

//Cache subtitle line number if last line was empty OR it's the beginning of the file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.keksuccino.linguji.linguji.frontend.views;

import com.google.common.collect.Lists;
import de.keksuccino.linguji.linguji.backend.Backend;
import de.keksuccino.linguji.linguji.backend.lib.ffmpeg.Ffmpeg;
import de.keksuccino.linguji.linguji.backend.lib.ffmpeg.info.VideoInfo;
Expand Down Expand Up @@ -40,6 +41,8 @@
import org.jetbrains.annotations.Nullable;
import java.awt.*;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class MainViewController implements ViewControllerBase {
Expand Down Expand Up @@ -332,7 +335,12 @@ protected void openSubtitleChooser(@NotNull File videoFile) {

Ffmpeg ffmpeg = Ffmpeg.buildDefault();
VideoInfo info = Objects.requireNonNull(ffmpeg.getVideoInfo(videoFile));
controller.subtitles = info.getSubtitlesOfType("ass");

//Add subtitle tracks of all supported types
controller.subtitles = new ArrayList<>();
controller.subtitles.addAll(info.getSubtitlesOfType("ass"));
controller.subtitles.addAll(info.getSubtitlesOfType("srt"));
controller.subtitles.addAll(info.getSubtitlesOfType("subrip")); //that's SRT (not sure if the type is always subrip, so I'm adding both srt and subrip)

controller.finishInitialization(stageChooserWindow);

Expand Down

0 comments on commit 2aa06a5

Please sign in to comment.