https://github.com/leawind/srt-parser-ts
SubRip Text (SRT) parser
https://github.com/leawind/srt-parser-ts
deno srt subrip subtitle typescript typescript-library
Last synced: about 1 month ago
JSON representation
SubRip Text (SRT) parser
- Host: GitHub
- URL: https://github.com/leawind/srt-parser-ts
- Owner: Leawind
- License: gpl-3.0
- Created: 2025-03-21T08:22:59.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-24T14:53:06.000Z (over 1 year ago)
- Last Synced: 2025-03-24T15:44:37.287Z (over 1 year ago)
- Topics: deno, srt, subrip, subtitle, typescript, typescript-library
- Language: TypeScript
- Homepage: https://jsr.io/@leawind/srt-parser
- Size: 24.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SubRip Text (SRT) Parser
[](https://github.com/LEAWIND/srt-parser-ts)
[](https://jsr.io/@leawind/srt-parser)
[](https://jsr.io/@leawind/srt-parser/doc)
[](https://github.com/Leawind/srt-parser-ts/actions/workflows/deno-test.yaml)
A parser for reading and manipulating [SubRip Text (SRT)](https://en.wikipedia.org/wiki/SubRip) format.
## Features
- Parse SRT files into structured data.
- Manipulate subtitle nodes.
- Convert subtitle data back into SRT format.
- Find subtitles that should be displayed at a specific time.
- Shift subtitle timing by a specified offset.
- Support for negative time values.
- Support for multiple time formats (`hh:mm:ss,mmm`, `hh:mm:ss.mmm`, `mm:ss,mmm`, `mm:ss`, `hh:mm:ss`).
## Usage
For example, we have a SRT file `example.srt` with the following content:
```srt
1
00:00:01,000 --> 00:00:04,000
Hello, world!
```
We can write a script to read the SRT file and manipulate the subtitle nodes:
```typescript
import { type SrtNode, SubRipText } from '@leawind/srt-parser';
// Reformat SRT content
const reformatted: string = SubRipText.reformatFile('example.srt');
// Load SRT from file
const srt: SubRipText = SubRipText.fromFile('./example.srt');
// Manipulate subtitles
srt.shiftTime(1000); // Shift by 1 second
const nodes: SrtNode[] = srt.getNodesAt(3000); // Find all subtitles nodes at 3 seconds
```