Skip to main content
PlaylistTask runs RunPlaylist on a worker thread. It builds a playlist URL from the active server and the subscriber’s credentials, fetches it with up to RETRY_MAX retries and automatic failover across the server sequence, then parses the M3U body and writes the channel list and category list to m.global.

XML component definition

PlaylistTask.xml
<?xml version="1.0" encoding="utf-8" ?>
<component name="PlaylistTask" extends="Task">
  <interface>
    <!-- inputs -->
    <field id="username" type="string" value="" />
    <field id="password" type="string" value="" />
    <!-- outputs -->
    <field id="result"   type="assocarray" />
    <field id="done"     type="boolean"    value="false" />
  </interface>
  <task functionName="RunPlaylist" />
</component>

Input fields

username
String
The subscriber’s username. Must match the credentials used during authentication.
password
String
The subscriber’s password.

Output fields

result
AssocArray
Populated when done becomes true. See the Result object section for all keys.
done
Boolean
Set to true when the task finishes. Observe this field to know when result is ready.

Result object

KeyTypeDescription
successBooleantrue when channels were fetched and parsed successfully
channelsArrayParsed channel objects from GTV_ParseM3U(), each with name, number, url, logo, and group
categoriesArrayUnique category/group strings extracted from the playlist
errorMsgStringLocalised error string on failure
errorCodeIntegerAUTH_REASON_* constant on auth failure, or AUTH_REASON_NONE on success
authReasonIntegerSame as errorCode
rawBodyStringRaw HTTP response body on failure, for debugging
httpCodeIntegerHTTP status code of the last attempt

Error codes

See AuthTask error codes for the full AUTH_REASON_* table. PlaylistTask maps HTTP failures to the same constants.

Function flow

1

Validate credentials

If either username or password is empty, the task sets done = true with errorMsg = "Credenciales vacías" immediately.
2

Resolve server

Reads m.global.activeServer (set by a previous AuthTask or HandshakeTask run). If empty, calls GTV_FindActiveServer() to probe the server list.
3

Build playlist URL

Constructs server + "/auth/" + encUser + "/" + encPass + "/playlist/m3u8/hls" matching PATH_PLAYLIST_TPL.
4

Fetch with retries

Calls GTV_HttpGet(url, TIMEOUT_HTTP) in a loop up to RETRY_MAX (3) times. On a network error (code = -1), advances to the next server in GTV_ServerBuildRequestSequence(). Stops immediately on any other HTTP error code.
5

Classify HTTP failure

Uses GTV_AuthClassifyFailure() to map auth-related HTTP codes to AUTH_REASON_* constants and sets errorMsg accordingly.
6

Parse M3U

Passes resp.body to GTV_ParseM3U(). Logs warnings if any channels were dropped for missing or duplicate channel numbers, or if fallback numbers were assigned.
7

Write global state

On success, writes m.global.channelList and m.global.categories for use by MainScreen.
8

Signal completion

Sets m.top.result and m.top.done = true.

AppConstants values used

ConstantValueUsed for
TIMEOUT_HTTP12000 msHTTP timeout for each playlist fetch attempt
RETRY_MAX3Maximum number of fetch attempts before giving up
PATH_PLAYLIST_TPL"/auth/{user}/{pass}/playlist/m3u8/hls"URL template for the playlist endpoint
AUTH_REASON_*see AuthTaskTyped failure codes written to result.errorCode

Usage example

' Run immediately after AuthTask succeeds
playlistTask = CreateObject("roSGNode", "PlaylistTask")
playlistTask.username = m.credentials.username
playlistTask.password = m.credentials.password

playlistTask.observeFieldScoped("done", "OnPlaylistDone")
playlistTask.control = "RUN"

sub OnPlaylistDone()
    r = m.playlistTask.result
    if r.success
        ' m.global.channelList and m.global.categories are now populated
        m.mainScreen.visible = true
    else
        ShowError(r.errorMsg)
    end if
end sub
On success, m.global.channelList and m.global.categories are written directly by the task. You do not need to copy them out of result.channels — though result.channels contains the same data.

Build docs developers (and LLMs) love