Create a php API and demo page #102

Open
opened 2026-02-20 22:25:30 -05:00 by deekerman · 14 comments
Owner

Originally created by @phihag on GitHub (Sep 13, 2011).

youtube-dl is often embedded by php applications. There should be an example php page included, with the following features:

  • Enter URLs and execute youtube-dl (in the background)
  • Show progress of youtube-dl instances
  • Offer a way to abort youtube-dl
  • Allow to download files from the webhost's temporary directory
  • Offer conversion to mp3/aac/ogg vorbis

This may require an additional output option in youtube-dl, for example the ability to output JSON sentences.

Originally created by @phihag on GitHub (Sep 13, 2011). youtube-dl is often embedded by php applications. There should be an example php page included, with the following features: - Enter URLs and execute youtube-dl (in the background) - Show progress of youtube-dl instances - Offer a way to abort youtube-dl - Allow to download files from the webhost's temporary directory - Offer conversion to mp3/aac/ogg vorbis This may require an additional output option in youtube-dl, for example the ability to output JSON sentences.
Author
Owner

@phihag commented on GitHub (Sep 13, 2011):

Showing status (and probably aborting, too) seems surprisingly difficult. I think we can trick around by the following:

  • Give youtube-dl an option to daemonize itself
  • Give youtube-dl an option to output its status machine-readable, as JSON (and include/not include progress)
  • Give youtube-dl an option to write PID (and cleanup on SIGTERM) and said JSON messages to a file instead of stdout
  • Give youtube-dl an option to delete the file when it's done
  • Give youtube-dl an option to stop outputting at stdout after {"status":"downloading"}
  • Write/use a library to parse streaming JSON in php
  • kill the subprocess if it doesn't get to {"status": "downloading"} within 10 seconds

Abort now works like this:

  • Find pidfile. If it isn't there, the process has been aborted/finished
  • Otherwise, kill said process.

Showing progress works like this:

  • Send an AJAX request for current state of a set of downloads. Each download is identified by
  • php determines state, using the json file. If it's not there, the process is either aborted or already finished
  • Look for the downloaded file. If it's there, youtube-dl finished
  • php reads current state from file
  • php send AJAX response
  • JS waits 2s, resends AJAX request

All in all, rather complicated, but achievable.

@phihag commented on GitHub (Sep 13, 2011): Showing status (and probably aborting, too) seems surprisingly difficult. I think we can trick around by the following: - Give youtube-dl an option to daemonize itself - Give youtube-dl an option to output its status machine-readable, as JSON (and include/not include progress) - Give youtube-dl an option to write PID (and cleanup on SIGTERM) and said JSON messages to a file instead of stdout - Give youtube-dl an option to delete the file when it's done - Give youtube-dl an option to stop outputting at stdout after `{"status":"downloading"}` - Write/use [a library to parse streaming JSON in php](http://stackoverflow.com/questions/7311402/incremental-json-parsing-in-php) - kill the subprocess if it doesn't get to `{"status": "downloading"}` within 10 seconds Abort now works like this: - Find pidfile. If it isn't there, the process has been aborted/finished - Otherwise, kill said process. Showing progress works like this: - Send an AJAX request for current state of a set of downloads. Each download is identified by - php determines state, using the json file. If it's not there, the process is either aborted or already finished - Look for the downloaded file. If it's there, youtube-dl finished - php reads current state from file - php send AJAX response - JS waits 2s, resends AJAX request All in all, rather complicated, but achievable.
Author
Owner

@phihag commented on GitHub (Sep 15, 2011):

Since the php code may be nontrivial, it should be developed outside of the main repository.

@phihag commented on GitHub (Sep 15, 2011): Since the php code may be nontrivial, it should be developed outside of the main repository.
Author
Owner

@viddypiddy commented on GitHub (Sep 9, 2012):

Did this ever get moved out to some other repo/forked? Is there work going on? A smooth browser interface would be extremely convenient.

