Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/1c7/subtitle-time
[npm package] Parse time format in SRT, VTT and ASS. For example, turn '00:01:01,000' into 61 (second) or vise versa.
https://github.com/1c7/subtitle-time
ass-format srt srt-subtitles subtitle subtitles-parsing time vtt
Last synced: 5 days ago
JSON representation
[npm package] Parse time format in SRT, VTT and ASS. For example, turn '00:01:01,000' into 61 (second) or vise versa.
- Host: GitHub
- URL: https://github.com/1c7/subtitle-time
- Owner: 1c7
- Created: 2020-02-14T10:27:47.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-02-22T08:25:14.000Z (almost 4 years ago)
- Last Synced: 2024-12-01T02:13:46.687Z (23 days ago)
- Topics: ass-format, srt, srt-subtitles, subtitle, subtitles-parsing, time, vtt
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/subtitle-time
- Size: 126 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# subtitle-time
[English Readme](./README-en.md)专门处理字幕时间,可以处理 SRT, VTT 和 ASS 的时间.
## 安装
```bash
npm i subtitle-time
```## 引入
```javascript
const { SubtitleTime } = require('subtitle-time')
```## 使用例子
### 秒 -> SRT
```javascript
let t = new SubtitleTime(61, 'second');
t.to('srt'); // '00:01:01,000'
```### ASS -> 秒
```javascript
let t = new SubtitleTime('0:01:15.50', 'ass');
t.to('second'); // 75.50
```### 秒 -> VTT
```javascript
let t = new SubtitleTime(61, 'second');
t.to('vtt'); // '00:01:01.000'
```### 秒 -> ASS
```javascript
let t = new SubtitleTime(61, 'second');
t.to('ass'); // '0:01:01.00'
```### SRT -> VTT
```javascript
let t = new SubtitleTime('00:01:01,000', 'srt');
t.to('vtt'); // '00:01:01.000'
```### 测试
```bash
npm test
```## 这个库为什么存在?
1. 我需要转换字幕的时间格式,比如把 `5` (秒)转成 SRT `00:00:05,000`
2. dayjs, moment.js 等其他 JS 时间库用不了
3. npm 上没有解决这个问题的工具