matroska-subtitles
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "matroska-subtitles", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Transform stream for parsing embedded .mkv subtitles.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -18,9 +18,70 @@ # matroska-subtitles [![npm][npm-img]][npm-url] [![dependencies][dep-img]][dep-url] [![license][lic-img]][lic-url] | ||
## documetation | ||
The `data` event of the stream will emit an array that determines the type of the data. | ||
When a new subtitle track is encountered a *track number* and *language* is emitted: | ||
```javascript | ||
data = [ 'new', { track: <track number>, language: <string> } ] | ||
``` | ||
Subsequently a specific subtitle track will emit data of this form: | ||
```javascript | ||
data = [ <track number>, { text: <string>, time: <ms>, duration: <ms> } ] | ||
``` | ||
## example | ||
The following is a basic example of extracting subtitle tracks of an mkv: | ||
```javascript | ||
var todo = true | ||
const fs = require('fs') | ||
const matroskaSubtitles = require('matroska-subtitles') | ||
var tracks = new Map() | ||
var subs = matroskaSubtitles() | ||
subs.on('data', function (data) { | ||
if (data[0] === 'new') { | ||
var key = data[1].track | ||
tracks.set(key, { | ||
language: data[1].language, | ||
subtitles: [] | ||
}) | ||
} else { | ||
var key = data[0] | ||
var subtitle = data[1] | ||
tracks.get(key).subtitles.push(subtitle) | ||
} | ||
}) | ||
subs.on('end', function () { | ||
tracks.forEach((track) => console.log(track)) | ||
}) | ||
fs.createReadStream('Sintel.2010.720p.mkv').pipe(subs) | ||
``` | ||
> Notice that this example doesn't take advantage of streaming since the subtitles first are being outputted when the stream ends. | ||
### response | ||
The response of this example would look like this: | ||
```javascript | ||
{ language: 'eng', | ||
subtitles: | ||
[ { text: 'This blade has a dark past.', | ||
time: 107250, | ||
duration: 1970 }, | ||
{ text: 'It has shed much innocent blood.', | ||
time: 111800, | ||
duration: 4000 }, | ||
{ text: 'You\'re a fool for traveling alone,\r\nso completely unprepared.', | ||
time: 118000, | ||
duration: 3450 } ] } | ||
``` | ||
> Note that the `language` might be `undefined` if the mkv track has not specified it. | ||
## contributing | ||
This is still a work in progress. | ||
@@ -27,0 +88,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7418
93