@viddypiddy commented on GitHub (Sep 9, 2012): Did this ever get moved out to some other repo/forked? Is there work going on? A smooth browser interface would be extremely convenient.
Author
Owner

@bassrock commented on GitHub (Oct 18, 2012):

I too am curious what is the status of this issue.

@bassrock commented on GitHub (Oct 18, 2012): I too am curious what is the status of this issue.
Author
Owner

@bencrundwell commented on GitHub (Nov 6, 2012):

I'm really keen to get the downloading progress in my PHP application. I patched a previous version to output a .progress file every second and then used PHP to poll it. But with the latest required update I have lost my patch. Would it be possible to add an output of current progress?

@bencrundwell commented on GitHub (Nov 6, 2012): I'm really keen to get the downloading progress in my PHP application. I patched a previous version to output a .progress file every second and then used PHP to poll it. But with the latest required update I have lost my patch. Would it be possible to add an output of current progress?
Author
Owner

@glisignoli commented on GitHub (Feb 18, 2013):

My thoughts on this was to just implement a sqlite database that multiple youtube-dl instances could access and update. This would allow multiple instances of youtube-dl to run, while allowing a single (or multiple) frontend(s) to read the sqlite database for updates on the running processes. This would be an easier update to youtube-dl than writing an API layer(or at least in my mind it is).
What this doesn't allow is control over running processes, although at the moment only use this would be would to stop the download/convert, which is just a kill of the PID.

I'm interested myself in adding this functionality, unfortunately python isn't a language I am familiar with, but I have enough free time that I am willing to "give it a go".

@glisignoli commented on GitHub (Feb 18, 2013): My thoughts on this was to just implement a sqlite database that multiple youtube-dl instances could access and update. This would allow multiple instances of youtube-dl to run, while allowing a single (or multiple) frontend(s) to read the sqlite database for updates on the running processes. This would be an easier update to youtube-dl than writing an API layer(or at least in my mind it is). What this doesn't allow is control over running processes, although at the moment only use this would be would to stop the download/convert, which is just a kill of the PID. I'm interested myself in adding this functionality, unfortunately python isn't a language I am familiar with, but I have enough free time that I am willing to "give it a go".
Author
Owner

@bassrock commented on GitHub (Feb 18, 2013):

@glisignoli That sounds like a really good idea for processing a bunch of youtube videos!! Maybe even using a worker service like resque or sidekiq! We could have a really decent server solution that we can just pass videos to using an api.

@bassrock commented on GitHub (Feb 18, 2013): @glisignoli That sounds like a really good idea for processing a bunch of youtube videos!! Maybe even using a worker service like resque or sidekiq! We could have a really decent server solution that we can just pass videos to using an api.
Author
Owner

@pricejn2 commented on GitHub (May 2, 2013):

@phihag - I found one of you examples at http://www.verious.com/qa/youtube-dl-and-php-exec/ Don't suppose you have any others out there to share?

@pricejn2 commented on GitHub (May 2, 2013): @phihag - I found one of you examples at http://www.verious.com/qa/youtube-dl-and-php-exec/ Don't suppose you have any others out there to share?
Author
Owner

@yasoob commented on GitHub (Sep 27, 2013):

Check this for help on some issues.

