Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed typings for subtitle codec, exposed SUBTITLE_CODECS enum #124

Merged
merged 5 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dasha.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const {
filterByLanguages,
filterByChannels,
} = require('./lib/track');
const { SUBTITLE_CODECS } = require('./lib/subtitle');

const parse = (text, url, fallbackLanguage) => {
if (text.includes('<MPD'))
Expand All @@ -24,4 +25,5 @@ module.exports = {
filterByCodecs,
filterByLanguages,
filterByChannels,
SUBTITLE_CODECS,
};
2 changes: 2 additions & 0 deletions lib/dash.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ const parseLanguage = (representation, adaptationSet, fallbackLanguage) => {
};

const identifierPattern = /\$([A-z]*)(?:(%0)([0-9]+)d)?\$/g;

const identifierReplacement =
(values) => (match, identifier, format, width) => {
if (match === '$$') return '$';
Expand All @@ -147,6 +148,7 @@ const identifierReplacement =
if (value.length >= width) return value;
return value.padStart(width, '0');
};

const buildSegmentUrl = (template, fields) => {
return template.replace(identifierPattern, identifierReplacement(fields));
};
Expand Down
1 change: 1 addition & 0 deletions lib/subtitle.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const createSubtitleTrack = ({
};

module.exports = {
SUBTITLE_CODECS,
parseSubtitleCodec,
tryParseSubtitleCodec,
checkIsClosedCaption,
Expand Down
30 changes: 10 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "dasha",
"version": "3.1.3",
"version": "3.1.4",
"description": "Streaming manifest parser",
"files": [
"dist",
"dasha.js",
"lib",
"types"
],
"scripts": {
Expand All @@ -14,8 +15,7 @@
"build": "tsup dasha.js --format esm,cjs",
"prepublishOnly": "npm run build"
},
"main": "./dist/dasha.js",
"module": "./dist/dasha.mjs",
"main": "dasha.js",
"types": "./types/dasha.d.ts",
"repository": {
"type": "git",
Expand Down Expand Up @@ -55,13 +55,13 @@
"m3u8-parser": "^7.2.0"
},
"devDependencies": {
"@eslint/js": "^9.15.0",
"@types/node": "^22.10.0",
"eslint": "^9.15.0",
"@eslint/js": "^9.16.0",
"@types/node": "^22.10.1",
"eslint": "^9.16.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"globals": "^15.12.0",
"prettier": "^3.4.1",
"globals": "^15.13.0",
"prettier": "^3.4.2",
"tsup": "^8.3.5",
"typescript": "^5.7.2"
}
Expand Down
15 changes: 8 additions & 7 deletions types/dasha.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,14 @@ export interface AudioTrack extends Track {
}

export type SubtitleCodec =
| 'SRT'
| 'SSA'
| 'ASS'
| 'TTML'
| 'VTT'
| 'STPP'
| 'WVTT';
| 'SRT' // https://wikipedia.org/wiki/SubRip
| 'SSA' // https://wikipedia.org/wiki/SubStation_Alpha
| 'ASS' // https://wikipedia.org/wiki/SubStation_Alpha#Advanced_SubStation_Alpha=
| 'TTML' // https://wikipedia.org/wiki/Timed_Text_Markup_Language
| 'VTT' // https://wikipedia.org/wiki/WebVTT
// MPEG-DASH box-encapsulated subtitle formats
| 'STPP' // https://www.w3.org/TR/2018/REC-ttml-imsc1.0.1-20180424
| 'WVTT'; // https://www.w3.org/TR/webvtt1

export interface SubtitleTrack extends Track {
type: 'text';
Expand Down
Loading