Overview
Them3u_parser module provides functionality to parse M3U/M3U8 playlist files and extract channel information including metadata, streaming URLs, DRM configuration, and HTTP headers.
Classes
PlaylistItem
Represents a single channel entry from an M3U playlist with all associated metadata and streaming configuration.Attributes
Channel display name (extracted from
#EXTINF line)Streaming URL (HLS, DASH, or direct stream)
Channel logo URL (from
tvg-logo attribute)Channel category/group (from
group-title attribute)Custom User-Agent header for HTTP requests
Cookie string for authentication
Referer header value
DRM license key or license server URL
Additional HTTP headers as key-value pairs
Whether this channel requires DRM (set to True when license_string is present)
Methods
to_json()
Serializes the PlaylistItem to a JSON string.JSON string representation of the object’s
__dict__to_dict()
Converts the PlaylistItem to a dictionary.Dictionary representation of the object’s attributes
from_dict()
Static method to create a PlaylistItem from a dictionary.Dictionary containing PlaylistItem attributes
New PlaylistItem instance with attributes populated from the dictionary
Functions
parse_m3u()
Parses M3U playlist content and extracts channel information.The raw M3U playlist content as a string
List of parsed PlaylistItem objects, one for each channel in the playlist
| Directive | Purpose | Example |
|---|---|---|
#EXTINF | Channel metadata | #EXTINF:-1 tvg-logo="logo.png" group-title="Sports",ESPN |
#EXTVLCOPT | VLC-specific options | #EXTVLCOPT:http-user-agent=Mozilla/5.0 |
#EXTHTTP | Custom HTTP headers (JSON) | #EXTHTTP:{"cookie":"session=abc","user-agent":"Custom"} |
#KODIPROP | Kodi properties (DRM) | #KODIPROP:inputstream.adaptive.license_key=https://license.url |
The parser uses a buffering system to collect metadata lines before encountering the URL line:
- Reads
#EXTINFto extracttvg-logo,group-title, and channel title - Reads
#EXTVLCOPTto extractuser-agentandreferer - Reads
#EXTHTTPto parse JSON headers forcookieanduser-agent - Reads
#KODIPROPto extract DRM license configuration - When a non-comment line (URL) is found, creates PlaylistItem with buffered data
- Handles pipe-separated parameters:
url|User-Agent=...&Referer=...
Special Handling
Pipe-Separated Parameters
The parser supports URL lines with pipe-separated parameters:- Parameters before the pipe are treated as the URL
- Parameters after the pipe are parsed as
key=valuepairs separated by& - Standard headers (
User-Agent,Referer,Cookie) are mapped to specific attributes - Non-standard headers are stored in the
headersdictionary
DRM Detection
When a#KODIPROP:inputstream.adaptive.license_key directive is found:
- The
license_stringattribute is set to the license key/URL - The
is_drmflag is set toTrue - This enables DRM-protected stream playback in Kodi
