Friday, December 11, 2009

Glype youtube plugin

My modified version of youtube plugin: /***************************************************************** * Override options for this site ******************************************************************/ // Increase timeout to 60 minutes $toSet[CURLOPT_TIMEOUT] = 0; // Strip javascript to simplify the page and stop existing javascript intefering //$options['stripJS'] = false; //dont need this /***************************************************************** * Pre-parsing applied BEFORE main proxy parser ******************************************************************/ function preParse($input, $type) { switch ( $type ) { case 'html': if(preg_match('/"t"\: "([-a-zA-Z0-9_]{43})/',$input,$tValue)) { define('T_VALUE',$tValue[1]); } if(preg_match('/"video_id"\: "([-a-zA-Z0-9_]{11})/',$input,$videoId)) { define('VIDEO_ID',$videoId[1]); } // Remove noscript message $input = preg_replace('#\Hello, you either have JavaScript turned off or an old version of Adobe.*?\<\/noscript\>#s', '', $input, 1); $input = preg_replace('#var\sfo\s\=\swriteMoviePlayer\(\"watch-player-div\", false, null, null, \"100%\", \"100%\"\) \;#', '', $input, 1); $input = preg_replace('#document.write\(\'Hello, you either have JavaScript turned off or an old version of Adobe.*? \<\/a\>.\'\)\;#s', '', $input, 1); $input = preg_replace('#yt.www.watch.player.write.*?\<\/script\>#s', '', $input, 1); $input = preg_replace('#\
#s', '', $input, 1); $input = preg_replace('#\
#s', '', $input, 1); break; } return $input; } /***************************************************************** * Post-parsing applied AFTER main proxy parser. ******************************************************************/ function postParse($input, $type) { switch ( $type ) { // Apply changes to HTML documents case 'html': // Check we have a video to show and if not, return unchanged if ( ! defined('VIDEO_ID') || ! defined('T_VALUE') ) { return $input; } // Create URL to mediaplayer $mediaPlayerUrl = GLYPE_URL . '/plugins/player.swf'; // Generate URL to flv file and preview image through proxy script $flvUrl = rawurlencode(proxifyURL(sprintf('http://www.youtube.com/get_video?video_id=%s&t=%s', VIDEO_ID, T_VALUE))); $imgUrl = rawurlencode(proxifyURL(sprintf('http://img.youtube.com/vi/%s/0.jpg', VIDEO_ID))); // Generate HTML for the flash object with our new FLV URL $html = << OUT; // Add our own player into the player div $input = preg_replace('#
#', '
' . $html, $input, 1); break; } return $input; } ?>

No comments: