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

Download to users directory instead of mine Django #24749

Closed
faizanalii opened this issue Apr 12, 2020 · 1 comment
Closed

Download to users directory instead of mine Django #24749

faizanalii opened this issue Apr 12, 2020 · 1 comment
Labels

Comments

@faizanalii
Copy link

@faizanalii faizanalii commented Apr 12, 2020

I'm making a Django app where users can paste link and download videos but there's a problem. I've tried to run it on my local server and then on WAN but both times results are same. Video is downloaded in my directory rather than users. I'm using youtube-dl for this. I'll be really thankful if someone help me out with this. I'll add the views.py file so you get a better understanding. Thanks!

from django.shortcuts import render
from django.http import HttpResponse,HttpResponseRedirect
from download.models import urlinput
from download.forms import Input
import youtube_dl
import subprocess
import os
def index(request):
form=Input()
if request.method=='POST':
form=Input(request.POST)
if form.is_valid():
link=form['url'].value()
#downloadaudio(link)
#video1080(link)
#homedir = os.path.expanduser("~")
#dirs=homedir +'/Downloads'
video720(link)
#download4k(link)
form.save(commit=True)
return render(request,'index.html',{'form':form})
else:
print("Invalid Input")
return render(request,'index.html',{'form':form})
def downloadaudio(link):
options={'format':'bestaudio/best','extractaudio':True,'audioformat':'mp3'}
with youtube_dl.YoutubeDL(options) as ydl:
ydl.download([link])
def video1080(link):
options={'format':'bestvideo+bestaudio/best'}
with youtube_dl.YoutubeDL(options) as ydl:
ydl.download([link])
def video720(link):
options={'format':'best'}
with youtube_dl.YoutubeDL(options) as ydl:
ydl.download([link])
def download4k(link):
subprocess.call("youtube-dl -f 299+140 {}".format(link))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.