如何解决我第二次写的代码中下载并保存的文件下载的时候可以改名字吗?
今天我决定写一个 Youtube 视频下载器,我没有任何问题地管理它。我有一个问题,当我在下面给出的代码中下载视频或声音时,我无法访问第一个下载的文件,因为我第二次没有下载的文件名是相同的。有什么办法可以解决这个问题吗?
from pytube import YouTube
def main():
while True:
link = input("Please enter the Youtube link you want to view : ")
file_path = input("Enter the file path for your downloads:")
yt = YouTube(link)
continuity = True
while continuity:
print("To download in high quality = 1'i\t\b\bTo download in low quality = 2'yi\nTo download as an audio file = 3'ü\t\b\bIf you want to enter another link,please press = 4\n\nTo terminate the program = q")
entry = input()
if entry == "1":
high = yt.streams.get_highest_resolution()
high.download(file_path)
print("Video downloads in high quality...")
elif entry == "2":
low = yt.streams.get_lowest_resolution()
low.download(file_path)
print("Video downloads in low quality...")
elif entry == "3":
audio = yt.streams.get_audio_only()
audio.download(file_path)
print("Downloading audio file...")
elif entry == "4":
print("Please wait...")
continuity = False
elif entry.lower() == "q":
print("Thank you for using our application. \nhttps://github.com/Batuhanaydn")
exit()
else:
print("You entered an unknown login")
break
main()
解决方法
您可以更改正在下载的文件名
stream.download(filename='something')
写入文件名时,不需要包含后缀,例如:.mp4 .mp3
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。