How to find directory of something you've downloaded within python script and move it?

Question:

from genericpath import isdir
from pytube import *
import os
#checks if directory exists, if not creates it
if os.path.isdir('C:/Users/aidan/Downloads/ytDownloader'):
    pass
else:
    os.mkdir('C:/Users/aidan/Downloads/ytDownloader')

playlist_url = Playlist('https://www.youtube.com/playlist?list=PLZYPi8njr7oJLOThbld0Md2x03P2e6qWR')
for url in playlist_url.videos:

    audio = url.streams.get_audio_only().download()
#Here I want to move audio into C:/Users/aidan/Downloads/ytDownloader

I want to put audio into ytDownloader file, I cannot find it on my computer when I run the script even though I’m pretty sure it downloaded. Thanks for any help.

Asked By: aids

||

Answers:

You may specify the output_path in the download function as detailed here.

For instance:

audio = url.streams.get_audio_only().download('C:/Users/aidan/Downloads/ytDownloader')

Answered By: Sheldon