【问题标题】:How do i change the directory of a downloaded video?如何更改下载视频的目录?
【发布时间】:2021-08-12 14:51:59
【问题描述】:

我使用 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()

【问题讨论】:

  • 为什么不直接移动下载的文件?
  • 我更喜欢学习如何去做。

标签: python tkinter pytube


【解决方案1】:

就像这样:

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")

【讨论】:

  • 感谢您的帮助!
猜你喜欢
  • 2020-09-05
  • 1970-01-01
  • 1970-01-01
  • 2017-06-06
  • 2010-10-20
  • 1970-01-01
  • 2021-04-13
  • 2022-01-23
  • 1970-01-01
相关资源
最近更新 更多