Youtube plugin for PHProxy | Tutorial

Written By: Keldorn Firecam
Date: 2009-10-31

Modifying PHProxy to work with Youtube

If you would like to modify PHProxy to be able to view youtube videos, you may not understand PHP enough to modify it to have this functionality. In this guide I will show the logic of creating a plugin and present to you a working plugin for PHProxy to have Youtube Support.

 

 

To Begin:

I recommend to use Notepad++ to edit PHProxy source code. So if you do not have that, download and install it.

Once you have done that, open up the file called "index.php" and scroll down to line: 879
Where you will see this.

 // // MODIFY AND DUMP RESOURCE //   
if ($_content_type == 'text/css') {     
$_response_body = proxify_css($_response_body); 
} else {     
 if ($_flags['strip_title']){

   $_response_body = preg_replace('#(<\s*title[^>]*>)(.*?)(<\s*/title[^>]*>)#is', '$1$3', $_response_body);     

} 

 

This area is called the "preParsing" stage. That is the preparsing of the html begins here, and, this is where you will want to begin creating any plugin. The Variable called $_response_body contains the HTML of the website PHProxy just downloaded. What were going to do is use some Regular expressions to find and remove some parts from the page. Namely we want to find and remove.

  • Find the video ID
  • Find the T Value
  • Remove the noscript messages
  • Null out their player

So after line 879 put this code:

/*
Youtube Plugin for PHProxy  ::: PreParsing       
Author: http://www.hidefinder.com                       	  
Disclaimer: This is distributed in the hope that 
it will be useful,but WITHOUT ANY WARRANTY
*/

  if($_url_parts['host'] == "www.youtube.com") {
	    
	         // Look for video ID and record it
	if ( preg_match('#\bvideo_id"\s*:\s*[\'"]?([^\'"\s]*)[\'"]#si', $_response_body, $videoId) ) {
	             
               $youtube = $videoId[1];
 
	 }
 
	         // Look for T-value. 
	 if ( preg_match('#\bt"\s*:\s*[\'"]?([^\'"\s]*)[\'"]#', $_response_body, $tValue) ) {
	     
                $tValue = $tValue[1];
	 }
	         
	// Null their player
	$_response_body  = preg_replace('#var\sfo\s\=\swriteMoviePlayer\(\"watch-player-div\"\)\;#', '', $_response_body, 1);
	$_response_body  = preg_replace('#writeMoviePlayer#','',$_response_body, 1);
	// Remove noscript messages
	$_response_body  = preg_replace('#document.write\(\'Hello, you either have JavaScript turned off or an old version of Adobe.*?\<\/a\>.\'\)\;#s', '', $_response_body, 1);
 
	         
   }
// -- End Youtube Plugin
 

 

Now head to Line 1197 in the code where you see this.

 

 
$_url_form .= '</form></div>';
$_response_body = preg_replace('#\<\s*body(.*?)\>#si', "$0\n$_url_form" , $_response_body, 1);
 

 

This area is called the PostParsing area, which means everything is done and we can make final touches to the html document.
Also note this being the Postparsing stage, you can put links or ads here by modying $_response_body with regural expressions and without the phproxy script rewriting your links go to threw the proxy. That is what were going to do here. Were going to use one more regural expression and find there Player div and insert our player into it.

So put underneath     where you see

$_response_body = preg_replace('#\<\s*body(.*?)\>[...]
/*
Youtube Plugin for PHProxy   :: PostParsing                     
Author: http://www.hidefinder.com                 
	    
Disclaimer: This is distributed in the hope that  
it will be useful,but WITHOUT ANY WARRANTY;      
*/
	    
	    // check if one the variables from the preparsing is set
  if(isset($youtube)) {
 
	         $flv = 'http://www.youtube.com/get_video?video_id=' . $youtube . '&t=' . $tValue;
	         $flv = encode_url($flv);
            
     $player_html = " <embed src=\"/player.swf\" width=\"620\" height=\"380\" bgcolor=\"000000\" allowscriptaccess=\"always\""
	            . "allowfullscreen=\"true\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\""
	            . "flashvars=\"width=620&height=380&type=video&fullscreen=true&volume=100&file=/index.php?q={$flv}&image=\" /><br/>;";

$_response_body = preg_replace('<div id="watch-noplayer-div">', '<div id="watch-noplayer-div">' . $player_html, $_response_body, 1);
	        
   }
// -- End Youtube Plugin
 
 

 

You are now done. But make sure you also upload the Player.swf to your root directory. You can download the player here.

Also as a final note. This has absolutly no file limit usage on it. As phproxy doesn't even have that feature. If PHProxy was using cURL that would easy to implement. But for Fopen I have no idea, that would be for you to figure out.

If something changes on youtube and this plugin breaks Contact us



Articles

Update

I've noticed url.php file sometimes getting slow on this site, simply can't have that! I've fixed this by enabled memcached into the redirect url.php file.  So if


Welcome to the New Hidefinder

Do you Smell that? Its that new website smell you have been waiting for! Just joking, the owner of hidefinder, has been busy these past nearly 2 weeks,  designing and programming the ne


How to put ads in proxified page for CGI proxy script

When you open the CGIProxy script with notepad you may become overwhelmed at the sheer about code in it. That can be a problem if you are trying to figure out how to put avertisemen


What is cgi proxy?

CGIProxy is a script that acts as a HTTP or FTP proxy. It was created to help people over come censorship of information and to surf anonymously online. By installing it on a server, it can


What is Glype Proxy?

Glype is a proxy script that had its first release beta in may 2007. Glype may of been created to replace the unsupported PHProxy script although its not certain of the moti




From the directory

Free Proxy

Comprehensive list of free web-based proxies,...
More Proxies For...

More Proxies .com - Fresh new proxies everyday,...


Friends