Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*****************************************************************
- * Plugin: YouTube
- * Description:
- * Replaces the YouTube player with our own player that loads
- * the FLV file directly.
- * Author: http://forums.glype.com/index.php?topic=109.180
- ******************************************************************/
- /*****************************************************************
- * Override options for this site
- ******************************************************************/
- // Increase timeout to 60 minutes
- $toSet[CURLOPT_TIMEOUT] = 7200;
- // 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':
- // Look for video ID and record it
- if ( preg_match('#pageVideoId\s\=\s\'(.{11})\'#', $input, $videoId) ) {
- define('VIDEO_ID', $videoId[1]);
- }
- // Look for T-value. Purpose unknown but seems to be required. Maybe a token
- // to complicate downloading FLV files?
- if ( preg_match('#"t": "(.*)"#', $input, $tValue) ) {
- define('T_VALUE', $tValue[1]);
- }
- // Remove noscript message
- $input = preg_replace('#\<noscript\>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\"\)\;#', '', $input, 1);
- $input = preg_replace('#document.write\(\'Hello, you either have JavaScript turned off or an old version of Adobe.*?\<\/a\>.\'\)\;#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
- <embed src="{$mediaPlayerUrl}"
- width="620"
- height="380"
- bgcolor="000000"
- allowscriptaccess="always"
- allowfullscreen="true"
- type="application/x-shockwave-flash"
- pluginspage="http://www.macromedia.com/go/getflashplayer"
- flashvars="width=480&height=395&type=video&fullscreen=true&volume=100&file={$flvUrl}&image={$imgUrl}" />
- OUT;
- // Add our own player into the player div
- $input = preg_replace('#<div id="watch-noplayer-div">#', '<div id="watch-noplayer-div">' . $html, $input, 1);
- break;
- }
- return $input;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement