Checking if a Stream is Online/Offline (PHP)
For the past year I have been watching SOOO many streams online. it got to a point where it almost completely replaces my TV view time.
as of 2011 the main streaming sites for video games are Justin.TV, Own3d.TV, Regame.TV.
all of these sites allow you to stream video over RTMP, and have become very popular with many sites and companies embedding such mechanisms to broadcast video on demand, and live streaming of events and games/tournaments.
each site therefor has its own API for developers/site builders to be able to embed things from their streams, and the most basic thing is an ONLINE Indicator.
so my 0.02 cents here will be to list functions that will enable you to have an Online indicator for each of the above, hoping that its saves some time…
for the examples, I used PHP for some quick and dirty coding.
for Justin.TV --
//justintv status check
function justinTVcheck ($channelName) {
$channelName = strtolower($channelName);
$json_file = http://api.justin.tv/api/stream/list.json?channel=" . $channelName;
$json = file_get_contents($json_file);
if (strpos($json, 'name')) {
return (1); //online
} else {
return (0); //offline
}
}
for own3d.TV --
//own3d status check
function ownedTVcheck ($channelName) {
$request = 'http://api.own3d.tv/liveCheck.php?live_id=';
$arg = $channelName;
$session = curl_init($request.$arg);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($session);
curl_close($session);
if (preg_match("/true/",$response, $result)) {
return (1); //online
} else {
return (0); //offline
}
}
for regame.TV --
//regame status check
function regameTVcheck ($channelName) {
$url = 'http://www.regame.tv/liveview_xml_multiple.php?stream_ids=';
$arg = $channelName;
$xml = simplexml_load_file($url.$arg);
$status=$xml->stream->online;
if (strcmp($status,'true')==0) {
return (1); //online
} else {
return (0); //offline
}
}
pretty straight forward, functions return 1 if the stream is online, and 0 if not. and should be easily transferable to other languages.




 

so you watch starcraft instead of posting in the blog ?:(
Posted by
Anonymous |
8:02 PM
i admit i have been quite inactive in this blog due to the high demand of time of my current job. but ill try to post more :)
happy new year !
Posted by
barry |
8:06 PM