PHP Class SrtParser\srtFile

Afficher le fichier Open project: delphiki/subrip-file-parser

Méthodes publiques

Méthode 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

Méthode 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 méthode

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

build() public méthode

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 méthode

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 méthode

Computes statistics regarding reading speed
public calcStats ( )

changeFPS() public méthode

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 méthode

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

deleteSub() public méthode

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

detect_utf_encoding() public static méthode

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

getEncoding() public méthode

public getEncoding ( )

getFileContent() public méthode

Getters
public getFileContent ( )

getFilename() public méthode

public getFilename ( )

getSub() public méthode

public getSub ( $idx )

getSubCount() public méthode

public getSubCount ( )

getSubs() public méthode

public getSubs ( )

isValid() public static méthode

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

isWebVTT() public méthode

public isWebVTT ( )

mergeSrtFile() public méthode

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

save() public méthode

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 méthode

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

searchCueFromTimecode() public méthode

public searchCueFromTimecode ( $_start )

searchWord() public méthode

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
Résultat array containing ids of entries

setWebVTT() public méthode

public setWebVTT ( $_is_WebVTT = true )

shift() public méthode

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 méthode

Sorts srtFile entries
public sortSubs ( )

sync() public méthode

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.
Résultat boolean Whether the subtitles could be adjusted