Skip to content

Commit

Permalink
Merge pull request #109 from ssnangua/main
Browse files Browse the repository at this point in the history
fix: #106 & #107 &#110
  • Loading branch information
vitalygashkov authored Nov 27, 2024
2 parents 7fb53a1 + 1142165 commit a5d3595
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
12 changes: 12 additions & 0 deletions lib/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ const parseAudioCodec = (codecs) => {
);
};

const isAudioCodec = (codecs) => {
try {
parseAudioCodec(codecs);
return true;
} catch (e) {
return false;
}
};

// https://professionalsupport.dolby.com/s/article/What-is-Dolby-Digital-Plus-JOC-Joint-Object-Coding?language=en_US
const getDolbyDigitalPlusComplexityIndex = (supplementalProps = []) => {
const targetScheme =
Expand Down Expand Up @@ -91,6 +100,7 @@ const createAudioTrack = ({
type,
codec,
channels,
contentProtection,
bitrate,
duration,
jointObjectCoding = 0,
Expand All @@ -110,6 +120,7 @@ const createAudioTrack = ({
codec,
bitrate: parsedBitrate,
size,
protection: contentProtection,
language,
segments,
channels: parsedChannels,
Expand All @@ -131,6 +142,7 @@ const createAudioTrack = ({
module.exports = {
AUDIO_CODECS,
parseAudioCodec,
isAudioCodec,
createAudioTrack,
getDolbyDigitalPlusComplexityIndex,
checkIsDescriptive,
Expand Down
9 changes: 8 additions & 1 deletion lib/dash.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ const xml = require('./xml');
const { parseDuration, isLanguageTagValid } = require('./util');
const {
parseVideoCodec,
isVideoCodec,
parseDynamicRange,
createVideoTrack,
} = require('./video');
const {
parseAudioCodec,
isAudioCodec,
createAudioTrack,
getDolbyDigitalPlusComplexityIndex,
checkIsDescriptive,
} = require('./audio');
const {
parseSubtitleCodec,
isSubtitleCodec,
checkIsClosedCaption,
checkIsSdh,
checkIsForced,
Expand Down Expand Up @@ -77,9 +80,11 @@ const parseBaseUrl = (manifestUrl, mpd, period, representation) => {
};

const parseContentTypes = (representation) => {
const codecs = representation.get('codecs');
const codecsType = isVideoCodec(codecs) ? 'video' : isAudioCodec(codecs) ? 'audio' : isSubtitleCodec(codecs) ? 'text' : null;

Check failure on line 84 in lib/dash.js

View workflow job for this annotation

GitHub Actions / test

Replace `·?·'video'·:·isAudioCodec(codecs)·?·'audio'·:·isSubtitleCodec(codecs)·?·'text'` with `⏎····?·'video'⏎····:·isAudioCodec(codecs)⏎······?·'audio'⏎······:·isSubtitleCodec(codecs)⏎········?·'text'⏎·······`
const mimeType = representation.get('mimeType');
const contentType =
representation.get('contentType') || mimeType?.split('/')[0];
codecsType || codecsTyperepresentation.get('contentType') || mimeType?.split('/')[0];

Check failure on line 87 in lib/dash.js

View workflow job for this annotation

GitHub Actions / test

Replace `·codecsTyperepresentation.get('contentType')·||` with `⏎····codecsTyperepresentation.get('contentType')·||⏎···`

Check failure on line 87 in lib/dash.js

View workflow job for this annotation

GitHub Actions / test

'codecsTyperepresentation' is not defined
if (!contentType && !mimeType)
throw new Error(
'Unable to determine the format of a Representation, cannot continue...',
Expand Down Expand Up @@ -300,6 +305,7 @@ const parseContentProtection = (contentProtections) => {
};

const parseManifest = async (text, url, fallbackLanguage) => {
text = text.replace(/\$.*?(RepresentationID|Number|Time).*?\$/g, "$$$1$$");

Check failure on line 308 in lib/dash.js

View workflow job for this annotation

GitHub Actions / test

Replace `"$$$1$$"` with `'$$$1$$'`
const mpd = appendUtils(xml.parse(text)).get('MPD');
const period = mpd.get('Period');
const durationString =
Expand Down Expand Up @@ -414,6 +420,7 @@ const parseManifest = async (text, url, fallbackLanguage) => {
jointObjectCoding:
getDolbyDigitalPlusComplexityIndex(supplementalProps),
isDescriptive: checkIsDescriptive(accessibilities),
contentProtection: parseContentProtection(contentProtections),
bitrate,
duration,
language,
Expand Down
10 changes: 10 additions & 0 deletions lib/subtitle.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ const parseSubtitleCodec = (codecs) => {
);
};

const isSubtitleCodec = (codecs) => {
try {
parseSubtitleCodec(codecs);
return true;
} catch (e) {
return false;
}
};

const checkIsClosedCaption = (roles = []) => {
for (const role of roles) {
const isClosedCaption =
Expand Down Expand Up @@ -120,6 +129,7 @@ const createSubtitleTrack = ({

module.exports = {
parseSubtitleCodec,
isSubtitleCodec,
checkIsClosedCaption,
checkIsSdh,
checkIsForced,
Expand Down
10 changes: 10 additions & 0 deletions lib/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ const parseVideoCodec = (codecs) => {
);
};

const isVideoCodec = (codecs) => {
try {
parseVideoCodec(codecs);
return true;
} catch (e) {
return false;
}
};

const parseDynamicRange = (
codecs,
supplementalProps = [],
Expand Down Expand Up @@ -185,6 +194,7 @@ const parseDynamicRange = (

module.exports = {
parseVideoCodec,
isVideoCodec,
parseDynamicRange,
createVideoTrack,
VIDEO_CODECS,
Expand Down

0 comments on commit a5d3595

Please sign in to comment.