Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

monocursive/srt_parser

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.