A lightweight and developer-friendly PHP script to retrieve the direct .m3u8
HLS stream URL for any live Twitch channel. It leverages Twitch's public GraphQL API to generate a valid token and signature for authenticated playback.
- π Generates secure stream access tokens and signatures via Twitch's GQL API
- π₯οΈ Supports browser and CLI usage
- π Returns result as:
- HTTP redirect (for browsers)
- JSON (if
format=json
is passed)
- β Input validation included
- π¦ No dependencies beyond built-in PHP cURL
- PHP 7.0+
php-curl
enabled
Upload script.php
to your web server and access it like so:
GET /script.php?channel=dorozeaxd
This will respond with a Location
redirect to the .m3u8
stream.
Want JSON instead?
GET /script.php?channel=dorozeaxd&format=json
Run from terminal:
php script.php channel=dorozeaxd
To get JSON output:
php script.php channel=dorozeaxd format=json
Name | Required | Description |
---|---|---|
channel |
β Yes | Twitch channel name (e.g., dorozeaxd ) |
format |
β No | Use json for JSON output, otherwise redirects |
{
"success": true,
"channel": "dorozeaxd",
"url": "https://usher.ttvnw.net/api/channel/hls/dorozeaxd.m3u8?...&sig=...&token=..."
}
On error:
{
"success": false,
"error": "Channel not found or offline"
}
- Only works if the channel is currently live
- Output URL is valid for direct streaming (e.g. with
ffmpeg
,VLC
, or in web players) - Twitch may update their GQL schema or validation mechanisms at any time
MIT License
- Originally authored by toxiicdev.net
- Maintained & cleaned up for open source by contributors