Skip to content

Commit

Permalink
fix: subtitle codec types
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalygashkov committed Dec 6, 2024
1 parent fb3ac36 commit 51f20a5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
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
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

0 comments on commit 51f20a5

Please sign in to comment.