DEV Community

Hussein Ouda
Hussein Ouda

Posted on

Problem with Python video downloader

I programmed a python program to download videos from YouTube

After I put the link and start the download I get the following error:

Exception in Tkinter callback

Traceback (most recent call last):

  File "C:\lib\tkinter\", line 1892, in __call__

    return self.func(*args)

  File "d:\", line 36, in DownloadVideo

    select = yt.streams.filter(progressive=True).first()

  File "C:\lib\site-packages\pytube\", line 292, in streams

    return StreamQuery(self.fmt_streams)

  File "C:\lib\site-packages\pytube\", line 177, in fmt_streams

    extract.apply_signature(stream_manifest, self.vid_info, self.js)

  File "C:\lib\site-packages\pytube\", line 409, in apply_signature

    cipher = Cipher(js=js)

  File "C:\lib\site-packages\pytube\", line 43, in __init__

    self.throttling_plan = get_throttling_plan(js)

  File "C:\lib\site-packages\pytube\", line 387, in get_throttling_plan

    raw_code = get_throttling_function_code(js)

  File "C:\lib\site-packages\pytube\", line 301, in get_throttling_function_code

    code_lines_list = find_object_from_startpoint(js, match.span()[1]).split('\n')

AttributeError: 'NoneType' object has no attribute 'span'

Enter fullscreen mode Exit fullscreen mode

I attach the following code for you:

# Youtube Downloader
from cgitb import text
from logging import root
from random import choices
from secrets import choice
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
from tkinter import filedialog
from typing_extensions import Self
from numpy import save
from pytube import YouTube
from soupsieve import select #pip install pytube3

Folder_Name = ""

#file location
def openLocation():
    global Folder_Name
    Folder_Name = filedialog.askdirectory()
    if(len(Folder_Name) > 1):
        locationError.config(text=Folder_Name, fg="green")
        locationError.config(text="اختر المجلد", fg="red")

#donwload video
def DownloadVideo():
    choice = ytdchoices.get()
    url = ytdEntry.get()

        yt = YouTube(url)

        if(choice == choices[0]):
            select = yt.streams.filter(progressive=True).first()

        elif(choice == choices[1]):
            select = yt.streams.filter(progressive=True, file_extension='mp4').last()

        elif(choice == choices[2]):
            select = yt.streams.filter(only_audio=True).first()

            ytdError.config(text="ألصق الرابط مجدداً", fg="red")

    #download function
    ytdError.config(text="تم الانتهاء من التحميل!!")

# -------- دالة من نحن --------
def about():
    messagebox.showinfo("Techmakers - Hussein Ouda", " : مرحبا بكم في برنامج تحميل الفيديوهات والصوتيات")

root = Tk()
root.title("Techmakers: v 1.0 Youtube Downloader")
root.geometry("650x410+340+10") #set window
root.resizable(False, False)
root.columnconfigure(0, weight=1) #set all content in center.

f1=Frame(root, width=580, height=100, bg='whitesmoke', bd=3, relief=GROOVE), y=130)
f2=Frame(root, width=580, height=55, bg='whitesmoke', bd=3, relief=GROOVE), y=250)

#Ytd Link Label
t = Label(root, text="برنامج تحميل الفيديوهات والصوتيات", bg='#FF5F00', fg='#EEEEEE', font=("Tajawal", 15, 'bold'))

ytdLabel = Label(root, text="ألصق رابط الفيديو",fg='#00092C', font=("Tajawal", 15, 'bold'))

#Entry Box
ytdEntryVar = StringVar()
ytdEntry = Entry(root, width=52, justify='center', font=("Tajawal", 15), bg='#B20600', fg='#00092C', textvariable=ytdEntryVar)

#Error Msg
ytdError = Label(root, text="ملاحظات التحميل", fg="#B20600", font=("Tajawal", 10))

#Asking save file label
saveLabel = Label(root, text="اختر مكان حفظ الفيديو", bg="whitesmoke", fg='#00092C', font=("Tajawal", 15, 'bold')), y=140)

#btn of save file
saveEntry = Button(root, width=20, font=("Tajawal", 10, 'bold'), bg="#00092C", fg="#EEEEEE", text="مسار الحفظ", command=openLocation, cursor='sizing'), y=180)

#Error Msg location
locationError = Label(root, text="لم يتم اختيار مسار حفظ الفيديو", bg='whitesmoke', fg="#B20600", font=("Tajawal", 15)), y=190)

#Download Quality
ytdQuality = Label(root, text="", bg='whitesmoke', font=("Tajawal", 15, 'bold')), y=255)

choices = ["720p", "144p", "صوت فقط"]
ytdchoices = ttk.Combobox(root, values=choices), y=265)

#download btn
downloadbtn = Button(root, text="بدء التحميل", width=20, font=("Tajawal", 10, 'bold'), bg="#00092C", fg="#EEEEEE", command=DownloadVideo, cursor='clock'), y=255)

#developer Label
about_btn = Button(root, text='من نحن', width=20, font=("Tajawal", 10, 'bold'), bg='#FF5F00', fg='#EEEEEE', bitmap='info',command=about, cursor='heart'), y=350, height=30)

#Close program
exit_btn = Button(root, text='إغلاق البرنامج', width=20, font=("Tajawal", 10, 'bold'), bg='#FF5F00', fg='#EEEEEE', cursor='cross', command=root.quit), y=350, width=80, height=30)


Enter fullscreen mode Exit fullscreen mode

Please Help

Discussion (1)

hussein_ouda profile image
Hussein Ouda Author

Problem solved

Turns out when I entered the pytube library code in github I found all the comments confirming that the problem is from the same library but the library has been updated
Now I updated the library and the program really worked without problems
Write :
pip install --upgrade pytube
It will work without problems, allah willing