diff --git a/lib/audio.js b/lib/audio.js index 3904312..de46198 100644 --- a/lib/audio.js +++ b/lib/audio.js @@ -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 = @@ -91,6 +100,7 @@ const createAudioTrack = ({ type, codec, channels, + contentProtection, bitrate, duration, jointObjectCoding = 0, @@ -110,6 +120,7 @@ const createAudioTrack = ({ codec, bitrate: parsedBitrate, size, + protection: contentProtection, language, segments, channels: parsedChannels, @@ -131,6 +142,7 @@ const createAudioTrack = ({ module.exports = { AUDIO_CODECS, parseAudioCodec, + isAudioCodec, createAudioTrack, getDolbyDigitalPlusComplexityIndex, checkIsDescriptive, diff --git a/lib/dash.js b/lib/dash.js index 8fea357..a41cc53 100644 --- a/lib/dash.js +++ b/lib/dash.js @@ -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, @@ -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; const mimeType = representation.get('mimeType'); const contentType = - representation.get('contentType') || mimeType?.split('/')[0]; + codecsType || codecsTyperepresentation.get('contentType') || mimeType?.split('/')[0]; if (!contentType && !mimeType) throw new Error( 'Unable to determine the format of a Representation, cannot continue...', @@ -300,6 +305,7 @@ const parseContentProtection = (contentProtections) => { }; const parseManifest = async (text, url, fallbackLanguage) => { + text = text.replace(/\$.*?(RepresentationID|Number|Time).*?\$/g, "$$$1$$"); const mpd = appendUtils(xml.parse(text)).get('MPD'); const period = mpd.get('Period'); const durationString = @@ -414,6 +420,7 @@ const parseManifest = async (text, url, fallbackLanguage) => { jointObjectCoding: getDolbyDigitalPlusComplexityIndex(supplementalProps), isDescriptive: checkIsDescriptive(accessibilities), + contentProtection: parseContentProtection(contentProtections), bitrate, duration, language, diff --git a/lib/subtitle.js b/lib/subtitle.js index e8e40a0..b9c555d 100644 --- a/lib/subtitle.js +++ b/lib/subtitle.js @@ -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 = @@ -120,6 +129,7 @@ const createSubtitleTrack = ({ module.exports = { parseSubtitleCodec, + isSubtitleCodec, checkIsClosedCaption, checkIsSdh, checkIsForced, diff --git a/lib/video.js b/lib/video.js index 0d8145c..fe25840 100644 --- a/lib/video.js +++ b/lib/video.js @@ -153,6 +153,15 @@ const parseVideoCodec = (codecs) => { ); }; +const isVideoCodec = (codecs) => { + try { + parseVideoCodec(codecs); + return true; + } catch (e) { + return false; + } +}; + const parseDynamicRange = ( codecs, supplementalProps = [], @@ -185,6 +194,7 @@ const parseDynamicRange = ( module.exports = { parseVideoCodec, + isVideoCodec, parseDynamicRange, createVideoTrack, VIDEO_CODECS,