m3u8 is a Python library designed to parse M3U8 HTTP Live Streaming (HLS) playlists. It allows loading playlists from URIs, file paths, or strings, and provides access to segments, streams, and other HLS tag information. The library is actively maintained, with its current version being 6.0.0, and receives regular updates to support new HLS specifications and bug fixes.
pip install m3u8Verified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to load an M3U8 playlist from a string using `m3u8.loads()` and access its basic properties like target duration and individual segments. An commented-out section shows how to load directly from a URL using `m3u8.load()` for live HLS streams.
Ensure your code handles `BITRATE` values as integers. If string representation is required, cast it explicitly: `str(playlist.playlists[0].stream_info.bandwidth['BITRATE'])`.
Adjust code to expect and handle `playlist.target_duration` as an integer. Cast if other types are explicitly needed: `float(playlist.target_duration)`.
Upgrade your Python environment to 3.7 or higher. Review and update any Python 2 specific code if migrating an older project.
Always prefer `segment.absolute_uri` when constructing URLs for segments or keys to ensure correct resolution against the playlist's `base_uri`.
Pass a `custom_tags_parser` function to `m3u8.load()` or `m3u8.loads()`. This function will be called for each line of the playlist, allowing you to process and store custom tag data.