ruslol228
ruslol228

Reputation: 43

Python: How to save .mp3 file in 'Download' folder on Android?

I'm making an application, that will convert Youtube video into .mp3 file using youtube_dl module.

import youtube_dl

def run():
    video_url = input("please enter youtube video url:")
    video_info = youtube_dl.YoutubeDL().extract_info(
        url = video_url,download=False
    )
    filename = f"{video_info['title']}.mp3"
    options={
        'format': 'bestaudio/best',
        'keepvideo': False,
        'outtmpl': filename,
    }

    with youtube_dl.YoutubeDL(options) as ydl:
        ydl.download([video_info['webpage_url']])

    print("Download complete... {}".format(filename))

if __name__=='__main__':
    run()

Well, if I run it and paste a youtube video link, it will download .mp3 file into the same folder where my .py file is. But how can I specify path for Android and let download .mp3 into user's Download folder?

Upvotes: 0

Views: 441

Answers (1)

fusion
fusion

Reputation: 457

Your filename should also contain the path, where you want to put it.

    filename = f"/your/path/to/{video_info['title']}.mp3"

As your Downloads folder is usually under your home directory, you could first find out your home directory as explained here and then prepend this, plus "/Downloads", to your filename variable.

Upvotes: 1

Related Questions