<?php
if(isset($_GET['url']))
{

	$url = explode("|", $_GET['url']);

	$host = "www.svt.se";
	$port = 80;
	$fp = fsockopen($host,$port);
	fputs ($fp, "GET /svt/road/Classic/shared/mediacenter/player.jsp?a={$url[0]}&d={$url[1]} HTTP/1.1\r\n".
	                "Host: ".$host."\r\n".
	                "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; sv-SE; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12\r\n".
	                "\r\n");
	$src = "";				
	while(true)
	{
		$src .= fgets($fp);
		if(strpos($src, "</html>")) break;
	}

	// Check if its a flv, asx or ram file
	preg_match("~so.addVariable\(\"pathflv\",\"(.*?)\"\);~", $src, $match);
	$result = $match[1];

	if(empty($match[1]))
	{
		preg_match("~<a href=\"(.*?.(?:asx|ram))\">~", $src, $match);

		if(substr($match[1], -3) == "asx")
		{
			$src = file_get_contents("http://www.svt.se" . $match[1]);
			preg_match("~<ref href=\"(.*?)\"/>~", $src, $match);

			$result = $match[1];
		}
		else
		{
			// Real Media not supported by VLC (no supported codec) Should generate error message, but.. cba atm.
			$result = file_get_contents("http://www.svt.se" . $match[1]);
		}
	}
	
	$_GET['file'] = $result;
	include("vlc.php");
}
?>
