hlx-url-rewriter
A transform stream to modify URLs contained in HLS playlists
Features
- Being used with other
hls-streams
objects, it provides a functionality to filter every playlists and rewrite the urls in them based on the rules
.
Install
Usage
const {createReadStream} = require('hlx-file-reader');
const {createUrlRewriter} = require('hlx-url-rewriter');
const {createTerminator} = require('hlx-terminator')
const src = createReadStream('https://foo.bar/sample.m3u8');
const rewrite = createUrlRewriter(urlStr => {
const url = new URL(urlStr);
return url.pathname;
});
const dest = createTerminator();
src.pipe(rewrite).pipe(dest)
.on('data', data => {
console.log(data.uri);
});
API
The features are built on top of the Node's transform streams.
createUrlRewriter(rules)
Creates a new TransformStream
object.
params
Name | Type | Required | Default | Description |
---|
rules | function | No | internally defined default function (see below) | A function that takes an original url string and returns a modified url string. The function is called asynchronously each time the stream encountered a url line or url attribute in playlists. |
default function
Default behavior is something like below (pseudo code):
function defaultFunc(url) {
if (url is relative) {
return url;
} else {
return `/${url.hostname}/${url.pathname}`;
}
}
return value
An instance of TransformStream
.