Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Update author information #7

Merged
merged 7 commits into from

2 participants

This page is out of date. Refresh to see the latest.
View
26 README.md
@@ -1,6 +1,8 @@
Subtitle Converter
==================
+Original README
+---------------
This is a java framework for processing subtitle formats and converting them into other formats.
So far the formats supported are EBU's STL, .SCC, .ASS/.SSA .SRT and a subset of W3C's TTML 1.0
@@ -19,3 +21,27 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Addtional Notes
+---------------
+Modified by Ethan Hart
+
+To run conversion, first, you must compile Convert.java by doing the following:
+
+ $ cd Subtitle\ Files/src/
+ $ javac Convert.java
+
+Once you have Convert.class, you can run the following:
+
+ $ java Convert input-file input-format output-format output-file
+
+Note: Some IO changes have been made for Linux support (filepaths) and are
+not guaranteed to work on Windows.
+
+To make a java archive (jar) file, do the following:
+
+ $ cd Subtitle\ Files/src/
+ $ ./makejar.sh
+
+This will create a jar which can be run from anywhere. It uses the same the
+argument structure as the Convert.class.
View
11 Subtitle Files/prueba.txt
@@ -1,11 +0,0 @@
-Scenarist_SCC V1.0
-
- 942c 942c
-
- 94ae 94ae 9420 9420 1340 1340 a820 68ef f26e 2068 ef6e 6be9 6e67 2029 8080 8080 942f 942f
-
- 942c 942c
-
- 94ae 94ae 9420 9420 1340 1340 c845 d92c 2054 c845 5245 ae80 8080 8080 942f 942f
-
-
View
82 Subtitle Files/src/Convert.java
@@ -0,0 +1,82 @@
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import subtitleFile.FormatASS;
+import subtitleFile.FormatSCC;
+import subtitleFile.FormatSRT;
+import subtitleFile.FormatSTL;
+import subtitleFile.FormatTTML;
+import subtitleFile.TimedTextFileFormat;
+import subtitleFile.TimedTextObject;
+
+
+public class Convert {
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+
+ TimedTextObject tto;
+ TimedTextFileFormat ttff;
+ OutputStream output = null;
+
+ //this is in case anyone may want to use this as stand alone java executable
+ if (args != null && args.length == 4){
+
+ try {
+
+ String inputFile = args[0];
+ String inputFormat = args[1];
+ String outputFormat = args[2];
+ String outputFile = args[3];
+
+ if ("SRT".equalsIgnoreCase(inputFormat)){
+ ttff = new FormatSRT();
+ } else if ("STL".equalsIgnoreCase(inputFormat)){
+ ttff = new FormatSTL();
+ } else if ("SCC".equalsIgnoreCase(inputFormat)){
+ ttff = new FormatSCC();
+ } else if ("XML".equalsIgnoreCase(inputFormat)){
+ ttff = new FormatTTML();
+ } else if ("ASS".equalsIgnoreCase(inputFormat)){
+ ttff = new FormatASS();
+ } else {
+ throw new Exception("Unrecognized input format: "+inputFormat+" only [SRT,STL,SCC,XML,ASS] are possible");
+ }
+
+ File file = new File(inputFile);
+ InputStream is = new FileInputStream(file);
+ tto = ttff.parseFile(file.getName(), is);
+
+ if ("SRT".equalsIgnoreCase(outputFormat)){
+ IOClass.writeFileTxt(outputFile, tto.toSRT());
+ } else if ("STL".equalsIgnoreCase(outputFormat)){
+ output = new BufferedOutputStream(new FileOutputStream(outputFile));
+ output.write(tto.toSTL());
+ output.close();
+ } else if ("SCC".equalsIgnoreCase(outputFormat)){
+ IOClass.writeFileTxt(outputFile, tto.toSCC());
+ } else if ("XML".equalsIgnoreCase(outputFormat)){
+ IOClass.writeFileTxt(outputFile, tto.toTTML());
+ } else if ("ASS".equalsIgnoreCase(outputFormat)){
+ IOClass.writeFileTxt(outputFile, tto.toASS());
+ } else {
+ throw new Exception("Unrecognized input format: "+outputFormat+" only [SRT,STL,SCC,XML,ASS] are possible");
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // normal test use
+ } else {
+ System.out.println("Usage: java Convert input-file input-format output-format output-file");
+ }
+
+ }
+}
View
82 Subtitle Files/src/IOClass.java
@@ -10,37 +10,36 @@
*
* @author J. David
*
- * Clase que se encarga de la lectura y escritura de ficheros o lectura desde teclado
+ * Class that handles reading and writing files or reads from keyboard
*
*/
public class IOClass {
/**
- * Metodo que recibe el nombre del fichero (o la ruta relativa al directorio de usuario)
- * y el fichero a escribir en forma de un array de Strings donde cada String representa una linea
+ * Method to get the file name (or path relative to the directory) and file to write to
+ * in the form of an array of strings where each string represents a line
*
- * @param nombreFichero nombre del fichero (o la ruta relativa al directorio de usuario)
- * @param ficheroTotal array de Strings donde cada String representa una linea del fichero
+ * @param fileName name of the file (or path relative to directory)
+ * @param totalFile array of strings where each string represents a line in the file
*/
- public static void escribirFicheroTxt(String nombreFichero, String[] ficheroTotal){
- FileWriter fichero = null;
+ public static void writeFileTxt(String fileName, String[] totalFile){
+ FileWriter file = null;
PrintWriter pw = null;
try
{
- fichero = new FileWriter(System.getProperty("user.dir")+"\\"+nombreFichero);
- pw = new PrintWriter(fichero);
+ file = new FileWriter(System.getProperty("user.dir")+"/"+fileName);
+ pw = new PrintWriter(file);
- for (int i = 0; i < ficheroTotal.length; i++)
- pw.println(ficheroTotal[i]);
+ for (int i = 0; i < totalFile.length; i++)
+ pw.println(totalFile[i]);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
- // Aprovechamos el finally para
- // asegurarnos que se cierra el fichero.
- if (null != fichero)
- fichero.close();
+ // Execute the "finally" to make sure the file is closed
+ if (null != file)
+ file.close();
} catch (Exception e2) {
e2.printStackTrace();
}
@@ -48,44 +47,43 @@ public static void escribirFicheroTxt(String nombreFichero, String[] ficheroTota
}
/**
- * Metodo que recibe el nombre del fichero (o la ruta relativa al directorio de usuario)
- * y el fichero a escribir en forma de un array de Strings donde cada String representa una linea
+ * Method to get the file name (or path relative to the directory) and file to write to
+ * in the form of an array of strings where each string represents a line
*
- * @param nombreFichero nombre del fichero (o la ruta relativa al directorio de usuario)
- * @return array de Strings donde cada String representa una linea del fichero leido
+ * @param fileName name of the file (or path relative to directory)
+ * @param s array of strings where each string represents a line in the file
*/
- public static String[] leerFicheroTxt(String nombreFichero){
+ public static String[] readfileTxt(String fileName){
String [] s = new String [0];
- String direccion = System.getProperty("user.dir")+"\\"+ nombreFichero;
+ String direccion = System.getProperty("user.dir")+"/"+ fileName;
- //Intenta cargar el archivo
- File archivo = null;
+ // Try to load the file (archive)
+ File archive = null;
FileReader fr = null;
BufferedReader br = null;
try {
- // Apertura del fichero y creacion de BufferedReader para poder
- // hacer una lectura comoda (disponer del metodo readLine()).
- archivo = new File (direccion);
- fr = new FileReader (archivo);
+ // Open the file and create BufferedReader in order to
+ // reading easier (disposing the method readLine()).
+ archive = new File (direccion);
+ fr = new FileReader (archive);
br = new BufferedReader(fr);
- // Lectura del fichero
- String linea = null;
- while((linea=br.readLine())!=null){
+ // Reading the file
+ String line = null;
+ while((line=br.readLine())!=null){
int n=0;
String [] s2 = new String[s.length+1];
for(n=0;n<s.length;n++)s2[n] = s[n];
- s2[n]=linea.trim();
+ s2[n]=line.trim();
s=s2;
}
}catch(Exception e){
- System.err.println("No se ha encontrado el archivo");
+ System.err.println("File not found");
System.exit(-1);
}finally{
- // En el finally cerramos el fichero, para asegurarnos
- // que se cierra tanto si todo va bien como si salta
- // una excepcion.
+ // In the "finally" block, try to close the file and ensure
+ // that it closes, otherwise, throw an exception
try{
if( null != fr ){
fr.close();
@@ -98,20 +96,20 @@ public static void escribirFicheroTxt(String nombreFichero, String[] ficheroTota
}
/**
- * Metodo que lee una linea desde el teclado
+ * Method to read a line from the keyboard
*
- * @return Devuelve el String leido
+ * @return Returns the string being read
*/
- public static String leerTeclado(){
- String respuesta = null;
+ public static String readTeclado(){
+ String response = null;
try{
InputStreamReader isr = new InputStreamReader (System.in);
BufferedReader br = new BufferedReader (isr);
- respuesta = br.readLine();
+ response = br.readLine();
} catch (IOException e){
- System.err.println("excepcion al leer el teclado, programa finalizado");
+ System.err.println("Error reading keyboard, program complete");
System.exit(-1);
}
- return respuesta;
+ return response;
}
}
View
41 Subtitle Files/src/Pruebas.java → Subtitle Files/src/Tests.java
@@ -14,7 +14,7 @@
import subtitleFile.TimedTextObject;
-public class Pruebas {
+public class Tests {
/**
* @param args
@@ -30,10 +30,10 @@ public static void main(String[] args) {
try {
- String inputFile = args[1];
- String inputFormat = args[0];
- String outputFormat = args[3];
- String outputFile = args[4];
+ String inputFile = args[0];
+ String inputFormat = args[1];
+ String outputFormat = args[2];
+ String outputFile = args[3];
if ("SRT".equalsIgnoreCase(inputFormat)){
ttff = new FormatSRT();
@@ -54,24 +54,23 @@ public static void main(String[] args) {
tto = ttff.parseFile(file.getName(), is);
if ("SRT".equalsIgnoreCase(outputFormat)){
- IOClass.escribirFicheroTxt(outputFile, tto.toSRT());
+ IOClass.writeFileTxt(outputFile, tto.toSRT());
} else if ("STL".equalsIgnoreCase(outputFormat)){
output = new BufferedOutputStream(new FileOutputStream(outputFile));
output.write(tto.toSTL());
+ output.close();
} else if ("SCC".equalsIgnoreCase(outputFormat)){
- IOClass.escribirFicheroTxt(outputFile, tto.toSCC());
+ IOClass.writeFileTxt(outputFile, tto.toSCC());
} else if ("XML".equalsIgnoreCase(outputFormat)){
- IOClass.escribirFicheroTxt(outputFile, tto.toTTML());
+ IOClass.writeFileTxt(outputFile, tto.toTTML());
} else if ("ASS".equalsIgnoreCase(outputFormat)){
- IOClass.escribirFicheroTxt(outputFile, tto.toASS());
+ IOClass.writeFileTxt(outputFile, tto.toASS());
} else {
throw new Exception("Unrecognized input format: "+outputFormat+" only [SRT,STL,SCC,XML,ASS] are possible");
}
} catch (Exception e) {
e.printStackTrace();
- } finally {
- output.close();
}
// normal test use
@@ -81,39 +80,39 @@ public static void main(String[] args) {
//To test the correct implementation of the SRT parser and writer.
ttff = new FormatSRT();
- File file = new File("standards\\SRT\\Avengers.2012.Eng.Subs.srt");
+ File file = new File("../standards/SRT/Avengers.2012.Eng.Subs.srt");
InputStream is = new FileInputStream(file);
tto = ttff.parseFile(file.getName(), is);
- IOClass.escribirFicheroTxt("prueba.txt", tto.toSRT());
+ IOClass.writeFileTxt("test.srt", tto.toSRT());
//To test the correct implementation of the ASS/SSA parser and writer.
ttff = new FormatASS();
- file = new File("standards\\ASS\\test.ssa");
+ file = new File("../standards/ASS/test.ssa");
is = new FileInputStream(file);
tto = ttff.parseFile(file.getName(), is);
- IOClass.escribirFicheroTxt("prueba.txt", tto.toASS());
+ IOClass.writeFileTxt("test.ssa", tto.toASS());
//To test the correct implementation of the TTML parser and writer.
ttff = new FormatTTML();
- file = new File("standards\\XML\\Debate0_03-03-08.dfxp.xml");
+ file = new File("../standards/XML/Debate0_03-03-08.dfxp.xml");
is = new FileInputStream(file);
tto = ttff.parseFile(file.getName(), is);
- IOClass.escribirFicheroTxt("prueba.txt", tto.toTTML());
+ IOClass.writeFileTxt("test.xml", tto.toTTML());
//To test the correct implementation of the SCC parser and writer.
ttff = new FormatSCC();
- file = new File("standards\\SCC\\sccTest.scc");
+ file = new File("../standards/SCC/sccTest.scc");
is = new FileInputStream(file);
tto = ttff.parseFile(file.getName(), is);
- IOClass.escribirFicheroTxt("prueba.txt", tto.toSCC());
+ IOClass.writeFileTxt("prueba.scc", tto.toSCC());
//To test the correct implementation of the STL parser and writer.
ttff = new FormatSTL();
- file = new File("standards\\STL\\Alsalirdeclasebien.stl");
+ file = new File("../standards/STL/Alsalirdeclasebien.stl");
is = new FileInputStream(file);
tto = ttff.parseFile(file.getName(), is);
try {
- output = new BufferedOutputStream(new FileOutputStream("prueba.txt"));
+ output = new BufferedOutputStream(new FileOutputStream("test.stl"));
output.write(tto.toSTL());
} finally {
output.close();
View
4 Subtitle Files/src/makejar.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+javac Convert.java
+jar cvfm subtitleConvert.jar manifest.txt Convert.class IOClass.class subtitleFile/*class
View
1  Subtitle Files/src/manifest.txt
@@ -0,0 +1 @@
+Main-Class: Convert
Something went wrong with that request. Please try again.