Youtube Video Download Script


/ Published in: PHP
Save to your folder(s)

Extracts the video title & download URL from a youtube page and starts a download.


Copy this code and paste it in your HTML
  1. <?php
  2. if ($_SERVER['REQUEST_METHOD'] == 'POST')
  3. {
  4. $url = (isset($_POST['url']) && !empty($_POST['url'])) ? $_POST['url'] : false;
  5. if (!$url) {
  6. echo "Please enter a URL.";
  7. } else {
  8. $source = file_get_contents($url);
  9. $source = urldecode($source);
  10.  
  11. // Extract video title.
  12. $vTitle_results_1 = explode('<title>', $source);
  13. $vTitle_results_2 = explode('</title>', $vTitle_results_1[1]);
  14.  
  15. $title = trim(str_replace(' - YouTube', '', trim($vTitle_results_2[0])));
  16.  
  17. // Extract video download URL.
  18. $dURL_results_1 = explode('url_encoded_fmt_stream_map": "url=', $source);
  19. $dURL_results_2 = explode('\u0026quality', $dURL_results_1[1]);
  20.  
  21. // Force download of video.
  22. $file = str_replace(' ', '_', strtolower($title)).'.webm';
  23.  
  24. header("Cache-Control: public");
  25. header("Content-Description: File Transfer");
  26. header("Content-Disposition: attachment; filename=$file");
  27. header("Content-Type: video/webm");
  28. header("Content-Transfer-Encoding: binary");
  29.  
  30. readfile($dURL_results_2[0]);
  31.  
  32. }
  33. }
  34. ?>
  35. <form method="post">
  36. <label for="url">URL:</label>
  37. <input type="text" name="url" value="" id="url">
  38. <input type="submit" name="submit" value="Download">
  39. </form>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.