Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

monocursive/srt_parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SrtParser

Elixir package to parse SRT (subtitles) files.

The goal was to be able to edit an SRT file from Elixir and save it back.

This library does not handle reading from a file, it only parses the content of a string.

View documentation

Installation

If available in Hex, the package can be installed by adding srt_parser to your list of dependencies in mix.exs:

def deps do
  [
    {:srt_parser, "~> 0.1.0"}
  ]
end

Usage

Parse an SRT string:

iex> SrtParser.parse("1\\n00:00:00,000 --> 00:00:02,123\\nHello world\\n")
{:ok, [
  %SrtParser.ParsedSubtitle{
    id: 1,
    start_time: 0,
    end_time: 2123,
    time_string: "00:00:00,000 --> 00:00:02,123",
    text: "Hello world"
  }
]}

Get an SRT string from a list of ParsedSubtitle structs:

iex> SrtParser.to_srt!([%SrtParser.ParsedSubtitle{id: 1, start_time: 0, end_time: 2123, time_string: "00:00:00,000 --> 00:00:02,123", text: "Hello world"}])
"1\\n00:00:00,000 --> 00:00:02,123\\nHello world"

Example on how to read an SRT file and parse it:

iex> File.read!("example.srt") |> SrtParser.parse()

Contributing

Feel free to send a pull request if you have any improvements to the library.

If you are considering to add a new feature, please create an issue first to discuss if the feature is a good fit for the project.

I want to keep it minimal and focused, but I know srt files can have a lot of different formats, so I'm open to adding new features.

License

MIT

About

Elixir package to parse SRT (subtitles) files

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages