Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
959 views
in Technique[技术] by (71.8m points)

video - How to set 'Downloads' folder as default directory for python pafy downloads

I have a code that downloads video with python pafy module

At default it downloads the video in where my .py file is. But I want the Windows Downloads Folder as the destination of the downloaded video. How can I do it? Thanks in Advance

import pafy

url = "video_url"
video = pafy.new(url)

#all streams
streams = video.streams

#best video
best = video.getbest()

#download
try:
    best.download()
except Exception as e:
    print ("Error Downloading video")
else:
    print ("Video Downloaded Successfully")
question from:https://stackoverflow.com/questions/65559692/how-to-set-downloads-folder-as-default-directory-for-python-pafy-downloads

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Based on the comments.

Initially I thought that you wanted to change the current directory in your machine. Hence, I referenced this question where we can read answers like this one which states that the desired operation can be achieved with

import os

os.chdir(path)

OFC in your particular case you'd want to change the path right before downloading the file.

Since you added more clarification with

What if I want to make it an app and in others computer how can I know there donwload directory folder?

that'd be a different scenario and there's an already existing question for that too with an already accepted answer.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.6k users

...