Advertisement
Guest User

Untitled

a guest
Jun 5th, 2010
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. <?php
  2. /*****************************************************************
  3. * Plugin: YouTube
  4. * Description:
  5. * Replaces the YouTube player with our own player that loads
  6. * the FLV file directly.
  7. * Author: http://forums.glype.com/index.php?topic=109.180
  8. ******************************************************************/
  9.  
  10. /*****************************************************************
  11. * Override options for this site
  12. ******************************************************************/
  13.  
  14. // Increase timeout to 60 minutes
  15. $toSet[CURLOPT_TIMEOUT] = 7200;
  16.  
  17. // Strip javascript to simplify the page and stop existing javascript intefering
  18. //$options['stripJS'] = false;
  19. //dont need this
  20.  
  21. /*****************************************************************
  22. * Pre-parsing applied BEFORE main proxy parser
  23. ******************************************************************/
  24.  
  25. function preParse($input, $type) {
  26.  
  27. switch ( $type ) {
  28.  
  29. case 'html':
  30.  
  31. // Look for video ID and record it
  32. if ( preg_match('#pageVideoId\s\=\s\'(.{11})\'#', $input, $videoId) ) {
  33. define('VIDEO_ID', $videoId[1]);
  34. }
  35.  
  36. // Look for T-value. Purpose unknown but seems to be required. Maybe a token
  37. // to complicate downloading FLV files?
  38. if ( preg_match('#"t": "(.*)"#', $input, $tValue) ) {
  39. define('T_VALUE', $tValue[1]);
  40. }
  41.  
  42. // Remove noscript message
  43. $input = preg_replace('#\<noscript\>Hello, you either have JavaScript turned off or an old version of Adobe.*?\<\/noscript\>#s', '', $input, 1);
  44. $input = preg_replace('#var\sfo\s\=\swriteMoviePlayer\(\"watch-player-div\"\)\;#', '', $input, 1);
  45. $input = preg_replace('#document.write\(\'Hello, you either have JavaScript turned off or an old version of Adobe.*?\<\/a\>.\'\)\;#s', '', $input, 1);
  46. break;
  47.  
  48. }
  49.  
  50. return $input;
  51.  
  52. }
  53.  
  54.  
  55. /*****************************************************************
  56. * Post-parsing applied AFTER main proxy parser.
  57. ******************************************************************/
  58.  
  59. function postParse($input, $type) {
  60.  
  61. switch ( $type ) {
  62.  
  63. // Apply changes to HTML documents
  64. case 'html':
  65.  
  66. // Check we have a video to show and if not, return unchanged
  67. if ( ! defined('VIDEO_ID') || ! defined('T_VALUE') ) {
  68. return $input;
  69. }
  70.  
  71. // Create URL to mediaplayer
  72. $mediaPlayerUrl = GLYPE_URL . '/plugins/player.swf';
  73.  
  74. // Generate URL to flv file and preview image through proxy script
  75.  
  76. $flvUrl = rawurlencode(proxifyURL(sprintf('http://www.youtube.com/get_video?video_id=%s&t=%s', VIDEO_ID, T_VALUE)));
  77. $imgUrl = rawurlencode(proxifyURL(sprintf('http://img.youtube.com/vi/%s/0.jpg', VIDEO_ID)));
  78.  
  79. // Generate HTML for the flash object with our new FLV URL
  80. $html = <<<OUT
  81. <embed src="{$mediaPlayerUrl}"
  82. width="620"
  83. height="380"
  84. bgcolor="000000"
  85. allowscriptaccess="always"
  86. allowfullscreen="true"
  87. type="application/x-shockwave-flash"
  88. pluginspage="http://www.macromedia.com/go/getflashplayer"
  89. flashvars="width=480&amp;height=395&amp;type=video&amp;fullscreen=true&amp;volume=100&amp;file={$flvUrl}&amp;image={$imgUrl}" />
  90. OUT;
  91.  
  92. // Add our own player into the player div
  93. $input = preg_replace('#<div id="watch-noplayer-div">#', '<div id="watch-noplayer-div">' . $html, $input, 1);
  94.  
  95. break;
  96.  
  97. }
  98.  
  99. return $input;
  100.  
  101. }
  102. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement