0

I want to pass the link user entered on a form to the downloader method.

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')

Error:

*Exception Type :TypeError

Exception Value :downloader() missing 1 required positional argument: 'yt'*

theDude
  • 41
  • 1
  • 8
  • 1
    call your downloader function like `downloader(request, yt)`. – Nalin Dobhal Jan 24 '20 at 09:05
  • 1
    But even when you do as @NalinDobhal suggested there is at least one more problem: `downloader` will never get called because of the `return` in the line before. And what do you do with the return value of `downloader`? See also [What is the purpose of the return statement?](https://stackoverflow.com/questions/7129285/what-is-the-purpose-of-the-return-statement) – Ocaso Protal Jan 24 '20 at 09:15
  • pytube is no longer maintained, consider using pytube3 instead – Martin Feb 08 '20 at 22:01

0 Answers0