Search code examples
pythondjangoherokuyoutube-dl

youtube-dl on django server


I have a python/django server on heroku, this is my index method:

def index(request):
    youtube_dl.main(['https://www.youtube.com/watch?v=ufERJEdcfAY'])
    return HttpResponse('hello')

when I go to my home page the response is as expected 'hello' but I can't find the media file anywhere in my server

I also have another main script:

if __name__ == '__main__':
    youtube_dl.main(['https://www.youtube.com/watch?v=ufERJEdcfAY'])

when I'm running python __main__.py everything works just fine and the file is downloaded to the folder which I ran the command from.

Any ideas will be highly welcomed, greetings!

edit

I tried the treading, and it seems like it's working but I can't find the file. I ran heroku run bash trying to find a directory which the file is inside of, but can't.

 ←[32m2015-03-27T11:53:42.068905+00:00 heroku[api]:←[0m Deploy a5bebbc by qobyyy@
gmail.com
←[32m2015-03-27T11:53:42.068905+00:00 heroku[api]:←[0m Release v44 created by qo
byyy@gmail.com
←[36m2015-03-27T11:53:42.880957+00:00 heroku[web.1]:←[0m State changed from up t
o starting
←[36m2015-03-27T11:53:45.526784+00:00 heroku[web.1]:←[0m Stopping all processes
with SIGTERM
←[36m2015-03-27T11:53:46.281281+00:00 app[web.1]:←[0m 2015-03-27 11:53:46 [3] [I
NFO] Shutting down: Master
←[36m2015-03-27T11:53:46.262444+00:00 app[web.1]:←[0m 2015-03-27 11:53:46 [10] [
INFO] Worker exiting (pid: 10)
←[36m2015-03-27T11:53:46.262449+00:00 app[web.1]:←[0m 2015-03-27 11:53:46 [9] [I
NFO] Worker exiting (pid: 9)
←[36m2015-03-27T11:53:46.263200+00:00 app[web.1]:←[0m 2015-03-27 11:53:46 [3] [I
NFO] Handling signal: term
←[36m2015-03-27T11:53:46.868377+00:00 heroku[web.1]:←[0m Starting process with c
ommand `gunicorn gettingstarted.wsgi --log-file -`
←[36m2015-03-27T11:53:47.009560+00:00 heroku[web.1]:←[0m Process exited with sta
tus 0
←[36m2015-03-27T11:53:48.660418+00:00 app[web.1]:←[0m 2015-03-27 11:53:48 [3] [I
NFO] Listening at: http://0.0.0.0:52428 (3)
←[36m2015-03-27T11:53:48.660502+00:00 app[web.1]:←[0m 2015-03-27 11:53:48 [3] [I
NFO] Using worker: sync
←[36m2015-03-27T11:53:48.669618+00:00 app[web.1]:←[0m 2015-03-27 11:53:48 [9] [I
NFO] Booting worker with pid: 9
←[36m2015-03-27T11:53:48.659633+00:00 app[web.1]:←[0m 2015-03-27 11:53:48 [3] [I
NFO] Starting gunicorn 19.0.0
←[36m2015-03-27T11:53:48.711500+00:00 app[web.1]:←[0m 2015-03-27 11:53:48 [10] [
INFO] Booting worker with pid: 10
←[36m2015-03-27T11:53:49.101270+00:00 heroku[web.1]:←[0m State changed from star
ting to up
←[33m2015-03-27T11:53:50.392891+00:00 heroku[router]:←[0m at=info method=GET pat
h="/" host=rocky-castle-8297.herokuapp.com request_id=0ad1d01d-174e-439c-b91d-2c
4487920d97 fwd="85.250.225.100" dyno=web.1 connect=1ms service=785ms status=200
bytes=213
←[36m2015-03-27T11:53:50.793930+00:00 app[web.1]:←[0m [youtube] ufERJEdcfAY: Dow
nloading webpage
←[36m2015-03-27T11:53:51.015179+00:00 app[web.1]:←[0m [youtube] ufERJEdcfAY: Ext
racting video information
←[36m2015-03-27T11:53:51.068767+00:00 app[web.1]:←[0m [youtube] ufERJEdcfAY: Dow
nloading js player en_US-vflFAPa9H
←[36m2015-03-27T11:53:51.349748+00:00 app[web.1]:←[0m [youtube] ufERJEdcfAY: Dow
nloading DASH manifest
←[36m2015-03-27T11:53:51.477715+00:00 app[web.1]:←[0m [download] Destination: Pi
xies  - - Where Is My Mind-ufERJEdcfAY.mp4
[download] 100% of 8.70MiB in 00:0059MiB/s ETA 00:00known ETA

Solution

  • according to this: https://devcenter.heroku.com/articles/read-only-filesystem

    It isn't possible do save files permanently from the code. It is saved for the duration of the request and then deleted.

    My solution is to upload it to dropbox (here I used the threading so thank you very much @itzmeontv) with their Python SDK, and then share the link to the file in dropbox.