first commit
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
import os
|
||||
import tkinter as tk
|
||||
from pytube import YouTube
|
||||
|
||||
|
||||
def create_directory(directory):
|
||||
if not os.path.exists(directory):
|
||||
os.makedirs(directory)
|
||||
|
||||
|
||||
def download_video():
|
||||
url = url_entry.get()
|
||||
save_as_mp3 = mp3_var.get()
|
||||
save_as_mp4 = mp4_var.get()
|
||||
selected_quality = quality_var.get()
|
||||
|
||||
if not save_as_mp3 and not save_as_mp4:
|
||||
status_label.config(text="Bitte wählen Sie mindestens ein Format aus.")
|
||||
return
|
||||
|
||||
try:
|
||||
video = YouTube(url)
|
||||
|
||||
if save_as_mp3:
|
||||
audio = video.streams.filter(only_audio=True).first()
|
||||
create_directory("mp3")
|
||||
audio.download(output_path="D:/Youtube Download/mp3/")
|
||||
status_label.config(text="MP3-Datei erfolgreich heruntergeladen.")
|
||||
|
||||
if save_as_mp4:
|
||||
create_directory("mp4")
|
||||
stream = video.streams.filter(progressive=True)
|
||||
filtered_streams = []
|
||||
for s in stream:
|
||||
if s.resolution == selected_quality:
|
||||
filtered_streams.append(s)
|
||||
if len(filtered_streams) > 0:
|
||||
filtered_streams[0].download(output_path="D:/Youtube Download/mp4/")
|
||||
status_label.config(text="MP4-Datei erfolgreich heruntergeladen.")
|
||||
else:
|
||||
status_label.config(text="Kein Stream in der angegebenen Qualität gefunden.")
|
||||
|
||||
except Exception as e:
|
||||
status_label.config(text="Fehler beim Herunterladen: " + str(e))
|
||||
|
||||
|
||||
# GUI erstellen
|
||||
window = tk.Tk()
|
||||
window.title("YouTube Downloader")
|
||||
|
||||
# URL-Eingabefeld
|
||||
url_label = tk.Label(window, text="YouTube-URL:")
|
||||
url_label.pack()
|
||||
url_entry = tk.Entry(window, width=50)
|
||||
url_entry.pack()
|
||||
|
||||
# Auswahlmöglichkeiten für Dateiformate
|
||||
format_label = tk.Label(window, text="Format:")
|
||||
format_label.pack()
|
||||
mp3_var = tk.IntVar()
|
||||
mp3_checkbox = tk.Checkbutton(window, text=".mp3", variable=mp3_var)
|
||||
mp3_checkbox.pack()
|
||||
mp4_var = tk.IntVar()
|
||||
mp4_checkbox = tk.Checkbutton(window, text=".mp4", variable=mp4_var)
|
||||
mp4_checkbox.pack()
|
||||
|
||||
# Auswahlmöglichkeiten für Videoqualität
|
||||
quality_label = tk.Label(window, text="Videoqualität:")
|
||||
quality_label.pack()
|
||||
quality_var = tk.StringVar()
|
||||
quality_var.set("720p") # Standard-Qualität
|
||||
quality_dropdown = tk.OptionMenu(window, quality_var, "144p", "240p", "360p", "480p", "720p")
|
||||
quality_dropdown.pack()
|
||||
|
||||
# Download-Button
|
||||
download_button = tk.Button(window, text="Download", command=download_video)
|
||||
download_button.pack()
|
||||
|
||||
# Statuslabel
|
||||
status_label = tk.Label(window, text="")
|
||||
status_label.pack()
|
||||
|
||||
# GUI starten
|
||||
window.mainloop()
|
||||
Reference in New Issue
Block a user