Last active
June 11, 2024 00:16
-
-
Save Yiannis128/dce0674ff9c17108695514ad6891f985 to your computer and use it in GitHub Desktop.
[yt-dlp] GUI Download Music Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Author: Yiannis Charalambous | |
# Simple GUI for YT-DLP Downloading Music | |
import tkinter as tk | |
from tkinter import ttk | |
import pathlib | |
from subprocess import PIPE, STDOUT, run, CompletedProcess | |
# Create the window | |
window = tk.Tk() | |
window.title("YT-DLP GUI Frontend") | |
window.geometry("500x100") | |
window.resizable(False, False) | |
def _download_song(url): | |
target_dir = pathlib.Path.home() / "Downloads" / "%(title)s.mp3" | |
process: CompletedProcess = run( | |
f"yt-dlp --extract-audio --progress --embed-thumbnail --add-metadata --audio-format mp3 --output".split(" ") + [target_dir, url], | |
#stdout=PIPE, | |
#stderr=STDOUT, | |
#timeout=process_timeout, | |
) | |
print(f"Finished: yt-dlp: {process.returncode}") | |
# Call yt-dlp and download song | |
def download_song(): | |
button["state"] = tk.DISABLED | |
button["text"] = "Downloading please wait..." | |
try: | |
_download_song(text_field.get("1.0","end-1c")) | |
button["state"] = tk.NORMAL | |
button["text"] = "Download <3" | |
except: | |
button["text"] = "Error: invalid URL" | |
# Create widgets | |
tk.Label(window, text="Paste Song URL").pack() | |
text_field = tk.Text(window, width=40, height=1) | |
text_field.pack() | |
button = tk.Button(window, text="Download <3", command=download_song) | |
button.pack() | |
#progress = ttk.Progressbar(window, orient="horizontal", length=400, mode="determinate", takefocus=True, maximum=100) | |
#progress.pack() | |
# Start the event loop. | |
window.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment