I've written the following script to download mp4 videos from youtube using pytube API:
from pytube import YouTube
import sys
SAVE_PATH = input('Enter a saving path: ')
LINK = input('Enter the link of the video: ')
try:
yt = YouTube(LINK)
except:
print('Connection error')
print(yt.title)
items = yt.streams.filter(only_audio=True).all()
stream = items[0]
stream.download()
When i run the code i get the following error :
Connection error
Traceback (most recent call last):
File "C:\Users\Dell\Desktop\Python\youtube.py", line 24, in <module>
print(yt.title)
NameError: name 'yt' is not defined
What's the problem and how can i fix it ?