Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function download($id = null, $path = "downloads")
- {
- $downloadPatch = __DIR__ .'/'.$path.'/';
- if (!file_exists($downloadPatch)) {
- mkdir($downloadPatch);
- }
- $video_id = $this->extract_youtube_id($id);
- $location = $downloadPatch.$video_id.".mp3";
- $title = $this->get_title($id);
- $thumb = $this->get_thumbnail($id);
- $check_if_already_done = $this->check_if_already_downloaded($video_id);
- $this->add_song_to_history($video_id, $title, $thumb);
- if(file_exists($location) == False && $check_if_already_done == 0) {
- $process = 'youtube-dl';
- $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;
- set_time_limit(0);
- $handle = popen($process.$options, "r");
- if (ob_get_level() == 0)
- ob_start();
- while (!feof($handle)) {
- $buffer = fgets($handle);
- // still work in progress :(
- // echo $this->clean_output($buffer); //get pid output
- // echo "."; //get pid output
- ob_flush();
- flush();
- }
- pclose($handle);
- ob_end_flush();
- }
- $size = $this->readable_filesize($location);
- $sinfo = array(
- 'file' => array(
- 'id' => $video_id,
- 'title' => $title,
- 'thumb' => $thumb,
- 'location' => $location,
- 'size' => $size
- )
- );
- $this->update_status($video_id,1);
- return $sinfo;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement