https://github.com/san650/subtitle
Elixir library to parse subtitle files (SubRip .srt files or MicroDVD .sub files)
https://github.com/san650/subtitle
elixir microdvd subrip subtitles
Last synced: about 1 year ago
JSON representation
Elixir library to parse subtitle files (SubRip .srt files or MicroDVD .sub files)
- Host: GitHub
- URL: https://github.com/san650/subtitle
- Owner: san650
- License: other
- Created: 2019-09-15T01:12:22.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-09-16T12:57:49.000Z (almost 7 years ago)
- Last Synced: 2025-02-08T18:31:27.411Z (over 1 year ago)
- Topics: elixir, microdvd, subrip, subtitles
- Language: Elixir
- Homepage:
- Size: 29.3 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Subtitle
Elixir library to parse subtitle files.
Current supported formats:
* SubRip subtitle files (`.srt`).
* MicroDVD subtitle fiels (`.txt` or `.sub`).
## Installation
Add `subtitle` to your list of dependencies in `mix.exs`:
```elixir
defp deps do
[{:subtitle, github: "https://github.com/san650/subtitle"}]
end
```
Install via `mix deps.get`.
## Usage
After installing just write a little Elixir function:
```elixir
# Returns a stream of %Subtitle.Frame{} structs
Subtitle.from_file("lord_of_the_rings.srt")
|> Enum.to_list
```
Streaming subtitles from any `IO.stream`
```elixir
subtitle = """
1
00:00:00,000 --> 00:00:01,000
Hello, world!
2
00:00:02,000 --> 00:00:03,000
This is the second frame
3
00:00:04,000 --> 00:00:05,000
This is the third line
"""
{:ok, file} = StringIO.open(subtitle, [:line])
file
|> IO.stream(:line)
|> Subtitle.SubRip.stream()
|> Enum.take(1)
# => %Subtitle.Frame{
# index: 1,
# begin_time: ~T[00:00:00.000000],
# end_time: ~T[00:00:01.000000],
# caption: "Hello, world!"
# }
```
## License
`Subtitle` is licensed under the MIT license.
See [LICENSE](./LICENSE) for the full license text.