Posted By

chrisaiv on 11/03/08


Tagged

php flash flv YouTube


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

MMDeveloper
adkatrit
tof
Balamir


PHP: Capture Location of FLV from YouTube


 / Published in: PHP
 

  1. <?php
  2. $url = trim($_REQUEST['url']);
  3. if (strpos($url, 'http://www.youtube.com/watch?v=') === 0)
  4. {
  5. $ch = curl_init();
  6.  
  7. curl_setopt($ch, CURLOPT_URL, $url);
  8. curl_setopt($ch, CURLOPT_HEADER, false);
  9. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  10.  
  11. $info = curl_exec($ch);
  12.  
  13. $pos1 = strpos($info, "&amp;video_id=", $pos1);
  14. $pos2 = strpos($info, "&amp;t=", $pos2);
  15.  
  16. $video_id = substr($info, $pos1 + 10, 11);
  17. $tag_t = substr($info, $pos2 + 3, 32);
  18.  
  19. $response = '';
  20. $response .= '' . $video_id . '';
  21. $response .= '' . $tag_t . '';
  22. $response .= '';
  23.  
  24. header("Content-type: text/xml");
  25. echo $response;
  26.  
  27. curl_close($ch);
  28. } else
  29. {
  30. die("Wrong URL / Parameters");
  31. }
  32. ?>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: lukemcr on December 7, 2009

Does this still work? I'm getting XML errors.

Posted By: chrisaiv on December 9, 2009

Works just fine, you just need to look at your URL params. Try something like this: http://localhost/?url=http://www.youtube.com/watch?v=-yg61brmEyo

You need to login to post a comment.