Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Something
Tuesday, January 8th, 2008 at 10:15:34pm MST 

  1. .htaccess:
  2.  
  3. Options -Indexes
  4. RewriteEngine on
  5. RewriteRule videoloader/(...........).flv videoloader.php?id=$1
  6. RewriteRule videoloader/(...........)/.*.flv videoloader.php?id=$1
  7.  
  8. videoloader.php:
  9.  
  10. <?php
  11.  
  12. include "dbinfo.php";
  13.  
  14. ini_set ('display_errors', '0');
  15.  
  16. function headers()
  17. {
  18.         header('Content-Transfer-Encoding: Binary');
  19.         header('Content-type: video/x-flv');
  20.         // change the above to whatever is appropriate
  21.  
  22.         header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"');
  23.         header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  24.         header("Cache-Control: no-store, no-cache, must-revalidate");
  25.         header("Last-Modified: Wed, 11 Apr 2020 02:32:57 GMT");
  26.         header('Accept-Ranges:bytes');
  27.         header("Pragma: no-cache");
  28. }
  29.  
  30. $id = $_GET['id'];
  31. $useragent = $_SERVER['HTTP_USER_AGENT'];
  32.  
  33. headers();
  34.  
  35. $t = getTCode($id,$useragent);
  36.  
  37. $contentlength = getContentLength($id,$t);
  38. header("$contentlength");
  39.  
  40. $url = "http://www.youtube.com/get_video?video_id=" . $id . "&t=" . $t;
  41.  
  42. set_time_limit(0);
  43.  
  44. readfile_chunked($url);
  45.  
  46. ?>
  47.  
  48.  
  49. dbinfo.php:
  50.  
  51. <?
  52.  
  53. require_once("curl_http_client.php");
  54. $useragent = $_SERVER['HTTP_USER_AGENT'];
  55.  
  56. ////////////////////////
  57. // streaming settings //
  58. ////////////////////////
  59.  
  60. $packetsize = 4096;
  61. $prebufferpackets = 2;
  62. $bufferpackets =1;
  63.  
  64. function getTCode($videoid,$useragent= "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.11) Gecko/20070312 Firefox/1.5.0.11")
  65. {
  66.         $curl = &new Curl_HTTP_Client();
  67.  
  68.         $curl->set_user_agent($useragent);
  69.         $referrer = "http://www.youtube.com/watch?v=" . $videoid;
  70.         set_time_limit (600);
  71.         $data = $curl->fetch_url($referrer);
  72.  
  73.         //echo $data;
  74.  
  75.         // search for our &t=
  76.  
  77.         $array1 = explode ("&t=", $data);
  78.         $array2 = explode ('&', $array1[1]);
  79.         $t = $array2[0];
  80.  
  81.         //echo "\nt =" . $t . "/n";
  82.  
  83.         return $t;
  84. }
  85.  
  86. function getContentLength($videoid,$t)
  87. {
  88.  
  89.         $url = "http://www.youtube.com/get_video?video_id=" . $videoid . "&t=" . $t;
  90.  
  91.         $array = get_headers($url);
  92.         $count = count($array);
  93.  
  94.         for ($i=0; $i < $count; $i++)
  95.         {
  96.                 if (strpos($array[$i], "Length"))
  97.                 {
  98.                         if ($array[$i] != "Content-Length: 0")
  99.                         {
  100.                                 return($array[$i]);
  101.                         }
  102.                 }
  103.         }
  104.  
  105.         return "Content-Length: 0";
  106. }
  107.  
  108. function readfile_chunked($filename) {
  109.  
  110.         global $packetsize;
  111.         global $prebufferpackets;
  112.         global $bufferpackets;
  113.  
  114.         $chunksize = $bufferpackets;; // it will stream for every packet. how many packets per echo
  115.         $tobuffer = $prebufferpackets; // how much times chunksize we want to buffer for the initial request
  116.         $first = 1;
  117.         $buffer = '';
  118.  
  119.         $handle = fopen($filename, 'rb');
  120.         if ($handle === false)
  121.         {
  122.                 return false;
  123.         }
  124.         while (!feof($handle))
  125.         {
  126.                 $buffer = '';
  127.                 set_time_limit(0);
  128.                 if ($first == 1) { $todo = $chunksize * $tobuffer; $first =0;} else { $todo = $chunksize; }
  129.  
  130.                 for ($i=0; $i<$todo; $i++)
  131.                 {
  132.                         $buffer .= fread($handle, $packetsize);
  133.                 }
  134.  
  135.                 echo $buffer;
  136.                 ob_flush();
  137.                 flush();
  138.         }
  139.         $status = fclose($handle);
  140.         return $status;
  141. }
  142.  
  143. ?>
  144.  
  145. curl_http_client.php:
  146.  
  147. <?php
  148. /**
  149.  * @version $Id$
  150.  * @package dinke.net
  151.  * @copyright &copy; 2007 Dinke.net
  152.  * @author Dragan Dinic <dragan@dinke.net>
  153.  */
  154.  
  155. /**
  156.  * Curl based HTTP Client
  157.  * Simple but effective OOP wrapper around Curl php lib.
  158.  * Contains common methods needed
  159.  * for getting data from url, setting referrer, credentials,
  160.  * sending post data, managing cookies, etc.
  161.  *
  162.  * Samle usage:
  163.  * $curl = &new Curl_HTTP_Client();
  164.  * $useragent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
  165.  * $curl->set_user_agent($useragent);
  166.  * $curl->store_cookies("/tmp/cookies.txt");
  167.  * $post_data = array('login' => 'pera', 'password' => 'joe');
  168.  * $html_data = $curl->send_post_data(http://www.foo.com/login.php, $post_data);
  169.  */
  170. class Curl_HTTP_Client
  171. {
  172.         /**
  173.          * Curl handler
  174.          * @access private
  175.          * @var resource
  176.          */
  177.         var $ch ;
  178.  
  179.         /**
  180.          * set debug to true in order to get usefull output
  181.          * @access private
  182.          * @var string
  183.          */
  184.         var $debug = false;
  185.  
  186.         /**
  187.          * Contain last error message if error occured
  188.          * @access private
  189.          * @var string
  190.          */
  191.         var $error_msg;
  192.  
  193.  
  194.         /**
  195.          * Curl_HTTP_Client constructor
  196.          * @param boolean debug
  197.          * @access public
  198.          */
  199.         function Curl_HTTP_Client($debug = false)
  200.         {
  201.                 $this->debug = $debug;
  202.  
  203.                 // initialize curl handle
  204.                 $this->ch = curl_init();
  205.  
  206.                 //set various options
  207.  
  208.                 //set error in case http return code bigger than 300
  209.                 curl_setopt($this->ch, CURLOPT_FAILONERROR, true);
  210.  
  211.                 // allow redirects
  212.                 curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true);
  213.  
  214.                 //hack to make code work on windows
  215.                 //if(strpos(PHP_OS,"WIN") !== false)
  216.                 {
  217.                         curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, 0);
  218.                 }
  219.         }
  220.  
  221.         /**
  222.          * Set username/pass for basic http auth
  223.          * @param string user
  224.          * @param string pass
  225.          * @access public
  226.          */
  227.         function set_credentials($username,$password)
  228.         {
  229.                 curl_setopt($this->ch, CURLOPT_USERPWD, "$username:$password");
  230.         }
  231.  
  232.         /**
  233.          * Set referrer
  234.          * @param string referrer url
  235.          * @access public
  236.          */
  237.         function set_referrer($referrer_url)
  238.         {
  239.                 curl_setopt($this->ch, CURLOPT_REFERER, $referrer_url);
  240.         }
  241.  
  242.         /**
  243.          * Set client's useragent
  244.          * @param string user agent
  245.          * @access public
  246.          */
  247.         function set_user_agent($useragent)
  248.         {
  249.                 curl_setopt($this->ch, CURLOPT_USERAGENT, $useragent);
  250.         }
  251.  
  252.         /**
  253.          * Set to receive output headers in all output functions
  254.          * @param boolean true to include all response headers with output, false otherwise
  255.          * @access public
  256.          */
  257.         function include_response_headers($value)
  258.         {
  259.                 curl_setopt($this->ch, CURLOPT_HEADER, $value);
  260.         }
  261.  
  262.  
  263.         /**
  264.          * Set proxy to use for each curl request
  265.          * @param string proxy
  266.          * @access public
  267.          */
  268.         function set_proxy($proxy)
  269.         {
  270.                 curl_setopt($this->ch, CURLOPT_PROXY, $proxy);
  271.         }
  272.  
  273.  
  274.  
  275.         /**
  276.          * Send post data to target URL
  277.          * return data returned from url or false if error occured
  278.          * @param string url
  279.          * @param array assoc post data array ie. $foo['post_var_name'] = $value
  280.          * @param string ip address to bind (default null)
  281.          * @param int timeout in sec for complete curl operation (default 10)
  282.          * @return string data
  283.          * @access public
  284.     */
  285.         function send_post_data($url, $postdata, $ip=null, $timeout=600)
  286.         {
  287.                 //set various curl options first
  288.  
  289.                 // set url to post to
  290.                 curl_setopt($this->ch, CURLOPT_URL,$url);
  291.  
  292.                 // return into a variable rather than displaying it
  293.                 curl_setopt($this->ch, CURLOPT_RETURNTRANSFER,true);
  294.  
  295.                 //bind to specific ip address if it is sent trough arguments
  296.                 if($ip)
  297.                 {
  298.                         if($this->debug)
  299.                         {
  300.                                 echo "Binding to ip $ip\n";
  301.                         }
  302.                         curl_setopt($this->ch,CURLOPT_INTERFACE,$ip);
  303.                 }
  304.  
  305.                 //set curl function timeout to $timeout
  306.                 curl_setopt($this->ch, CURLOPT_TIMEOUT, $timeout);
  307.  
  308.                 //set method to post
  309.                 curl_setopt($this->ch, CURLOPT_POST, true);
  310.  
  311.  
  312.                 //generate post string
  313.                 $post_array = array();
  314.                 if(!is_array($postdata))
  315.                 {
  316.                         return false;
  317.                 }
  318.                 foreach($postdata as $key=>$value)
  319.                 {
  320.                         $post_array[] = urlencode($key) . "=" . urlencode($value);
  321.                 }
  322.  
  323.                 $post_string = implode("&",$post_array);
  324.  
  325.                 if($this->debug)
  326.                 {
  327.                         echo "Post String: $post_string\n";
  328.                 }
  329.  
  330.                 // set post string
  331.                 curl_setopt($this->ch, CURLOPT_POSTFIELDS, $post_string);
  332.  
  333.  
  334.                 //and finally send curl request
  335.                 $result = curl_exec($this->ch);
  336.  
  337.                 if(curl_errno($this->ch))
  338.                 {
  339.                         if($this->debug)
  340.                         {
  341.                                 echo "Error Occured in Curl\n";
  342.                                 echo "Error number: " .curl_errno($this->ch) ."\n";
  343.                                 echo "Error message: " .curl_error($this->ch)."\n";
  344.                         }
  345.  
  346.                         return false;
  347.                 }
  348.                 else
  349.                 {
  350.                         return $result;
  351.                 }
  352.         }
  353.  
  354.         /**
  355.          * fetch data from target URL
  356.          * return data returned from url or false if error occured
  357.          * @param string url
  358.          * @param string ip address to bind (default null)
  359.          * @param int timeout in sec for complete curl operation (default 5)
  360.          * @return string data
  361.          * @access public
  362.     */
  363.         function fetch_url($url, $ip=null, $timeout=600)
  364.         {
  365.                 // set url to post to
  366.                 curl_setopt($this->ch, CURLOPT_URL,$url);
  367.  
  368.                 //set method to get
  369.                 curl_setopt($this->ch, CURLOPT_HTTPGET,true);
  370.  
  371.                 // return into a variable rather than displaying it
  372.                 curl_setopt($this->ch, CURLOPT_RETURNTRANSFER,true);
  373.  
  374.                 //bind to specific ip address if it is sent trough arguments
  375.                 if($ip)
  376.                 {
  377.                         if($this->debug)
  378.                         {
  379.                                 echo "Binding to ip $ip\n";
  380.                         }
  381.                         curl_setopt($this->ch,CURLOPT_INTERFACE,$ip);
  382.                 }
  383.  
  384.                 //set curl function timeout to $timeout
  385.                 curl_setopt($this->ch, CURLOPT_TIMEOUT, $timeout);
  386.  
  387.                 //and finally send curl request
  388.                 $result = curl_exec($this->ch);
  389.  
  390.                 if(curl_errno($this->ch))
  391.                 {
  392.                         if($this->debug)
  393.                         {
  394.                                 echo "Error Occured in Curl\n";
  395.                                 echo "Error number: " .curl_errno($this->ch) ."\n";
  396.                                 echo "Error message: " .curl_error($this->ch)."\n";
  397.                         }
  398.  
  399.                         return false;
  400.                 }
  401.                 else
  402.                 {
  403.                         return $result;
  404.                 }
  405.         }
  406.  
  407.         /**
  408.          * Fetch data from target URL
  409.          * and store it directly to file
  410.          * @param string url
  411.          * @param resource value stream resource(ie. fopen)
  412.          * @param string ip address to bind (default null)
  413.          * @param int timeout in sec for complete curl operation (default 5)
  414.          * @return boolean true on success false othervise
  415.          * @access public
  416.     */
  417.         function fetch_into_file($url, $fp, $ip=null, $timeout=600)
  418.         {
  419.                 // set url to post to
  420.                 curl_setopt($this->ch, CURLOPT_URL,$url);
  421.  
  422.                 //set method to get
  423.                 curl_setopt($this->ch, CURLOPT_HTTPGET, true);
  424.  
  425.                 // store data into file rather than displaying it
  426.                 curl_setopt($this->ch, CURLOPT_FILE, $fp);
  427.  
  428.                 //bind to specific ip address if it is sent trough arguments
  429.                 if($ip)
  430.                 {
  431.                         if($this->debug)
  432.                         {
  433.                                 echo "Binding to ip $ip\n";
  434.                         }
  435.                         curl_setopt($this->ch, CURLOPT_INTERFACE, $ip);
  436.                 }
  437.  
  438.                 //set curl function timeout to $timeout
  439.                 curl_setopt($this->ch, CURLOPT_TIMEOUT, $timeout);
  440.  
  441.                 //and finally send curl request
  442.                 $result = curl_exec($this->ch);
  443.  
  444.                 if(curl_errno($this->ch))
  445.                 {
  446.                         if($this->debug)
  447.                         {
  448.                                 echo "Error Occured in Curl\n";
  449.                                 echo "Error number: " .curl_errno($this->ch) ."\n";
  450.                                 echo "Error message: " .curl_error($this->ch)."\n";
  451.                         }
  452.  
  453.                         return false;
  454.                 }
  455.                 else
  456.                 {
  457.                         return true;
  458.                 }
  459.         }
  460.  
  461.         /**
  462.          * Send multipart post data to the target URL
  463.          * return data returned from url or false if error occured
  464.          * (contribution by vule nikolic, vule@dinke.net)
  465.          * @param string url
  466.          * @param array assoc post data array ie. $foo['post_var_name'] = $value
  467.          * @param array assoc $file_field_array, contains file_field name = value - path pairs
  468.          * @param string ip address to bind (default null)
  469.          * @param int timeout in sec for complete curl operation (default 30 sec)
  470.          * @return string data
  471.          * @access public
  472.     */
  473.         function send_multipart_post_data($url, $postdata, $file_field_array=array(), $ip=null, $timeout=600)
  474.         {
  475.                 //set various curl options first
  476.  
  477.                 // set url to post to
  478.                 curl_setopt($this->ch, CURLOPT_URL, $url);
  479.  
  480.                 // return into a variable rather than displaying it
  481.                 curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
  482.  
  483.                 //bind to specific ip address if it is sent trough arguments
  484.                 if($ip)
  485.                 {
  486.                         if($this->debug)
  487.                         {
  488.                                 echo "Binding to ip $ip\n";
  489.                         }
  490.                         curl_setopt($this->ch,CURLOPT_INTERFACE,$ip);
  491.                 }
  492.  
  493.                 //set curl function timeout to $timeout
  494.                 curl_setopt($this->ch, CURLOPT_TIMEOUT, $timeout);
  495.  
  496.                 //set method to post
  497.                 curl_setopt($this->ch, CURLOPT_POST, true);
  498.  
  499.                 // disable Expect header
  500.                 // hack to make it working
  501.                 $headers = array("Expect: ");
  502.                 curl_setopt($this->ch, CURLOPT_HTTPHEADER, $headers);
  503.  
  504.                 // initialize result post array
  505.                 $result_post = array();
  506.  
  507.                 //generate post string
  508.                 $post_array = array();
  509.                 $post_string_array = array();
  510.                 if(!is_array($postdata))
  511.                 {
  512.                         return false;
  513.                 }
  514.  
  515.                 foreach($postdata as $key=>$value)
  516.                 {
  517.                         $post_array[$key] = $value;
  518.                         $post_string_array[] = urlencode($key)."=".urlencode($value);
  519.                 }
  520.  
  521.                 $post_string = implode("&",$post_string_array);
  522.  
  523.  
  524.                 if($this->debug)
  525.                 {
  526.                         echo "Post String: $post_string\n";
  527.                 }
  528.  
  529.                 // set post string
  530.                 //curl_setopt($this->ch, CURLOPT_POSTFIELDS, $post_string);
  531.  
  532.  
  533.                 // set multipart form data - file array field-value pairs
  534.                 if(!empty($file_field_array))
  535.                 {
  536.                         foreach($file_field_array as $var_name => $var_value)
  537.                         {
  538.                                 if(strpos(PHP_OS, "WIN") !== false) $var_value = str_replace("/", "\\", $var_value); // win hack
  539.                                 $file_field_array[$var_name] = "@".$var_value;
  540.                         }
  541.                 }
  542.  
  543.                 // set post data
  544.                 $result_post = array_merge($post_array, $file_field_array);
  545.                 curl_setopt($this->ch, CURLOPT_POSTFIELDS, $result_post);
  546.  
  547.  
  548.                 //and finally send curl request
  549.                 $result = curl_exec($this->ch);
  550.  
  551.                 if(curl_errno($this->ch))
  552.                 {
  553.                         if($this->debug)
  554.                         {
  555.                                 echo "Error Occured in Curl\n";
  556.                                 echo "Error number: " .curl_errno($this->ch) ."\n";
  557.                                 echo "Error message: " .curl_error($this->ch)."\n";
  558.                         }
  559.  
  560.                         return false;
  561.                 }
  562.                 else
  563.                 {
  564.                         return $result;
  565.                 }
  566.         }
  567.  
  568.         /**
  569.          * Set file location where cookie data will be stored and send on each new request
  570.          * @param string absolute path to cookie file (must be in writable dir)
  571.          * @access public
  572.          */
  573.         function store_cookies($cookie_file)
  574.         {
  575.                 // use cookies on each request (cookies stored in $cookie_file)
  576.                 curl_setopt ($this->ch, CURLOPT_COOKIEJAR, $cookie_file);
  577.         }
  578.  
  579.         /**
  580.          * Get last URL info
  581.          * usefull when original url was redirected to other location
  582.          * @access public
  583.          * @return string url
  584.          */
  585.         function get_effective_url()
  586.         {
  587.                 return curl_getinfo($this->ch,CURLINFO_EFFECTIVE_URL);
  588.         }
  589.  
  590.         /**
  591.          * Get http response code
  592.          * @access public
  593.          * @return int
  594.          */
  595.         function get_http_response_code()
  596.         {
  597.                 return curl_getinfo($this->ch,CURLINFO_HTTP_CODE);
  598.         }
  599.  
  600.         /**
  601.          * Return last error message and error number
  602.          * @return string error msg
  603.          * @access public
  604.     */
  605.         function get_error_msg()
  606.         {
  607.                 $err = "Error number: " .curl_errno($this->ch) ."\n";
  608.                 $err .="Error message: " .curl_error($this->ch)."\n";
  609.  
  610.                 return $err;
  611.         }
  612. }
  613. ?>

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

worth-right
worth-right fantasy-obligation