Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a php API and demo page #152

Open
phihag opened this issue Sep 13, 2011 · 14 comments
Open

Create a php API and demo page #152

phihag opened this issue Sep 13, 2011 · 14 comments
Labels

Comments

@phihag
Copy link
Contributor

phihag commented 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.

@phihag
Copy link
Contributor Author

phihag commented 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
Copy link
Contributor Author

phihag commented Sep 15, 2011

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

@viddypiddy
Copy link

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

@bassrock
Copy link

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

@bencrundwell
Copy link

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?

@phihag phihag mentioned this issue Feb 18, 2013
@glisignoli
Copy link
Contributor

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".

@bassrock
Copy link

@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.

@pricejn2
Copy link

pricejn2 commented 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?

@yasoob
Copy link
Contributor

yasoob commented Sep 27, 2013

Check this for help on some issues.

@SpEcHiDe
Copy link
Contributor

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

@yan12125
Copy link
Collaborator

@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.

@siddht4
Copy link

siddht4 commented 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
Copy link

siddht4 commented 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.

@bato3
Copy link
Contributor

bato3 commented 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

joedborg referenced this issue in joedborg/youtube-dl Nov 17, 2020
[pull] master from rg3:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests