View Single Post
Old 01-24-2011, 10:26 PM  
d-null
. . .
 
d-null's Avatar
 
Industry Role:
Join Date: Apr 2007
Location: NY
Posts: 13,724
Quote:
Originally Posted by fris View Post
try this.

Code:
<?php

  class youtube
  {
      var $cookies;
      var $mgr;
      var $req;
      var $debug = true;
      var $auth = false;
      
      function youtube()
      {
      }
      function download($video_id)
      {
          $url = "https://youtube.com/watch?v=" . $video_id;
          $this->req =& new HTTP_Request($url);
          $response = $this->req->sendRequest();
          if (PEAR::isError($response)) {
              $response->getMessage() . "\n";
          } else {
              $page = $this->req->getResponseBody();
              $vpattern = '/v=(.*?)&/';
              preg_match($vpattern, $page, $mv);
              echo "<br />Video ID:" . $v_id = $mv[1];
              $tpattern = '/&t=(.*?)&/';
              preg_match($tpattern, $page, $tickets);
              echo "<br />Token ID:" . $token = $tickets[1];
              $curl = "video_id=";
              $curl .= $v_id;
              $curl .= "&t=";
              $curl .= $token;
              $url = "https://youtube.com/get_video?" . $curl;
              if ($this->debug)
                  return $url;
          }
      }
  }
  
  function getPatternFromUrl($url)
  {
      $url = $url . '&';
      $pattern = '/v=(.+?)&+/';
      preg_match($pattern, $url, $matches);
      return($matches[1]);
  }
  
  function GrabFlvFromYoutube($pattern)
  {
      $tube = new youtube();
      $flv_http_path = $tube->download($pattern);
      echo "<br/>Complete URL:" . $flv_http_path;
      set_time_limit(0);
      
      $data = file_get_contents($flv_http_path);
      $new_flv_path = dirname(_FILE_) . '/flvs/' . $pattern . '-' . time() . '.flv';
      echo "<br />File uploaed:";
      file_put_contents($new_flv_path, $data);
      return $new_flv_path;
  }
  
  // here is url of youtube video
  $url = $_POST['url'];
  $pattern = getPatternFromUrl($url);
  $flv_path = GrabFlvFromYoutube($pattern);
  echo "File Successfully Downloaded at:" . $flv_path . "<br/>";
  
?>
thanks for this fris

I'm playing with it but still getting 500 errors, is there something I am missing if trying to run the above as it is?


and I'm not doing this to "steal" any content for those that voiced concern
d-null is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote