Python youtube_dl instantly deletes file right after downloading it

805 Views Asked by At

I made this script, and for the most part, it works. However, once it downloads to the /Downloads folder, it instantly deletes it, stating, for example: "[ffmpeg] Destination: C:\Users\bertr\Downloads\Sanford Clark - It's Nothing To Me.mp3 Deleting original file C:\Users\bertr\Downloads\Sanford Clark - It's Nothing To Me.webm (pass -k to keep)"

Is there anything I can do to prevent it from deleting it?

    print("hi")
    link = linkhere.get()
    print(link)
    user = getpass.getuser()

    params = {
        'format': 'bestaudio/best',
        'outtmpl': 'C:/Users/{}/Downloads/%(title)s.%(ext)s'.format(user),
        'postprocessors':[{
            'key': 'FFmpegExtractAudio',
            'preferredcodec': 'mp3',
            'preferredquality': '192',
        }]
    }

    youtube = yt.YoutubeDL(params)
    youtube.download([link])
    print('downloaded file')```

1

There are 1 best solutions below

0
On

You are just downloading a mp3 file so video will not be kept. However you can add 'keepvideo': True to params. So, video will not be deleted.

params = {
    'format': 'bestaudio/best',
    'outtmpl': 'C:/Users/{}/Downloads/%(title)s.%(ext)s'.format(user),
    'keepvideo': True,
    'postprocessors':[{
        'key': 'FFmpegExtractAudio',
        'preferredcodec': 'mp3',
        'preferredquality': '192',
    }]
}