Advertisement
Guest User

Untitled

a guest
May 20th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. public function download($id = null, $path = "downloads")
  2. {
  3. $downloadPatch = __DIR__ .'/'.$path.'/';
  4. if (!file_exists($downloadPatch)) {
  5. mkdir($downloadPatch);
  6. }
  7. $video_id = $this->extract_youtube_id($id);
  8. $location = $downloadPatch.$video_id.".mp3";
  9. $title = $this->get_title($id);
  10. $thumb = $this->get_thumbnail($id);
  11. $check_if_already_done = $this->check_if_already_downloaded($video_id);
  12. $this->add_song_to_history($video_id, $title, $thumb);
  13. if(file_exists($location) == False && $check_if_already_done == 0) {
  14. $process = 'youtube-dl';
  15. $options = ' --newline --extract-audio --audio-format mp3 --audio-quality 0 --embed-thumbnail --max-filesize 500m --no-playlist --add-metadata --metadata-from-title "(?P<artist>.+?) - (?P<title>.+)" -o "'.$downloadPatch.'%(id)s.%(ext)s" https://www.youtube.com/watch?v=' . $video_id;
  16. set_time_limit(0);
  17. $handle = popen($process.$options, "r");
  18. if (ob_get_level() == 0)
  19. ob_start();
  20. while (!feof($handle)) {
  21. $buffer = fgets($handle);
  22. // still work in progress :(
  23. // echo $this->clean_output($buffer); //get pid output
  24. // echo "."; //get pid output
  25. ob_flush();
  26. flush();
  27. }
  28. pclose($handle);
  29. ob_end_flush();
  30. }
  31. $size = $this->readable_filesize($location);
  32. $sinfo = array(
  33. 'file' => array(
  34. 'id' => $video_id,
  35. 'title' => $title,
  36. 'thumb' => $thumb,
  37. 'location' => $location,
  38. 'size' => $size
  39. )
  40. );
  41. $this->update_status($video_id,1);
  42. return $sinfo;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement