def download_audio():
#try:
b2.config(text="Please wait...")
b2.config(state=DISABLED)
stream = yt.streams.filter(res="480p")
path = filedialog.askdirectory()
if path == None:
return
stream[0].download(path)
for i in os.listdir(path):
os.rename(os.path.join(path,i),os.path.join(path,i.replace(' ','_')))
title = yt.title.replace(' ','_')
print(title)
print(path)
video = VideoFileClip(os.path.join(path+"//"+title+".mp4"))
print(video)
video.audio.write_audiofile(os.path.join(path+"//"+title+".mp3"))
This is the Error message 属性错误:NoneType对象没有属性write_audiofile
答案 0 :(得分:1)
尝试:
def download_audio():
#try:
b2.config(text="Please wait...")
b2.config(state=DISABLED)
stream = yt.streams.filter(res="480p")
path = filedialog.askdirectory()
if path == None:
return
stream[0].download(path)
for i in os.listdir(path):
os.rename(os.path.join(path,i),os.path.join(path,i.replace(' ','_')))
title = yt.title.replace(' ','_')
print(title)
print(path)
video = VideoFileClip(os.path.join(path,title+".mp4"))
print(video)
video.audio.write_audiofile(os.path.join(path,title+".mp3"))
需要在os.path中使用逗号而不是“ //”来构建路径。
答案 1 :(得分:0)
尝试video.write_audiofile(os.path.join(path+"//"+title+".mp3"))
使用ffmpeg转换视频或使用opencv进行所有视频管理可能会更好。
答案 2 :(得分:0)
弄清楚了。 实际上,streams.filter(“ 480p”)给了我一个没有音频的纯视频流,这就是为什么nonetype错误的原因,因为它没有音频对象。 通过执行stream.filter(progressive = True)解决了这个问题。
def download_audio():
#try:
b2.config(text="Please wait...")
b2.config(state=DISABLED)
stream = yt.streams.filter(progressive=True)
path = filedialog.askdirectory()
if path == None:
return
stream[0].download(path)
for i in os.listdir(path):
os.rename(os.path.join(path,i),os.path.join(path,i.replace(' ','_')))
title = yt.title.replace(' ','_')
print(title)
print(path)
video = VideoFileClip(os.path.join(path+"//"+title+".mp4"))
print(video)
video.audio.write_audiofile(os.path.join(path+"//"+title+".mp3"))