Download the PHP package chaostangent/php-ass without Composer
On this page you can find all versions of the php package chaostangent/php-ass. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download chaostangent/php-ass
More information about chaostangent/php-ass
Files in chaostangent/php-ass
Package php-ass
Short Description A library for reading Advanced Sub Station Alpha subtitle files
License Creative Commons Attribution-ShareAlike 3.0
Homepage http://github.com/johnnoel/php-ass
Informations about the package php-ass
php-ass
A library for reading Advanced Substation Alpha subtitle files.
Specification
The ASS file specs are available in various parts in various places:
- Wikipedia has a good overview
- The original format in Microsoft Word .doc format
- How the files are incorporated into Matroska (MKV) files
In short: ASS files are an advanced version of the original SSA (Sub Station Alpha) subtitle files and include several improvements in terms of styling and effects.
A valid script file starts with [Script Info] and contains several sections in INI style format.
Quick start
Install using composer:
Then start using:
Parts
Script
The ChaosTangent\ASS\Script
class represents the root object of an ASS script.
You instantiate a Script
with the content of a script as well as an optional filename:
Once instantiated you can check whether what's been passed looks like a valid ASS script:
This only checks the first few bytes for the "[Script Info]" string, it doesn't guarantee that a passed script is valid or readable.
To parse the passed script:
This will go through the content passed when creating the script and parse it into blocks and lines.
To get the current collection of blocks, you can call getBlocks()
or treat the script as an iterator:
To check if a script has a block:
Block
Every ASS script is comprised of a few different blocks. The ChaosTangent\ASS\Block\Block
abstract class represents one of these blocks.
At the moment php-ass supports the following blocks:
- Script Info as
ChaosTangent\ASS\Block\ScriptInfo
- V4+ Styles as
ChaosTangent\ASS\Block\Styles
- Events as
ChaosTangent\ASS\Block\Events
Any other kind of block (e.g. "Aegisub Project Garbage", "Fonts") are silently ignored when parsing.
ScriptInfo
blocks provide functions for common fields:
Otherwise you can just treat blocks as containers for lines. You can use array access to get a specific line:
Or treat the block as an iterator:
Line
Lines are the core of a script file. Any line that isn't a comment (not to be confused with a comment event line) uses the base class ChaosTangent\ASS\Line\Line
.
Lines in some blocks are mapped according to a special "Format" line. These are represented by ChaosTangent\ASS\Line\Format
. Format lines have a special getMapping()
method that returns an array that can be used to parse other lines.
If all of this sounds a bit complicated, you mostly won't have to worry about it if parsing files as it's all taken care of for you. All it means is that for Dialogue and Style lines, you can use methods to get the different parts:
Dialogue lines also have an extra method for getting the text of a line without any style override codes in it:
For all lines you can use the generic getKey()
and getValue()
methods which will return the key of the line (e.g. "Dialogue", "Format", "Style") and its unparsed value:
If you only want lines of a specific type, just do an instanceof
check when iterating through:
Tests
There is a growing test suite for this library that you can use phpunit to validate against. Any esoteric or known broken scripts would be a welcome addition.
TODO
- Allow reading of embedded information (images, fonts etc.)
- Allow construction and writing of ASS files
- More line type support
- More block type support
- Test completion