0

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.

JBis
  • 827
  • 1
  • 10
  • 26
  • @JaredFarrish How come `PHP Notice: Undefined index: url in.......` – RiggsFolly Apr 07 '18 at 19:55
  • Cool, go for it – RiggsFolly Apr 07 '18 at 19:57
  • @RiggsFolly Please remove downvote. Or at least explain why you down voted. – JBis Apr 07 '18 at 19:58
  • Then remove this line `$url = escapeshellarg($_GET["url"]);`, apparently unnecessary line and you will get rid of the apparently irrelevant error – RiggsFolly Apr 07 '18 at 19:58
  • @RiggsFolly I have edited the question as requested. – JBis Apr 07 '18 at 19:59
  • Might be worth running it again and checking that the `Undefined index` error has also gone away, so others dont get confused – RiggsFolly Apr 07 '18 at 20:00
  • Have you checked that the `shell_exec()` functions has not been disabled by your hosting company? – RiggsFolly Apr 07 '18 at 20:02
  • Please check your server logs for errors, you might not have access to shell functions based on your web-related php configuration. This is pretty common in shared environments. – Jared Farrish Apr 07 '18 at 20:02
  • @RiggsFolly I have reran and edited as needed. I was hosting the website on my localhost and then am going to move it to a server I own and run. I don't think that, that is the issue as I was able to run the `touch` command. – JBis Apr 07 '18 at 20:04
  • It would still be useful to check that it will still run on your hosting package before bothering to fix it on your local system – RiggsFolly Apr 07 '18 at 20:05
  • @RiggsFolly As I said before, I run the server. I have full access to the configuration files. I don't have a hosting package because I do not pay to host my website, because I host it myself on my server, that I run, configure, and use. – JBis Apr 07 '18 at 20:08
  • What does your apache log say when you run the script from the web url? – Jared Farrish Apr 07 '18 at 20:09
  • It does not appear to say anything. The access log and the error log do not have anything that appears to be a sign of execution of a command or and error with that command. – JBis Apr 07 '18 at 20:18
  • Debug it like the page isn't being run then. Start at that and work your way into it once you confirm the proper execution sequence (scrip runs, then output the command, then the next part, etc). Once you know for a fact it's being run and the command appears correct, then debug what it's actually doing with the command. – Jared Farrish Apr 07 '18 at 20:28
  • I am not exactly sure what you mean. I attempted to change the command to the `touch` command and it worked. I also tried the `sleep` command to see if the execution time was too short but that worked too. – JBis Apr 07 '18 at 20:31
  • @JBis I have the same problem right now. Did you get a solution? – JuanFernandoz Mar 10 '23 at 02:56

0 Answers0