python - 第二次下载我写的代码中下载并保存的文件时,我可以更改名称吗?
问题描述
今天我决定写一个 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
推荐阅读
- java - Android:在 3 个活动之间传递相同的变量?
- mod-rewrite - HTTP_REFERER 中应该和不应该包含(或应该转义)哪些字符?
- mysql - 按部门 ID 分组的“部门 LEFT JOIN 产品”的 MySQL 查询未返回所有部门的数据
- python - 使用计时器装饰器来触发电视节目方法
- javascript - WebGL texImage2D 参数
- ssl - 让我们在没有 SNI 的情况下加密证书
- javascript - 如何将数组从我的 Vue 组件导入到 store.js(使用 Vuex 进行状态管理)
- javascript - Webpack 4 sass-loader 导入文件,路径中没有〜波浪号
- python-3.x - Python 3:Beautifulsoup 和缓存
- scala - Akka Http - 多路由和隐式代码的简单反射