我已经学习了python的基础知识,所以在下面尝试了这段代码
from pytube import YouTube
Save_path="E:\python\youtube downloader"
link="https://www.youtube.com/watch?v=xWOoBJUqlbI"
try:
yt=YouTube(link)
except:
print("Connection error!")
mp4file=yt.filter('mp4')
yt.set_filename("ashshak")
d_file=yt.get(mp4files[-1].extention,mp4files[-1].resolution)
try:
d_file.download(Save_path)
except:
print("Error in downlaod")
print("Download failed")
当我尝试使用此代码或使用下面给出的 GUI 界面代码时,编译器将显示此错误。但我已经安装了“pip install pytube”库
Traceback (most recent call last):
File "E:\python\youtube downloader\practiceyoutube.py", line 1, in <module>
from pytube import YouTube
File "C:\Users\PC\AppData\Local\Programs\Python\Python36\lib\site-packages\pytube\__init__.py", line 16, in <module>
from pytube.streams import Stream
File "C:\Users\PC\AppData\Local\Programs\Python\Python36\lib\site-packages\pytube\streams.py", line 17, in <module>
from pytube import extract
File "C:\Users\PC\AppData\Local\Programs\Python\Python36\lib\site-packages\pytube\extract.py", line 7, in <module>
from pytube.compat import quote
ImportError: cannot import name 'quote'
我在这里遇到了什么问题。我已经完成了python的所有基础。所以我渴望在 python 中做一些新的项目。有人可以帮帮我吗?
这是我在这里使用的 GUI 代码,但在这里也出现了同样的问题。
import tkinter as tk
from pytube import YouTube
def downloadVid():
global E1
string =E1.get()
yt = YouTube(str(string))
videos = yt.get_videos()
s=1
for v in videos:
print(str(s) + '.' + str(v))
s +=1
n=int(input("Enter your choice"))
vid=videos[n-1]
destination=str(input("Enter your destination"))
vid.download(destination)
print(yt.filename+"\n Ha been downloaded")
root=tk.Tk()
w=tk.Label(root,text="Youtube Downloader")
w.pack()
E1=tk.Entry(root,bd=5)
E1.pack(side=tk.TOP)
button=tk.Button(root,text="Download",fg="red",command=downloadVid )
button.pack(side=tk.BOTTOM)
root.mainloop()