<?php
// change to your working directory
chdir('/var/www/sc2');
if(file_exists('lock'))
die('already running...'."\n");
touch('lock');
// config
$email = "your@email.com";
$password = "yourpassword";
// log me in
$timeout = 30;
$stream = fsockopen('www.gomtv.net', 80, $errno, $errstr, $timeout);
$loginStr = "cmd=login&returl=%252F&mb_username=".$email."&mb_password=".$password."&rememberme=1";
$header = "POST /user/loginCheck.php HTTP/1.1\r\n"
."Host:
www.gomtv.net\r\n" ."Connection: Keep-Alive\r\n"
."Content-Type: application/x-www-form-urlencoded\r\n"
."Content-Length: ".strlen($loginStr)."\r\n"
."\r\n"
.$loginStr."\r\n";
if(!$stream){
unlink('lock');
die('network error'."\n");
}
fputs($stream, $header);
$cookiedata = '';
$endHeader = 0;
while(!$endHeader){
$temp = fgets($stream);
if ($temp == "\r\n"){
$endHeader = 1;
break;
} elseif(stristr($temp,'Set-Cookie: ')) {
$exp_temp = explode(';',$temp);
$cookiedata .= str_replace('Set-Cookie: ','',$exp_temp[0]).'; ';
}
}
$cookiedata .= 'setVQ=HQ';
echo $cookiedata;
// get streaming url
fclose($stream);
$stream = fsockopen('www.gomtv.net', 80, $errno, $errstr, $timeout);
$header = "GET /2010gslopens3/live/ HTTP/1.1\r\n"
."Host:
www.gomtv.net\r\n" ."Connection: Keep-Alive\r\n"
."Cookie: ".$cookiedata."\r\n"
."\r\n";
if(!$stream){
unlink('lock');
die('network error'."\n");
}
fputs($stream, $header);
$content = '';
while(!feof($stream)){
$content .= fgets($stream);
}
$next_url =
explode("'",stristr($content,"http://www.gomtv.net/gox/flash_live.php?num=HQ&sn="));
$next_url = $next_url[0];
echo $next_url."\n";
if(!$next_url){
unlink('lock');
die("stream is offline atm"."\n");
}
// TEMPORARY
//$next_url =
"/gox/flash_live.php?num=HQ&sn=732bbcdd4b44f514160&lid=23";
fclose($stream);
// get XML INFO
$stream = fsockopen('www.gomtv.net', 80, $errno, $errstr, $timeout);
$header = "GET ".$next_url." HTTP/1.1\r\n"
."Host:
www.gomtv.net\r\n" ."Connection: Keep-Alive\r\n"
."Cookie: ".$cookiedata."\r\n"
."\r\n";
if(!$stream){
unlink('lock');lukasaeneas
die('network error'."\n");
}
fputs($stream, $header);
$content = '';
while(!feof($stream)){
$content .= fgets($stream);
}
$next_url = explode('"',stristr($content,'http://'));
$next_url = $next_url[0];
if(!$next_url){
unlink('lock');
die("couldn't find video data"."\n");
}
fclose($stream);
echo $next_url;
// FINALLY LOAD STREAM
$parsed = parse_url($next_url);
echo $parsed['host'].':'. $parsed['port'];
$stream = fsockopen($parsed['host'], $parsed['port'], $errno, $errstr,
$timeout);
$header = "GET ".$parsed['path'].'?'.$parsed['query']." HTTP/1.1\r\n"
."Host: ".$parsed['host']."\r\n"
."Connection: Keep-Alive\r\n"
."Cookie: ".$cookiedata."\r\n"
."\r\n";
if(!$stream){
unlink('lock');
die('network error'."\n");
}
fputs($stream, $header);
$endHeader = 0;
while(!$endHeader){
$temp = fgets($stream);
// echo $temp;
if ($temp == "\r\n" || feof($stream)){
$endHeader = 1;
break;
}
}
$filename = check_fname('stream0', 'stream');
$file = fopen($filename,'w');
if(!$file){
unlink('lock');
die('couldn\'t open file, probably already streaming'."\n");
}
while(!feof($stream)){
$temp = fgets($stream);
//echo $temp;
fputs($file,$temp);
}
fclose($stream);
fclose(file);
if(filesize($filename) == 0)
unlink($filename);
echo "done"."\n";
unlink('lock');
echo "done"."\n";
unlink('lock');
function check_fname($fname, $origfname, $count = 0){
if(file_exists($fname)) {
$count++;
$fname = check_fname($origfname.$count, $origfname,
$count);
}
return $fname;
}
?>