@mdgate/subtitle 0.6.7 → 0.6.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +139 -9
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,27 +1,157 @@
|
|
|
1
1
|
# @mdgate/subtitle
|
|
2
2
|
|
|
3
|
-
Convert subtitle
|
|
4
|
-
Edge, and browsers. No native addons.
|
|
3
|
+
**Convert subtitle files to Markdown in TypeScript.**
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
`.jss`
|
|
5
|
+
[`@mdgate/subtitle`](https://github.com/mdgate/converters/tree/main/packages/subtitle) reads caption files directly in JavaScript and converts cues into GitHub-Flavored Markdown, without Python, native addons, WASM, or a media player.
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
Handles `.srt`, `.vtt`, `.webvtt`, `.ass`, `.ssa`, `.lrc`, `.sub` (MicroDVD), `.sbv`, `.ttml`, and `.jss`.
|
|
8
|
+
|
|
9
|
+
Works in **Node.js, Cloudflare Workers, Edge runtimes, and browsers**.
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @mdgate/subtitle
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { toMarkdown } from '@mdgate/subtitle';
|
|
17
|
+
|
|
18
|
+
const markdown = await toMarkdown(bytes);
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`bytes` is a `Uint8Array`, so the file can come from a file upload, object storage, an HTTP request, a browser file picker, or anywhere else your application gets bytes.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Why [`@mdgate/subtitle`](https://github.com/mdgate/converters/tree/main/packages/subtitle)
|
|
26
|
+
|
|
27
|
+
Subtitles are already a transcript. Converting them to Markdown lets an agent search, chunk, and cite spoken content without a video pipeline.
|
|
28
|
+
|
|
29
|
+
* **Pure TypeScript**
|
|
30
|
+
* **Subtitles → Markdown locally**
|
|
31
|
+
* **No Python runtime**
|
|
32
|
+
* **No native addons**
|
|
33
|
+
* **No WASM runtime**
|
|
34
|
+
* **Zero third-party runtime dependencies**
|
|
35
|
+
* **Works with raw `Uint8Array` input**
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## What it extracts
|
|
40
|
+
|
|
41
|
+
[`@mdgate/subtitle`](https://github.com/mdgate/converters/tree/main/packages/subtitle) parses cue timing and text, strips format-specific markup, and rebuilds a shared document model.
|
|
42
|
+
|
|
43
|
+
The converter handles subtitle-specific concerns including:
|
|
44
|
+
|
|
45
|
+
* SRT and WebVTT timing
|
|
46
|
+
* ASS / SSA dialogue lines
|
|
47
|
+
* LRC lyrics
|
|
48
|
+
* MicroDVD `.sub`
|
|
49
|
+
* YouTube `.sbv`
|
|
50
|
+
* TTML
|
|
51
|
+
* Jacosub `.jss`
|
|
52
|
+
* italic and other simple emphasis when the format carries it
|
|
53
|
+
|
|
54
|
+
The output is Markdown that can be searched, indexed, chunked, cached, or passed directly to an AI agent.
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Node.js
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import { readFile } from 'node:fs/promises';
|
|
62
|
+
import { toMarkdown } from '@mdgate/subtitle';
|
|
63
|
+
|
|
64
|
+
const bytes = new Uint8Array(await readFile('talk.srt'));
|
|
65
|
+
const markdown = await toMarkdown(bytes);
|
|
66
|
+
|
|
67
|
+
console.log(markdown);
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## Browser
|
|
10
73
|
|
|
11
74
|
```ts
|
|
12
75
|
import { toMarkdown } from '@mdgate/subtitle';
|
|
13
76
|
|
|
77
|
+
const file = input.files![0];
|
|
78
|
+
const bytes = new Uint8Array(await file.arrayBuffer());
|
|
79
|
+
|
|
14
80
|
const markdown = await toMarkdown(bytes);
|
|
15
81
|
```
|
|
16
82
|
|
|
17
|
-
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Cloudflare Workers and Edge runtimes
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
import { toMarkdown } from '@mdgate/subtitle';
|
|
89
|
+
|
|
90
|
+
export default {
|
|
91
|
+
async fetch(request: Request) {
|
|
92
|
+
const bytes = new Uint8Array(await request.arrayBuffer());
|
|
93
|
+
const markdown = await toMarkdown(bytes);
|
|
94
|
+
|
|
95
|
+
return new Response(markdown, {
|
|
96
|
+
headers: {
|
|
97
|
+
'content-type': 'text/markdown; charset=utf-8',
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## Format detection
|
|
107
|
+
|
|
108
|
+
Many subtitle formats can be recognized from their contents. A path hint still helps for ambiguous text files.
|
|
109
|
+
|
|
110
|
+
The path is never used to read a file from disk.
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## Compose it with other file readers
|
|
115
|
+
|
|
116
|
+
[`@mdgate/subtitle`](https://github.com/mdgate/converters/tree/main/packages/subtitle) implements the converter interface from [`@mdgate/core`](https://github.com/mdgate/converters/tree/main/packages/core).
|
|
18
117
|
|
|
19
118
|
```ts
|
|
20
119
|
import { create } from '@mdgate/core';
|
|
21
120
|
import { subtitle } from '@mdgate/subtitle';
|
|
121
|
+
import { text } from '@mdgate/text';
|
|
122
|
+
|
|
123
|
+
const read = create([
|
|
124
|
+
subtitle(),
|
|
125
|
+
text(),
|
|
126
|
+
]);
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
The application still uses one reading interface while each format remains independently installable.
|
|
22
130
|
|
|
23
|
-
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## Need more than subtitles?
|
|
134
|
+
|
|
135
|
+
If your application needs to read many different file types, use the complete converter set:
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
npm install @mdgate/converters
|
|
24
139
|
```
|
|
25
140
|
|
|
26
|
-
|
|
27
|
-
|
|
141
|
+
```ts
|
|
142
|
+
import { toMarkdown } from '@mdgate/converters';
|
|
143
|
+
|
|
144
|
+
const markdown = await toMarkdown(bytes, {
|
|
145
|
+
path: filename,
|
|
146
|
+
});
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
[`@mdgate/subtitle`](https://github.com/mdgate/converters/tree/main/packages/subtitle) is one of the single-format packages in the open-source [`mdgate/converters`](https://github.com/mdgate/converters) project.
|
|
150
|
+
|
|
151
|
+
For AI agents, the same converter architecture can be used to extend `read_file` from text files to real-world document formats.
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## License
|
|
156
|
+
|
|
157
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdgate/subtitle",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.9",
|
|
4
4
|
"description": "mdgate subtitle and caption converter",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"homepage": "https://
|
|
7
|
+
"homepage": "https://convert.mdgate.dev",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "git+https://github.com/mdgate/converters.git",
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"prepublishOnly": "bun run build"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@mdgate/core": "0.6.
|
|
32
|
-
"@mdgate/document": "0.6.
|
|
33
|
-
"@mdgate/utils": "0.6.
|
|
31
|
+
"@mdgate/core": "0.6.9",
|
|
32
|
+
"@mdgate/document": "0.6.9",
|
|
33
|
+
"@mdgate/utils": "0.6.9"
|
|
34
34
|
},
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|