Module: WebVTT
- Defined in:
- lib/parser.rb,
lib/webvtt.rb,
lib/segmenter.rb
Defined Under Namespace
Classes: Cue, File, InputError, MalformedFile, Segmenter, Timestamp
Class Method Summary
collapse
Class Method Details
.convert_from_srt(srt_file, output = nil) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/parser.rb', line 7
def self.convert_from_srt(srt_file, output=nil)
if !::File.exists?(srt_file)
raise InputError, "SRT file not found"
end
srt = ::File.read(srt_file)
output ||= srt_file.gsub(".srt", ".vtt")
srt.gsub!(/([0-9]{2}:[0-9]{2}:[0-9]{2})([,])([0-9]{3})/, '\1.\3')
srt.gsub!("\r\n", "\n")
srt = "WEBVTT\n\n#{srt}".strip
::File.open(output, "w") {|f| f.write(srt)}
return File.new(output)
end
|
.read(file) ⇒ Object
3
4
5
|
# File 'lib/parser.rb', line 3
def self.read(file)
File.new(file)
end
|
.segment(input, options = {}) ⇒ Object
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/segmenter.rb', line 3
def self.segment(input, options={})
if input.is_a?(String)
input = File.new(input)
end
if ! input.respond_to?(:to_webvtt)
raise InputError, "Input must be a WebVTT instance or a path"
end
segmenter = Segmenter.new(input, options)
subs = segmenter.split_to_files
playlist = segmenter.generate_playlist(subs)
return [playlist, subs]
end
|