videojs / mpd-parser

https://videojs.github.io/mpd-parser/
Other
79 stars 54 forks source link

Wrong resolvedUri #117

Open Caringor opened 3 years ago

Caringor commented 3 years ago

Hi, I'm trying to parse SlingTV manifest, however the uri and resolvedUri in the returned parser manifest seems to be wrong.

{ uri: 'audio/stereo/192/$Number%08x$.m4s', timeline: 1, duration: 2.048, resolvedUri: 'http://p-cdn1-c-cg14-linear-cbd46b77.movetv.com/15807/live/CNNHD-DYN/6986bd324cdc11ebb62f0025b5472115/audio/stereo/192/$Number%08x$.m4s', map: [Object], number: 2877 }

The real url should be: http://p-cdn1-c-cg14-linear-cbd46b77.movetv.com/15807/live/CNNHD-DYN/6986bd324cdc11ebb62f0025b5472115/audio/stereo/192/00000ffc.m4s

example.mpd.txt

gkatsev commented 3 years ago

I think it's because we only expect BaseURL elements to be children the MPD element rather than inside a Period.

Jssly commented 2 years ago

@gkatsev

I got the same issue on this website. My research result is that it's a regex issue here: https://github.com/videojs/mpd-parser/blob/main/src/segment/segmentTemplate.js#L6

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

In this example the regex is $Number%08x$, not match to identifierPattern. The code should be

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

another issue is the number need to be set as hex format in function https://github.com/videojs/mpd-parser/blob/main/src/segment/segmentTemplate.js#L44

here is my solution: export const identifierReplacement = (values) => (match, identifier, format, width, base) => { if (match === '$$') { // escape sequence return '$'; }

if (typeof values[identifier] === 'undefined') { return match; }

let value = '' + values[identifier];

if (identifier === 'RepresentationID') { // Format tag shall not be present with RepresentationID return value; }

if (!format) { width = 1; } else { width = parseInt(width, 10); }

if(base ==='x') { value = parseInt(value).toString(16) }

if (value.length >= width) { return value; }

return ${(new Array(width - value.length + 1)).join('0')}${value}; };