-
-
Save kostapc/17ecb64dd396f77b5af61393a6f333a4 to your computer and use it in GitHub Desktop.
simple web front for https://github.com/rg3/youtube-dl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$ytdlPath = '/whereever/your/youtube-dl'; //change this | |
ob_start(); | |
$url = trim(rawurldecode($_SERVER['QUERY_STRING'])); | |
$qStr = parse_url($url, PHP_URL_QUERY ); | |
parse_str($qStr, $get); | |
if (!isset($get['v']) || !preg_match('~[a-zA-Z0-9_-]{11}~',$get['v']) ) { | |
die(); | |
} | |
$titleCommand = escapeshellcmd('python2.7 -u ' . $ytdlPath . ' --youtube-skip-dash-manifest --skip-download --print-json http://www.youtube.com/watch?v=' . $get['v']); | |
$json = shell_exec($titleCommand); | |
$info = json_decode($json, true); | |
$title = $info['title']; | |
$downloadCommand = escapeshellcmd('python2.7 -u ' . $ytdlPath . ' --youtube-skip-dash-manifest -q -o - http://www.youtube.com/watch?v=' . $get['v']); | |
$descriptorspec = [ | |
0 => ["pipe", "r"], | |
1 => ["pipe", "w"], | |
2 => ["pipe", "w"] | |
]; | |
ob_end_clean(); | |
header('Content-Description: File Transfer'); | |
header('Content-Type: application/octet-stream'); | |
header('Content-Disposition: attachment; filename="' . $title .'.mp4"'); | |
header('Expires: 0'); | |
header('Cache-Control: must-revalidate'); | |
header('Pragma: public'); | |
$process = proc_open($downloadCommand, $descriptorspec, $pipes, realpath('./'), array()); | |
if (is_resource($process)) { | |
while ($s = fgets($pipes[1])) { | |
print $s; | |
flush(); | |
} | |
} | |
proc_close($process); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment