I am trying to create a Youtube Downloader inspired by Nimesh Neema answer at https://apple.stackexchange.com/questions/321650/downloading-youtube-music-videos/321668?noredirect=1#comment409948_321668. It uses the youtube-dl
command.
youtube.php
<?php
ini_set("display_errors", 1);
ini_set("track_errors", 1);
ini_set("html_errors", 1);
error_reporting(E_ALL);
$command = '/usr/local/bin/youtube-dl https://www.youtube.com/watch?v=b91ovTKCZGU --no-check-certificate -f mp4 -o /Library/WebServer/Documents/files/test.mp4';
$command1 = 'sleep 2; echo "hi"';
shell_exec($command);
echo '<pre>';
passthru($command);
echo '</pre>';
?>
When accused through a web browser nothing happens. But if I run php ./youtube.php
in Terminal I get the following and the video is created:
<pre>[youtube] b91ovTKCZGU: Downloading webpage
[youtube] b91ovTKCZGU: Downloading video info webpage
[youtube] b91ovTKCZGU: Extracting video information
[download] /Library/WebServer/Documents/files/test.mp4 has already been downloaded
[download] 100% of 10.09MiB
If that isn't odd enough. If I change the command to be executed to /usr/bin/touch /Library/WebServer/Documents/files/test.mp4
it creates the file even when accessed through a web browser.
My Question: How can I get the PHP script to execute the command when accessed through a browser and successfully create the video?
If you are going to downvote please explain the reason why in the comments so I can edit and adjust the question as needed
Update: I transferred the script to my server. It ran perfectly. It seems to be an issue with my configuration.