Captive can read subtitles from various formats. Subtitles can be modified and exported to another format as well as JSON. Captive currently supports SRT
and WebVTT
formats.
- Read subtitles
- Convert to another format (SRT, WebVTT)
- Save to file
- Serialize as JSON
Parse subtitles
Subtitles can be read from a file using from_file
and providing a filename
s = Captive::SRT.from_file(filename: 'test.srt')
s = Captive::VTT.from_file(filename: 'test.vtt')
Alternately, subtitles can be parsed from a blob of text if you don't want to load from a file
s = Captive::SRT.from_blob(filename: 'test.srt')
s = Captive::VTT.from_blob(filename: 'test.vtt')
Or to get instantiate an empty captive object simply
s = Captive::SRT.new
s = Captive::VTT.new
Save to File
Subtitles can be saved to a file using save_as
s = Captive::VTT.from_file(filename: 'test.vtt')
s.save_as(filaname: 'output.vtt')
Serializing as JSON
Need to store your subtitle data in a format agnostic way? as_json
is your friend
s = Captive::VTT.from_file(filename: 'test.vtt')
s.as_json
Switch Formats
Subtitles parsed in one format can be converted to another format. Currently, SRT and WebVTT are supported.
s = Captive::SRT.new('test.srt')
vtt = s.as_vtt # Will return a Captive::VTT instance
vtt.save_as(filename: 'conversion.vtt')
Simply add captive
to your Gemfile
gem 'captive'
Or install it yourself with:
$ gem install captive
Captive is lightweight and has no external dependencies.
After cloning the repo, run bundle install
to get the development dependencies. Use bin/console
to spin up an IRB instance with captive loaded.
Bug reports and pull requests are welcome on GitHub at https://github.com/mserran2/captive.
The gem is available as open source under the terms of the MIT License.