Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
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))