I got a script which is looking up if a user is either ONLINE or OFFLINE. I stated 2 behaviors for now, PRINTF('Online')
and PRINTF('OFFLINE')
just to see everything works as it should.
Now to my question,
I would like to have if user is OFFLINE, it should embed his youtube channel instead of just printing OFFLINE. How can I code this?
<?php
$channel = "CHANNEL-NAME";
$json_file = @file_get_contents("http://api.justin.tv/api/stream/list.json?".
"channel={$channel}", 0, null, null);
$json_array = json_decode($json_file, true);
if( array_key_exists( '0', $json_array )
&& array_key_exists( 'channel', $json_array[0] )
&& $json_array[0]['name'] == "live_user_{$channel}" )
{
$channelTitle = $json_array[0]['channel']['title'];
$title = $json_array[0]['channel']['status'];
printf('Online');
}
else
{
printf('Offline');
}
?>