]*novalidate id=\"gaia_loginform\")[^>].+<\/form>/Uis";
preg_match($sPattern,$sData,$aData);
if(isset($aData[0])){
// get action
$sPattern = "/action=\"([^\"]+)/is";
preg_match($sPattern,$aData[0],$aTarget);
$sTarget = $aTarget[1];
// get all inputs
$sPattern = "/]+/is";
preg_match_all($sPattern,$aData[0],$aInput);
// go through the inputs and extract the vars and their values
$sPost = "";
for($y=0;$y0){
$sPost .= "&";
}
// get var names
$sPattern = "/name=\"([^\"]+)/is";
preg_match($sPattern,$aInput[0][$y],$aVar);
if(!isset($aVar[1])){
// no name
continue;
}
$sPost .= $aVar[1]."=";
// add pass
if($aVar[1]=="Passwd"){
$sPost .= $sPass;
continue;
}
// add email/user
if($aVar[1]=="Email"){
$sPost .= $sUser;
continue;
}
// get values
$sPattern = "/value=\"([^\"]+)/is";
preg_match($sPattern,$aInput[0][$y],$aVal);
if(!isset($aVal[1]) || empty($aVal[1])){
// no value
continue;
}
$sPost .= $aVal[1];
}
// in case we are skipping an input with no name
$sPost = str_replace("&&","&",$sPost);
curl_setopt($ch, CURLOPT_URL, $sTarget);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $sPost);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: application/x-www-form-urlencoded"));
$sResponse = curl_exec($ch);
// find the user style string if it is there, login was successful
$iPos = strpos($sResponse,"refresh");
if($iPos){
// ok we have logged in, go to youtube and get the video
curl_setopt($ch, CURLOPT_URL, $sYTLink);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$sResponse = curl_exec($ch);
preg_match('/\'PLAYBACK_ID\':\s+\"(.*)\"/',$sResponse,$aPID);
preg_match('/yt\.setAjaxToken\(\'watch_actions_ajax\',\s+\"(.*)\"/',$sResponse,$aSessionToken);
if(!isset($aPID[1])){
echo"No playback id found";
}
elseif(!isset($aSessionToken[1])){
echo"No session id found";
}
else{
// like this video
curl_setopt($ch, CURLOPT_URL, "http://www.youtube.com/watch_actions_ajax?action_like_video=1&video_id=".$sVID."&plid=".$aPID[1]);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "session_token=".$aSessionToken[1]."&screen=".rawurlencode("h=800&w=1280&d=24"));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: application/x-www-form-urlencoded"));
$sResponse = curl_exec($ch);
curl_close($ch);
//echo $sResponse;
}
}
else{
echo "Login failed";
}
}
else{
die("Unable to find login form, terminating script\n");
}
}
}
?>