Skip to content

toxiicdev/Twitch-M3U

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 

Repository files navigation

πŸŽ₯ Twitch to M3U

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.


✨ Features

  • πŸ” 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

βš™οΈ Requirements

  • PHP 7.0+
  • php-curl enabled

πŸš€ Usage

🌍 Web (GET)

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

Optional: Set Content-Type: application/json header for JSON output


πŸ’» CLI

Run from terminal:

php script.php channel=dorozeaxd

To get JSON output:

php script.php channel=dorozeaxd format=json

πŸ“₯ Parameters

Name Required Description
channel βœ… Yes Twitch channel name (e.g., dorozeaxd)
format ❌ No Use json for JSON output, otherwise redirects

πŸ§ͺ Example JSON Output

{
  "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"
}

🧼 Notes

  • 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

πŸ“„ License

MIT License


πŸ™Œ Credits

  • Originally authored by toxiicdev.net
  • Maintained & cleaned up for open source by contributors

About

A simple PHP script to get Twitch HLS Stream by a channel name

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages