【发布时间】:2021-12-02 11:47:35
【问题描述】:
下午好。我是python的初学者。所以,我试图用 PyTube 制作 YouTube 视频/音频下载器(仅用于教育目的)。我在 youtube 上看过很多视频,我正在努力让这个工具变得更好。所以我添加了视频/音频选择选项和恢复/质量选择选项。好消息是我已经成功制作了视频下载器。但是我在音频下载器中遇到了问题。问题是,PyTube downloads the audio file in MP4 format。我在 google 和 youtube 上搜索过。但我找不到任何解决方案。我想将 mp4 重命名为 mp3(因为文件没问题,但格式不对)。作为初学者,我不知道如何将下载文件保存在其他地方(临时文件夹),然后重命名然后将其传输到输出文件夹。我尝试添加filename=link.title+'mp3'。但它返回此错误:OSError: [Errno 22] Invalid argument: 'G:/Downloaded Videos/Latest English Ringtone | Turkish Bgm Ringtone 2021 | Bad Boy | Attitude Tone | Villain Ringtone.mp3'
这是我的代码:
from pytube import YouTube
link='https://www.youtube.com/watch?v=KrhPrPK2owA'
link=YouTube(link)
print('Title:',link.title+'\n'+'Views:',link.views)
streams=link.streams.filter(type='audio')
kbps_list=[]
itag_list=[]
print('Available Kbps: ',end='')
for s in streams:
i=s.itag
s=s.abr
if s not in kbps_list:
kbps_list.append(s)
itag_list.append(i)
print(s,end=' ')
reso=input('\nEnter Kbps to download: ')
if reso not in kbps_list:
print('This Kbps is not available')
from sys import exit
exit()
reso=kbps_list.index(reso)
final=streams.get_by_itag(itag_list[reso])
print('Downloading...')
final.download('G:/Downloaded Videos/')
# final.download('G:/Downloaded Videos/', filename=link.title+'mp3')======================
# if I add custom filename, It returns the error ========================================
print('Successfully Downloaded!')
【问题讨论】:
标签: python-3.x format pytube