@yasoob commented on GitHub (Sep 27, 2013): Check [this](https://github.com/rg3/youtube-dl/issues/469#issuecomment-23700706) for help on some issues.
Author
Owner

@SpEcHiDe commented on GitHub (Jun 14, 2015):

PHP file


" ; } ``` ?>

SH file
#!/bin/sh

ping -c1 "www.google.com" 2>&1 > /dev/null

if [ $? -ne 0 ]; then
echo "connect to internet and try again"
else
if [ $# -ne 2 ]; then
echo "usage instructions : sh ${0} "
else
cd ${2}
./youtube-dl ${1}
fi
fi

@SpEcHiDe commented on GitHub (Jun 14, 2015): PHP file <?php if(isset($_POST['submit'])){ $c=$_POST['cmqwe']; // save to directory $b=$_POST['link']; // video link $a="yt-dl.sh"; // youtube dl script name ``` $com="sh ".$a." ".$b." ".$c; $com=shell_exec("sh ".$a." ".$b." ".$c); $com=nl2br($com); echo $com . "<br /><hr />" ; } ``` ?> SH file #!/bin/sh ping -c1 "www.google.com" 2>&1 > /dev/null if [ $? -ne 0 ]; then echo "connect to internet and try again" else if [ $# -ne 2 ]; then echo "usage instructions : sh ${0} <youtube-link> <chmodded folder>" else cd ${2} ./youtube-dl ${1} fi fi
Author
Owner

@yan12125 commented on GitHub (Jun 14, 2015):

@SpEcHiDe Your script is quite dangerous. Imagine the POST data:

submit=Submit&cmqwe=foobar&link=foobar;rm+-rf+/home

Anyway, pass $_POST or $_GET data to shell_exec() without proper escaping is VERY VERY dangerous.

@yan12125 commented on GitHub (Jun 14, 2015): @SpEcHiDe Your script is quite dangerous. Imagine the POST data: ``` submit=Submit&cmqwe=foobar&link=foobar;rm+-rf+/home ``` Anyway, pass `$_POST` or `$_GET` data to `shell_exec()` without proper escaping is **VERY VERY** dangerous.
Author
Owner

@siddht4 commented on GitHub (Jul 10, 2017):

This can be done by mere sanitize the data.I have tried where the index page takes user input url.A session cookie is auto injected.When the user clicks on submit button the ajax requests post the data which is sanitized along with user ip,cookie and store it in mariadb(I have tried in mariadb,so this will also work for mysql or percona db).

ydl_opts and my_hook can be customized to form a json which can be shown to the user as actual download status.

The only issue left here is how to send back user to download the complete file.It was internal so not a big deal. if d['status'] == 'finished': to send a callback to download page is what i m thinking now

@siddht4 commented on GitHub (Jul 10, 2017): This can be done by mere sanitize the data.I have tried where the index page takes user input url.A session cookie is auto injected.When the user clicks on submit button the ajax requests post the data which is sanitized along with user ip,cookie and store it in mariadb(I have tried in mariadb,so this will also work for mysql or percona db). ydl_opts and my_hook can be customized to form a json which can be shown to the user as actual download status. The only issue left here is how to send back user to download the complete file.It was internal so not a big deal. ` if d['status'] == 'finished':` to send a callback to download page is what i m thinking now
Author
Owner

@siddht4 commented on GitHub (Jul 10, 2017):

I have tried the json part https://github.com/siddht1/youtube_dl_embed/blob/master/1.py ,this will create a file a.json which can be used as an api feature.Merge this with https://github.com/siddht3/table_json_creator to create a api type.

Things still missing are url provided and extractor details.Which I suppose my_hook has.

@siddht4 commented on GitHub (Jul 10, 2017): I have tried the json part https://github.com/siddht1/youtube_dl_embed/blob/master/1.py ,this will create a file a.json which can be used as an api feature.Merge this with https://github.com/siddht3/table_json_creator to create a api type. Things still missing are url provided and extractor details.Which I suppose my_hook has.
Author
Owner

@bato3 commented on GitHub (Jul 10, 2018):

It isn't example, but full site: https://github.com/Rudloff/alltube

If you want create simple youtube-dl server it's better use NODE: https://www.npmjs.com/package/youtube-dl

@bato3 commented on GitHub (Jul 10, 2018): It isn't example, but full site: https://github.com/Rudloff/alltube If you want create simple youtube-dl server it's better use NODE: https://www.npmjs.com/package/youtube-dl
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/youtube-dl-ytdl-org#102
No description provided.