A node.js module for creating m3u / m3u8 files. Supported dialects are m3u, extended m3u and http live streaming m3u.
This module is still new, but I'm going to use it in production over at transloadit.com next.
npm install m3u
The default Writer
class can be used to create basic m3u files:
var writer = require('m3u').writer();
// A comment.
writer.comment('I am a comment');
// An empty line.
writer.write(); // blank line
// A playlist item, usually a path or url.
writer.file('foo.mp3');
console.log(writer.toString());
The ExtendedWriter
supports all methods of the normal Writer
, as well as
additional capabilities defined by the extended m3u format.
var writer = require('m3u').extendedWriter();
// Adds a playlist item preceeded by an optional EXTINF tag for the duration.
// and title of the item.
writer.file('bar.mp3');
writer.file('bar.mp3', 23);
writer.file('bar.mp3', 23, 'Artist - Title');
console.log(writer.toString());
The HttpLiveStreamingWriter
supports all methods of the ExtendedWriter
, as
well as additional capabilities defined by Apple:
var writer = require('m3u').httpLiveStreamingWriter();
// EXT-X-TARGETDURATION: Maximum media file duration.
writer.targetDuration(10);
// EXT-X-MEDIA-SEQUENCE: Sequence number of first file (optional).
// (optional)
writer.mediaSequence(0)
// EXT-X-PROGRAM-DATE-TIME: The date of the program's origin, optional.
// (optional)
writer.programDateTime('2011-04-11T21:24:06Z');
// EXT-X-ALLOW-CACHE: Set if the client is allowed to cache this m3u file.
// (optional)
writer.allowCache(true);
writer.allowCache(false);
// EXT-X-PLAYLIST-TYPE: Provides mutability information about the m3u file.
// (optional)
writer.playlistType('EVENT');
writer.playlistType('VOD');
// EXT-X-ENDLIST: Indicates that no more media files will be added to the m3u file.
// (optional)
writer.endlist();
// EXT-X-VERSION: Indicates the compatibility version of the Playlist file.
// (optional)
writer.version(3);
// Adds a playlist as the next item preceeded by an EXT-X-STREAM-INF tag.
writer.playlist('another.m3u', {
bandwidth: 3000000, // required
programId: 1,
codecs: ['avc1.42001e', 'mp4a.40.34'],
resolution: '640x480',
});
// EXT-X-DISCONTINUITY: Indicates that the player should expect the next video segment to be a different resolution or have a different audio profile than the last.
writer.discontinuity();
console.log(writer.toString());
I don't have plans for more features at this point, except bug fixes.
Stuff I probably won't have time to do myself, and would love to get patches for:
- Implement the ability to read m3u files
- Support node.js's writeable stream interface for the writers
HttpLiveStreamingWriter#key()
(EXT-X-KEY)- Support JS date objects for
HttpLiveStreamingWriter#programDateTime()
node-m3u is licensed under the MIT license.