如何更改下载视频的目录?

How do i change the directory of a downloaded video?

我使用 tkinter 和 pytube 完成了这个简单的 python 程序,用于下载 youtube 视频。 它工作得很好,但我想更改目标文件夹,但不知道如何更改。

from tkinter import*
from pytube import YouTube

root = Tk()
root.geometry('500x300')
root.resizable(0,0)
root.title("Youtube Video Downloader")

Label(root,text = 'Youtube Video Downloader', font = 'arial 20 bold').pack()

#field for entering link
link = StringVar()
Label(root, text='Paste link here:', font = 'arial 15 bold').place(x = 160, y = 60)
link_enter = Entry(root, width = 70, textvariable = link).place(x = 32, y = 90)

#def for downloading
def Downloader():     
 url =YouTube(str(link.get()))
 video = url.streams.first()
 video.download()
 Label(root, text = 'DOWNLOADED', font = 'arial 15').place(x= 180 , y = 210)
 
Button(root,text = 'DOWNLOAD', font = 'arial 15 bold' ,bg = 'pale violet red', padx = 2, command = Downloader).place(x=180 ,y = 150)
root.mainloop()

就像这样:

yt_url = YouTube("your url to the video which should be downloaded")
yt_vid = yt_url.streams.filter(file_extension="mp4").first()
mp4file = yt_vid.download(output_path="path where video should be stored")

因此,您必须将 output_path 放入您的下载函数中:

#def for downloading
def Downloader():     
 url =YouTube(str(link.get()))
 video = url.streams.first()
 video.download(output_path="path where the video should be stored")