我想将用户在表单上输入的链接传递给下载器方法。
from django.shortcuts import render
import pytube
from .forms import VideoDownloadForm
# Create your views here.
def details(request):
if request.method == 'POST':
form = VideoDownloadForm(request.POST, request.FILES)
if form.is_valid():
f = form.cleaned_data['Url']
yt = pytube.YouTube(f)
# videos = yt.streams.filter(progressive=True, type='video', subtype='mp4').order_by('resolution').desc().first()
thumb = yt.thumbnail_url
title = yt.title
return render(request, 'ytdownloader/details.html', { 'title': title, 'thumbnail': thumb})
downloader(yt)
else:
form = VideoDownloadForm()
return render(request, 'ytdownloader/front.html', {'form': form})
def downloader(request, yt):
videos = yt.streams.filter(progressive=True, type='video', subtype='mp4').order_by('resolution').desc().first()
videos.download('C:\\Users\\user\\Downloads')
return render(request, 'ytdownloader/details.html')
错误:
*异常类型:TypeError
异常值:downloader() 缺少 1 个必需的位置参数:'yt'*