我不知道如何在尝试下载 .mp4 文件时更改 pytube 中的目标文件。
我尝试过(但失败了):
def mp4():
from pytube import YouTube
import os
......(non important code for the question)
# destination to save file
destination = "downloads"
#download the file
out_file = video.download(output_path=destination)
# save the file
base, ext = os.path.splitext(out_file)
new_file = base + '.mp4'
os.rename(out_file, new_file)
# result of success
print(yt.title + " has been successfully downloaded.")
它不起作用,不是因为它给出了错误或错误,而是因为它只是将文件下载到没有目录,而不是“下载”目录。
相反,我希望下载位于“下载”文件夹中。
replit 与所有代码是here