package net.knarcraft.ffmpegconverter.streams; /** * An object representation of a subtitle stream in a media file */ public class SubtitleStream extends AbstractStream implements StreamObject { final private String title; final private String file; final private boolean isFullSubtitle; final private boolean isImageSubtitle; /** * Instantiates a new subtitle stream * * @param codecName

The name of the codec for the subtitle stream.

* @param absoluteIndex

The index of the subtitle stream.

* @param relativeIndex

The index of the subtitle stream relative to other subtitle streams.

* @param language

The language of the subtitle stream.

* @param title

The title of the subtitle stream.

* @param file

The file containing the subtitle.

*/ public SubtitleStream(String codecName, int absoluteIndex, int relativeIndex, String language, String title, String file) { this.codecName = codecName; this.absoluteIndex = absoluteIndex; this.language = language; this.title = title; this.isFullSubtitle = isFullSubtitle(); this.relativeIndex = relativeIndex; this.isImageSubtitle = isImageSubtitle(); this.file = file; } /** * Gets the title of the subtitle stream * * @return

The title of the subtitle stream.

*/ public String getTitle() { return this.title; } /** * Gets the file name of the file containing this subtitle * * @return

The file name containing the subtitle stream.

*/ public String getFile() { return this.file; } /** * Gets whether the subtitle is an image subtitle * * @return

Whether the subtitles is an image subtitle.

*/ public boolean getIsImageSubtitle() { return this.isImageSubtitle; } /** * Gets whether the subtitle is a full subtitle * * @return

Whether the subtitle is a full subtitle.

*/ public boolean getIsFullSubtitle() { return this.isFullSubtitle; } /** * Checks whether a subtitle is image based (as opposed to text based) * * @return

True if the subtitle is image based.

*/ private boolean isImageSubtitle() { return codecName != null && (getCodecName().equals("hdmv_pgs_subtitle") || getCodecName().equals("dvd_subtitle")); } /** * Checks whether the subtitle translates everything (as opposed to just songs and signs) * * @return

True if the subtitle translates everything.

*/ private boolean isFullSubtitle() { if (getTitle() == null) { return false; } String titleLowercase = getTitle().toLowerCase(); return !titleLowercase.matches(".*signs?[ &/a-z]+songs?.*") && !titleLowercase.matches(".*songs?[ &/a-z]+signs?.*") && !titleLowercase.matches(".*forced.*"); } }