Downloads HLS Playlist file and TS chunks. You can use it for content pre-fetching from CDN to Edge Server for your end viewers.
NPM • Documentation • GitHub
⚠️ This package is native ESM and no longer provides a CommonJS export. If your project uses CommonJS, you will have to convert to ESM. Please don't open issues for questions regarding CommonJS / ESM.
⚠️ HLSDownloaderv2.x.x
is no longer maintained and we will not accept any backport requests.
- Retryable
- Promise Based
- Support for HTTP/2
- Overwrite protection
- Support for custom HTTP Headers
- Support for custom HTTP Client
- Bring your own progress bar during download
- Concurrent download segments with multiple http connections
- node >=18.x.x
It is pretty straight forward
# using npm
npm install --save hlsdownloader
# or with yarn
yarn add hlsdownloader
# or pnpm
pnpm install hlsdownloader
destination
field is optional. If destination
is not provided it just fetches the content from origin.
It can also be useful if you want to do content pre-fetching from CDN for your end viewers. If any TS
or m3u8
variant download is failed it continues downloading others and reports after finishing.
It's simple as below with.
import HLSDownloader from 'hlsdownloader';
const options = {
playlistURL: 'http://example.com/path/to/your/playlist.m3u8', // change it
destination: '/tmp', // change it (optional: default '')
concurrency: 10, // change it (optional: default = 1),
overwrite: true, // change it (optional: default = false)
// (optional: default = null
onData: function (data) {
console.log(data); // {url: "<url-just-downloaded>", totalItems: "<total-items-to-download>", path: "<absolute-path-of-download-loation>"}
},
// (optional: default = null
onError: function (error) {
console.log(error); // { url: "<URLofItem>", name: "<nameOfError>", message: "human readable message of error" }
},
};
const downloader = new HLSDownloader(options);
downloader.startDownload().then(response => console.log(response));
ℹ️ Check example.js for working example
// on success
{
total: <number>,
playlistURL: 'your playlist url'
message: 'Downloaded successfully',
}
// on partial download
{
total: <number>,
playlistURL: 'your playlist url',
message: 'Download done with some errors',
errors: [
{
name: 'InvalidPlaylist',
message: 'Playlist parsing is not successful'
url: 'https://cnd.hls-server.test/playlist.m3u8'
}
] // items url that is skipped or could not downloaded for error
}
HLSDownloader supports all Ky API except these options given below
- uri
- url
- json
- form
- body
- method
- setHost
- isStream
- parseJson
- prefixUrl
- cookieJar
- playlistURL
- concurrency
- allowGetBody
- stringifyJson
- methodRewriting
It also disable retry failed request that you can easily override
npm test
To run it on watch mode
npm run test:watch
npm docs:gen
👤 Nur Rony
- Website: nurrony.github.io
- Twitter: @nmrony
- Github: @nurrony
- LinkedIn: @nmrony
Contributions, issues and feature requests are welcome!
Feel free to check issues page. You can also take a look at the contributing guide.
Give a ⭐️ if this project helped you!. I will be grateful if you all help me to improve this package by giving your suggestions, feature request and pull requests. I am all ears!!