- file_get_contents: documentation ( source)
- json_decode: documentation ( source)
- rawurlencode: documentation ( source)
- sprintf: documentation ( source)
<?php
$stream = 'monstercat';
$url = sprintf('https://api.twitch.tv/api/channels/%s/access_token/', $stream);
$page = file_get_contents($url);
$json = json_decode($page, true);
$token = $json['token'];
$sig = $json['sig'];
echo 'http://usher.twitch.tv/api/channel/hls/' . $stream . '.m3u8?player=twitchweb&token=' . rawurlencode($token) . '&sig=' . $sig;