I am trying to create a YouTube video downloader in python using pytube and tkinter. Most of the videos are getting downloaded fine but in some videos I am getting the error as 'cipher'. Can anyone help while this is happening?
Also I am trying to download in mp3 format but setting the 'audioonly' attribute to True downloads my file in mp4 format without the video. But I want the format in mp3. How can I do so?
Here is my code
def startDownload(url):
global file_size
path_to_save = askdirectory()
if path_to_save is None:
return
try:
global MaxFileSize, fileSizeInBytes
choice = youtubeChoicesLabel.get()
url=urlField.get()
yt = YouTube(url)
nome = yt.title
# video2 = urlField.get()
if (choice == download_choices[1]):
print("720p video is downloading")
selectVideo = yt.streams.filter(progressive=True, file_extension='mp4').first()
elif (choice == download_choices[2]):
print("Audio file is downloading")
# selectVideo =yt.streams.get_audio_only()
# new_filename= nome + '*.mp3'
# default_filename= nome + '*.mp4'
# ffmpeg = ('ffmpeg -i ' %path_to_save %default_filename + new_filename)
# subprocess.run(ffmpeg, shell=True)
selectVideo = yt.streams.filter(only_audio=True).first()
elif (choice == download_choices[0]):
return
fileSizeInBytes = selectVideo.filesize
MaxFileSize = fileSizeInBytes/1024000
MB =str(MaxFileSize)+ "MB"
print("File Size = : {:00.000f}".format (MaxFileSize))
# yt = YouTube(url)
# st=yt.streams.first()
st= selectVideo
yt.register_on_complete_callback(complete_download)
yt.register_on_progress_callback(progress_download)
file_size=st.filesize
st.download(output_path=path_to_save)
except Exception as e:
print(e)