Created
April 26, 2019 09:08
-
-
Save ssadovski007/bb2b64b7ec3916569b0c216f11650198 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// rule for AnyProxy tool (http://anyproxy.io/en/) | |
// support https://github.com/google/shaka-player/issues/1884 investigation | |
const moment = require('moment') | |
const parser = require('xml2json') | |
module.exports = { | |
summary: "manifest-period@start-resets-from-PT0S.js", | |
*beforeSendResponse(requestDetail, responseDetail) { | |
if (requestDetail.url.includes('.mpd') | |
&& requestDetail.requestOptions.method === "GET" | |
&& responseDetail.response.header['Content-Type'] === "application/dash+xml" | |
&& responseDetail.response.statusCode === 200) { | |
let newResponse = Object.assign({}, responseDetail.response) | |
let manifestJson = JSON.parse(parser.toJson(newResponse.body.toString(), {reversible: true})), | |
rootMPD = manifestJson['MPD'], | |
periods = [rootMPD.Period].flat() | |
if (rootMPD.type === "static" | |
&& rootMPD.profiles === "urn:mpeg:dash:profile:isoff-live:2011" | |
&& periods[0]) { | |
let firstPeriodStart = moment.duration(periods[0].start || "PT0S") | |
periods.forEach(p => { | |
p.start = moment.duration(p.start).subtract(firstPeriodStart).toString() | |
}) | |
newResponse.header['X-Proxy-By'] = `AnyProxy: ${this.summary}` | |
newResponse.body = parser.toXml(manifestJson) | |
} | |
return { | |
response: newResponse | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment