PHP Class SrtParser\srtFile

显示文件 Open project: delphiki/subrip-file-parser

Public Methods

Method Description
__construct ( $_filename, $_encoding = '' ) srtFile constructor
build ( boolean $stripTags = false, $stripBasic = false, array $replacements = [] ) Builds file content (file_content[_notag])
buildPart ( integer $from, integer $to, boolean $stripTags = false, $stripBasic = false, array $replacements = [] ) Builds file content (file_content[_notag]) from entry $from to entry $to
calcStats ( ) Computes statistics regarding reading speed
changeFPS ( float $old_fps, float $new_fps ) Converts timecodes based on the specified FPS ratio
cp1252_to_utf8 ( string $text ) Converts Windows-1252 (CP-1252) to UTF-8
deleteSub ( integer $_index ) Deletes a cue
detect_utf_encoding ( string $text ) Detects UTF encoding
getEncoding ( )
getFileContent ( ) Getters
getFilename ( )
getSub ( $idx )
getSubCount ( )
getSubs ( )
isValid ( string $_filename ) : boolean Checks if the file is a valid SubRip file
isWebVTT ( )
mergeSrtFile ( srtFile $_srtFile ) Imports subtitles from another srtFile object
save ( string $filename = null, boolean $stripTags = false ) Saves the file
saveStats ( string $filename, $output = 'html' ) Saves statistics as XML file
searchCueFromTimecode ( $_start )
searchWord ( string $word, boolean $case_sensitive = false, boolean $strict = false ) : array Searchs a word/expression and returns ids of the matched entries
setWebVTT ( $_is_WebVTT = true )
shift ( $time, integer $startIndex = false, integer $endIndex = false ) Shifts a range of subtitles a specified amount of time.
sortSubs ( ) Sorts srtFile entries
sync ( integer $startIndex, integer $startTime, integer $endIndex, integer $endTime, boolean $syncLast = true ) : boolean Auto syncs a range of subtitles given their first and last correct times.

Private Methods

Method Description
convertEncoding ( ) Converts file content to UTF-8
getPercent ( $nb ) : integer
loadContent ( ) Loads file content and detect file encoding if undefined
parseSubtitles ( ) Parses file content into srtFileEntry objects

Method Details

__construct() public method

srtFile constructor
public __construct ( $_filename, $_encoding = '' )

build() public method

Builds file content (file_content[_notag])
public build ( boolean $stripTags = false, $stripBasic = false, array $replacements = [] )
$stripTags boolean If true, {\...} tags will be stripped
$replacements array

buildPart() public method

Builds file content (file_content[_notag]) from entry $from to entry $to
public buildPart ( integer $from, integer $to, boolean $stripTags = false, $stripBasic = false, array $replacements = [] )
$from integer Id of the first entry
$to integer Id of the last entry
$stripTags boolean If true, {\...} tags will be stripped
$replacements array

calcStats() public method

Computes statistics regarding reading speed
public calcStats ( )

changeFPS() public method

Converts timecodes based on the specified FPS ratio
public changeFPS ( float $old_fps, float $new_fps )
$old_fps float
$new_fps float

cp1252_to_utf8() public static method

Converts Windows-1252 (CP-1252) to UTF-8
public static cp1252_to_utf8 ( string $text )
$text string The string to be converted

deleteSub() public method

Deletes a cue
public deleteSub ( integer $_index )
$_index integer

detect_utf_encoding() public static method

Detects UTF encoding
public static detect_utf_encoding ( string $text )
$text string

getEncoding() public method

public getEncoding ( )

getFileContent() public method

Getters
public getFileContent ( )

getFilename() public method

public getFilename ( )

getSub() public method

public getSub ( $idx )

getSubCount() public method

public getSubCount ( )

getSubs() public method

public getSubs ( )

isValid() public static method

Checks if the file is a valid SubRip file
public static isValid ( string $_filename ) : boolean
$_filename string The path to the file
return boolean

isWebVTT() public method

public isWebVTT ( )

mergeSrtFile() public method

Imports subtitles from another srtFile object
public mergeSrtFile ( srtFile $_srtFile )
$_srtFile srtFile another srtFile object

save() public method

Saves the file
public save ( string $filename = null, boolean $stripTags = false )
$filename string
$stripTags boolean If true, use file_content_notag instead of file_content

saveStats() public method

Saves statistics as XML file
public saveStats ( string $filename, $output = 'html' )
$filename string

searchCueFromTimecode() public method

public searchCueFromTimecode ( $_start )

searchWord() public method

Searchs a word/expression and returns ids of the matched entries
public searchWord ( string $word, boolean $case_sensitive = false, boolean $strict = false ) : array
$word string
$case_sensitive boolean
$strict boolean
return array containing ids of entries

setWebVTT() public method

public setWebVTT ( $_is_WebVTT = true )

shift() public method

Shifts a range of subtitles a specified amount of time.
public shift ( $time, integer $startIndex = false, integer $endIndex = false )
$time The time to use (ms), which can be positive or negative.
$startIndex integer The subtitle index the range begins with.
$endIndex integer The subtitle index the range ends with.

sortSubs() public method

Sorts srtFile entries
public sortSubs ( )

sync() public method

The subtitles are first shifted to the first subtitle's correct time, and then proportionally adjusted using the last subtitle's correct time. Based on gnome-subtitles (https://git.gnome.org/browse/gnome-subtitles/)
public sync ( integer $startIndex, integer $startTime, integer $endIndex, integer $endTime, boolean $syncLast = true ) : boolean
$startIndex integer The subtitle index to start the adjustment with.
$startTime integer The correct start time for the first subtitle.
$endIndex integer The subtitle index to end the adjustment with.
$endTime integer The correct start time for the last subtitle.
$syncLast boolean Whether to sync the last subtitle.
return boolean Whether the subtitles could be adjusted