Skip to content

ToYonos/subtitles4j

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

subtitles4j

What is it ?

Subtitles4j is a simple library which allows you to parse and manipulate subtitles files.

Which formats are supported ?

For the moment, only SubRip (srt) and Advanced SubStation Alpha (ass).

How to use it ?

Parsing and writting files

You can easily parse, write and convert files thanks to Subtitles4jFactory.

// Getting the factory
Subtitles4jFactory factory = Subtitles4jFactory.getInstance();
Parsing
// From a File
File inputFile = new File("/an/input/file.srt");
// The input type is deducted from the extension
SubtitlesContainer container = factory.fromFile(inputFile);

// From an InputStream
InputStream is = new FileInputStream(inputFile);
// The input type must be provided
container = factory.fromStream(is, SubtitlesType.SRT);
Writing
// To a File
File outputFile = new File("/an/output/file.ass");
factory.toASS(container, outputFile);

// To an OutputStream
FileOutputStream os = new FileOutputStream(outputFile);
factory.toASS(container, os);
Direct conversion
// File to File
factory.toASS(inputFile, outputFile);
		
// InputStream to OutputStream
factory.toASS(is, SubtitlesType.SRT, os);

Content manipulation

The utility class Subtitles4jUtils allows you to perform operation on subtitles files.

Time shifting
// From a File, add 250 ms to every timestamp
Subtitles4jUtils.shift(inputFile, 250);
		
// From an InputStream, remove 150 ms to every timestamp
Subtitles4jUtils.shift(is, SubtitlesType.SRT, os, -150);
Captions removing
// From a File, remove all captions matching the pattern
Subtitles4jUtils.removeCaptions(inputFile, "some pattern");

// From an InputStream, remove all captions matching the pattern
Subtitles4jUtils.removeCaptions(is, SubtitlesType.SRT, os, "some pattern");

About

A simple library, to parse and manipulate subtitles files

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages