Code:
<?php
/*****************************************************************
* Plugin: FlowTube
* Description:
* Replaces the YouTube player with FlowPlayer, which loads
* the original FLV file directly.
* Author: kronflux
******************************************************************/
// Increase timeout to 60 minutes
$toSet[CURLOPT_TIMEOUT] = 7200;
// Strip javascript to stop existing javascript from intefering
// $options['stripJS'] = false;
// Currently not needed, but if problems arise, just uncomment it and see if that helps.
// 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\"\:\s"(.*)"#', $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\", 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);
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
$flowPlayerUrl = GLYPE_URL . '/plugins/flowplayer-3.1.1.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="{$flowPlayerUrl}"
width="620"
height="380"
id="FlowPlayer"
name="FlowPlayer"
bgcolor="000000"
allowscriptaccess="always"
allowfullscreen="true"
type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer"
flashvars="id=player&config={'playlist':['$flvUrl']}&width=620&height=380&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);
$input = preg_replace('#http://s.ytimg.com/yt/swf/watch-vfl106690.swf#s', '' . $flowPlayerUrl . '', $input, 1);
$input = preg_replace('#http://s.ytimg.com/yt/swf/watch_v8-vfl106690.swf#s', '' . $flowPlayerUrl . '', $input, 1);
break;
}
return $input;
}
?>