Main function
GTV_ParseM3U
The raw M3U playlist string. Returns an empty result immediately if
invalid or "".roAssociativeArray with the following fields:
| Field | Type | Description |
|---|---|---|
channels | Array | Sorted array of channel objects (sorted by number ascending) |
categories | Array | Unique category name strings, in insertion order |
droppedMissingNumber | Integer | Channels skipped because channel-number was absent (strict mode only) |
droppedDuplicateNumber | Integer | Channels skipped because their channel-number was already seen |
fallbackAssigned | Integer | Channels that received an auto-incremented number (lenient mode only) |
Channel object structure
Each element inresult.channels is an roAssociativeArray with these fields:
| Field | Type | Source attribute | Description |
|---|---|---|---|
id | String | tvg-id | Channel identifier from the playlist |
name | String | tvg-name or post-comma | Display name of the channel |
logo | String | tvg-logo | URL to the channel logo image |
group | String | group-title | Category name; defaults to "General" if absent |
number | Integer | channel-number | Channel number used for sorting and contentId |
url | String | Next non-comment line | Normalized stream URL |
contentId | String | Derived from number | String representation of number, used as a unique key |
Strict channel number mode
The parser behaviour is controlled byAppConstants().PARSER_STRICT_CHANNEL_NUMBER (default: true).
| Mode | PARSER_STRICT_CHANNEL_NUMBER | Channels without channel-number |
|---|---|---|
| Strict | true | Dropped; counted in droppedMissingNumber |
| Lenient | false | Assigned a sequential fallback number; counted in fallbackAssigned |
URL normalisation
GTV_NormalizeChannelUrl rewrites non-standard scheme prefixes before the URL is stored:
| Raw scheme | Normalised to | Notes |
|---|---|---|
hls://http://... | http://... | Strips hls:// wrapper |
hls://https://... | https://... | Strips hls:// wrapper |
hls://<host> | http://<host> | Adds http:// when no inner scheme is present |
hlss://https://... | https://... | Strips hlss:// wrapper |
hlss://<host> | https://<host> | Adds https:// when no inner scheme is present |
| Anything else | Unchanged |
Supported M3U format
The parser recognises Extended M3U lines starting with#EXTINF. Attributes must use key="value" or key='value' syntax. The channel name may also be placed after the final comma on the #EXTINF line.
Blank lines and comment lines (starting with
#) between #EXTINF and the stream URL are skipped automatically. Only the first non-blank, non-comment line after #EXTINF is used as the URL.Helper functions
GTV_ExtractAttr(src, attrName)
GTV_ExtractAttr(src, attrName)
Extracts the value of a named attribute from an Handles both double-quoted (
#EXTINF line.") and single-quoted (') values, as well as unquoted values terminated by a space or tab. Returns "" if the attribute is not found.GTV_NormalizeChannelUrl(rawUrl)
GTV_NormalizeChannelUrl(rawUrl)
Rewrites
hls:// and hlss:// scheme prefixes to standard http:// or https:// URLs.GTV_TrimStr(s)
GTV_TrimStr(s)
Strips leading and trailing spaces, tabs, and carriage-return characters from a string.
GTV_SortChannels(arr)
GTV_SortChannels(arr)
Sorts a channel array in ascending order by Returns the same array reference after sorting in place.
channel.number using insertion sort.