Skip to content

Instantly share code, notes, and snippets.

@Levyathanus
Last active September 14, 2020 09:50
Show Gist options
  • Save Levyathanus/6414b889ff5275bfd2a78dcd9c37f543 to your computer and use it in GitHub Desktop.
Save Levyathanus/6414b889ff5275bfd2a78dcd9c37f543 to your computer and use it in GitHub Desktop.
Simple python3 youtube mp3 downloader
#### Windows 10 requirements ####
# -> python3 (from Microsoft Store (python 3.8) or official Python website)
# -> youtube_dl (Pip: pip install --upgrade youtube_dl)
# -> ffmpeg (Choco: choco install ffmpeg)
# Launch program with cmd: python3 path\to\mp3Downloader.py
from __future__ import unicode_literals
import youtube_dl
from tkinter import *
window = Tk()
label = Label(text = "YouTube URL: ")
entry = Entry(width = 50)
space1 = Label(text = "")
space2 = Label(text = "")
def mp3_download():
url = entry.get()
print(url)
if url != "":
try:
ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download([url])
except Exception:
print("Invalid URL!")
dl_button = Button(master = window, text = "Download", command = mp3_download)
label.pack()
entry.pack()
space1.pack()
dl_button.pack()
space2.pack()
window.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment