Rewrites a lot of code

Streams are now parsed to objects, making it easier to get required information.
Improved styling.
Some better comments.
Better input parsing.
This commit is contained in:
2019-10-06 01:02:47 +02:00
parent 0a39a69e73
commit 20e6df04f1
10 changed files with 684 additions and 429 deletions

View File

@@ -0,0 +1,29 @@
package ffmpegconverter.streams;
public class AudioStream extends StreamObject {
private String language; //The audio language
private int channels; //Whether mono, stereo, etc
private String title; //Titles exist
public AudioStream(String codec, int absoluteIndex, int relativeIndex, String language, String title, int channels) {
this.codecType = "audio";
this.codecName = codec;
this.absoluteIndex = absoluteIndex;
this.language = language;
this.title = title;
this.relativeIndex = relativeIndex;
this.channels = channels;
}
public String getLanguage() {
return this.language;
}
public int getChannels() {
return this.channels;
}
public String getTitle() {
return this.title;
}
}

View File

@@ -0,0 +1,43 @@
package ffmpegconverter.streams;
/**
* An object representation of a stream in a media file
*/
public abstract class StreamObject {
int absoluteIndex;
int relativeIndex;
String codecName;
String codecType;
/**
* Gets the type of the stream codec (video/audio/subtitle)
* @return codec type
*/
public String getCodecType() {
return this.codecType;
}
/**
* Gets the name of the stream codec
* @return codec name
*/
public String getCodecName() {
return this.codecName;
}
/**
* Gets the absolute index of a stream object
* @return absolute index
*/
public int getAbsoluteIndex() {
return this.absoluteIndex;
}
/**
* Gets the relative index of a stream object (kth element of codec type)
* @return relative index
*/
public int getRelativeIndex() {
return this.relativeIndex;
}
}

View File

@@ -0,0 +1,59 @@
package ffmpegconverter.streams;
/**
* An object representation of a subtitle stream in a media file
*/
public class SubtitleStream extends StreamObject {
private String language;
private String title; //Title shown
private boolean isFullSubtitle; //Songs and signs will be false
private boolean isImageSubtitle;
public SubtitleStream(String codecName, int absoluteIndex, int relativeIndex, String language, String title) {
this.codecType = "subtitle";
this.codecName = codecName;
this.absoluteIndex = absoluteIndex;
this.language = language;
this.title = title;
this.isFullSubtitle = isFullSubtitle();
this.relativeIndex = relativeIndex;
this.isImageSubtitle = isImageSubtitle();
}
/**
* 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");
}
/**
* Checks whether translates everything (as opposed to just songs and signs)
* @return True if the subtitles translate everything
*/
private boolean isFullSubtitle() {
if (getTitle() == null) {
return false;
}
String title = getTitle().toLowerCase();
return !(title.contains("songs and signs") || title.contains("songs & signs") || title.contains("songs ") ||
title.contains("signs/songs") || title.contains("[forced]") || title.contains("(forced)"));
}
public String getLanguage() {
return this.language;
}
public String getTitle() {
return this.title;
}
public boolean getIsImageSubtitle() {
return this.isImageSubtitle;
}
public boolean getIsFullSubtitle() {
return this.isFullSubtitle;
}
}

View File

@@ -0,0 +1,13 @@
package ffmpegconverter.streams;
/**
* An object representation of a video stream in a media file
*/
public class VideoStream extends StreamObject {
public VideoStream(String codec, int absoluteIndex, int relativeIndex) {
this.codecType = "video";
this.codecName = codec;
this.absoluteIndex = absoluteIndex;
this.relativeIndex = relativeIndex;
}
}