module Subtitles
Overview
Common methods shared between the very similar SSA and ASS formats.
Extended Modules
Defined in:
caption.crmeta.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
-
#by_extension(file : File) : Format.class?
Detect the filetype of the given file by its extension rather than its contents
-
#by_extension(filepath : String) : Format.class?
Detect the filetype of the given filepath by its extension rather than its contents
-
#by_extension!(file) : Format.class
The same as
#by_extension
, except raises on failure rather than returning nil -
#convert(content : IO, to format : Format.class, resync resync_option : Time::Span? = nil)
At once -- parse, resync, and output a converted subtitle
-
#detect(content : IO) : Format.class?
Detect what filetype the given IO contains, if any.
-
#detect(*, file filepath : String) : Format.class?
Opens the given file, calls
#detect(IO)
on the open file, closes it, and returns the result. -
#filter_styles(from captions : Captions) : Array(Caption)
Accepts an Array(Caption|Style) and returns an Array(Caption)
-
#parse(content : IO) : Captions?
parse the given IO into a Caption object, if possible, or return nil.
-
#parse(*, filepath : String)
parse the given filepath into a Caption object, if possible, or return nil.
-
#parse!(content) : Captions
Parse the given IO into a Caption object, or raise an exception.
-
#resync(captions : Array(Caption), offset : Time::Span)
Resync the given
Captions
' timestamps. -
#resync(captions : Array(Caption), offset : Number, frame_rate : Time::Span = (1 / 24_f32).seconds, ratio = 1_f64)
Resync the given
Captions
' timestamps. -
#resync(captions : Array(Caption), &block : ::Tuple(Time::Span, Time::Span) -> ::Tuple(Time::Span, Time::Span))
Resync the given
Captions
' timestamps.
Instance Method Detail
Detect the filetype of the given file by its extension rather than its contents
Detect the filetype of the given filepath by its extension rather than its contents
The same as #by_extension
, except raises on failure rather than returning
nil
At once -- parse, resync, and output a converted subtitle
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
Opens the given file, calls #detect(IO)
on the open file, closes it,
and returns the result.
Accepts an Array(Caption|Style) and returns an Array(Caption)
parse the given IO into a Caption object, if possible, or return nil.
parse the given filepath into a Caption object, if possible, or return nil.
Parse the given IO into a Caption object, or raise an exception.
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.
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.
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