module Subtitles

Overview

Common methods shared between the very similar SSA and ASS formats.

Extended Modules

Defined in:

caption.cr
meta.cr
style.cr
format.cr
format/substation.cr
format/ssa.cr
format/ass.cr
format/json.cr
format/srt.cr
config.cr
subtitles.cr

Constant Summary

Formats = {:SSA, :ASS, :SRT, :JSON}

Instance Method Summary

Instance Method Detail

def by_extension(file : File) : Format.class? #

Detect the filetype of the given file by its extension rather than its contents


[View source]
def by_extension(filepath : String) : Format.class? #

Detect the filetype of the given filepath by its extension rather than its contents


[View source]
def by_extension!(file) : Format.class #

The same as #by_extension, except raises on failure rather than returning nil


[View source]
def convert(content : IO, to format : Format.class, resync resync_option : Time::Span? = nil) #

At once -- parse, resync, and output a converted subtitle


[View source]
def detect(content : IO) : Format.class? #

Detect what filetype the given IO contains, if any. This cycles through all available types and calls #detect on them. If a filetype is detected, the class of that type will be returned for instantiation. If none of the available filetypes match the given IO, nil will be returned.

For example:

if subs = Subtitles.detect(content).try &.new(content)... # subs is a new instance of some Format
else
  # subs is nil
end

[View source]
def detect(*, file filepath : String) : Format.class? #

Opens the given file, calls #detect(IO) on the open file, closes it, and returns the result.


[View source]
def filter_styles(from captions : Captions) : Array(Caption) #

Accepts an Array(Caption|Style) and returns an Array(Caption)


[View source]
def parse(content : IO) : Captions? #

parse the given IO into a Caption object, if possible, or return nil.


[View source]
def parse(*, filepath : String) #

parse the given filepath into a Caption object, if possible, or return nil.


[View source]
def parse!(content) : Captions #

Parse the given IO into a Caption object, or raise an exception.


[View source]
def resync(captions : Array(Caption), offset : Time::Span) #

Resync the given Captions' timestamps. That is, increase or decrease the start and end time of every dispalyed caption by a given amount of time.


[View source]
def resync(captions : Array(Caption), offset : Number, frame_rate : Time::Span = (1 / 24_f32).seconds, ratio = 1_f64) #

Resync the given Captions' timestamps. That is, increase or decrease the start and end time of every dispalyed caption by a given number of frames.


[View source]
def resync(captions : Array(Caption), &block : ::Tuple(Time::Span, Time::Span) -> ::Tuple(Time::Span, Time::Span)) #

Resync the given Captions' timestamps. That is, increase or decrease the start and end time of every dispalyed caption by the amount of time returned from the block.

A block attacked to this method MUST return a Tuple of two values, each of which is a Time::Span. It also must accept two parameters, which are the start and end times of each caption in the list. For example, to make every subtitle 10 milliseconds later, you could do

Subtitles.resync captions do |start, end_time|
  { start + 10.milliseconds, end_time + 10.milliseconds }
end

[View source]