<?php require '../autoloader.php'; $url = 'https://www.youtube.com/watch?v=oeCihv9A3ac'; $track = 'Eminem - Phenomenal'; $download = new YTDownloader\Service\Download($url); YTDownloader\Helper\Convert::$quality = "256K"; $file = $download->convert(); $file = YTDownloader::getDownloadPath() . $file; header('Content-type: audio/mpeg'); header('Content-length: ' . filesize($file)); header('Content-Disposition: attachment; filename="' . $track . '.mp3"'); header("Content-Transfer-Encoding: binary"); header("Content-Type: audio/mpeg, audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3"); readfile($file);
<?php require '../autoloader.php'; $check = $_POST['check']; if (isset($check) && $check == "submitForm") { $action = $_POST['action']; $videoId = $_POST['videoId']; $youtube = new YTDownloader\Service\Download($videoId); $response = array(); try { switch ($action) { case 'qualities': $response = $youtube->availableQualities(); break; case 'downloadBest': $file = $youtube->getVideo(); $response['download'] = true; $response['file'] = $file; break; case 'download': $quality = $_POST['quality']; $file = $youtube->download($quality, 'mp4'); $response['download'] = true; $response['file'] = $file; break; } } catch (Exception $e) { $response["error"] = $e->getMessage(); } echo json_encode($response); }
public static function downloadVideo($url, $opts = []) { $folder = self::media('', 'show', ['type' => 'video']); $extension = $opts['extension'] ?? 'mp4'; try { $ytdl = new \YTDownloader\Service\Download($url, ['path' => $folder]); $file = $ytdl->convert($extension, ['type' => 'video', 'quality' => $opts['quality'] ?? '240p']); $name = uniqid() . ".{$extension}"; copy($folder . $file, $folder . $name); unlink($folder . $file); } catch (\Exception $e) { $name = false; } return $name; }