Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 30b74713af | |||
| 4f823557bc | |||
| 2faaf7aa1c |
+136
-27
@@ -1,6 +1,15 @@
|
|||||||
import os
|
import os
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
|
from tkinter import filedialog
|
||||||
from pytube import YouTube
|
from pytube import YouTube
|
||||||
|
import pickle
|
||||||
|
|
||||||
|
# Output directories for MP3 and MP4 files
|
||||||
|
mp3_output_directory = ""
|
||||||
|
mp4_output_directory = ""
|
||||||
|
|
||||||
|
# File name for storing the directories
|
||||||
|
config_file = "config/directories.pickle"
|
||||||
|
|
||||||
|
|
||||||
def create_directory(directory):
|
def create_directory(directory):
|
||||||
@@ -8,6 +17,90 @@ def create_directory(directory):
|
|||||||
os.makedirs(directory)
|
os.makedirs(directory)
|
||||||
|
|
||||||
|
|
||||||
|
def save_directories():
|
||||||
|
global mp3_output_directory, mp4_output_directory
|
||||||
|
|
||||||
|
directories = {
|
||||||
|
"mp3": mp3_output_directory,
|
||||||
|
"mp4": mp4_output_directory
|
||||||
|
}
|
||||||
|
|
||||||
|
with open(config_file, "wb") as f:
|
||||||
|
pickle.dump(directories, f)
|
||||||
|
|
||||||
|
|
||||||
|
def load_directories():
|
||||||
|
global mp3_output_directory, mp4_output_directory
|
||||||
|
|
||||||
|
if os.path.isfile(config_file):
|
||||||
|
with open(config_file, "rb") as f:
|
||||||
|
directories = pickle.load(f)
|
||||||
|
mp3_output_directory = directories.get("mp3", "")
|
||||||
|
mp4_output_directory = directories.get("mp4", "")
|
||||||
|
|
||||||
|
|
||||||
|
def select_directory(format_type):
|
||||||
|
global mp3_output_directory, mp4_output_directory
|
||||||
|
|
||||||
|
# Open directory selection dialog
|
||||||
|
directory = filedialog.askdirectory()
|
||||||
|
|
||||||
|
if format_type == "mp3":
|
||||||
|
mp3_output_directory = directory
|
||||||
|
elif format_type == "mp4":
|
||||||
|
mp4_output_directory = directory
|
||||||
|
|
||||||
|
|
||||||
|
def open_settings():
|
||||||
|
settings_window = tk.Toplevel(window)
|
||||||
|
settings_window.title("Settings")
|
||||||
|
settings_window.geometry("300x200")
|
||||||
|
|
||||||
|
# MP3 output directory selection
|
||||||
|
mp3_label = tk.Label(settings_window, text="MP3 Output Directory:")
|
||||||
|
mp3_label.pack()
|
||||||
|
|
||||||
|
mp3_directory_entry = tk.Entry(settings_window, width=50)
|
||||||
|
mp3_directory_entry.insert(tk.END, mp3_output_directory)
|
||||||
|
mp3_directory_entry.pack()
|
||||||
|
|
||||||
|
def select_mp3_directory():
|
||||||
|
directory = filedialog.askdirectory()
|
||||||
|
mp3_directory_entry.delete(0, tk.END)
|
||||||
|
mp3_directory_entry.insert(tk.END, directory)
|
||||||
|
|
||||||
|
mp3_directory_button = tk.Button(settings_window, text="Select Directory", command=select_mp3_directory)
|
||||||
|
mp3_directory_button.pack()
|
||||||
|
|
||||||
|
# MP4 output directory selection
|
||||||
|
mp4_label = tk.Label(settings_window, text="MP4 Output Directory:")
|
||||||
|
mp4_label.pack()
|
||||||
|
|
||||||
|
mp4_directory_entry = tk.Entry(settings_window, width=50)
|
||||||
|
mp4_directory_entry.insert(tk.END, mp4_output_directory)
|
||||||
|
mp4_directory_entry.pack()
|
||||||
|
|
||||||
|
def select_mp4_directory():
|
||||||
|
directory = filedialog.askdirectory()
|
||||||
|
mp4_directory_entry.delete(0, tk.END)
|
||||||
|
mp4_directory_entry.insert(tk.END, directory)
|
||||||
|
|
||||||
|
mp4_directory_button = tk.Button(settings_window, text="Select Directory", command=select_mp4_directory)
|
||||||
|
mp4_directory_button.pack()
|
||||||
|
|
||||||
|
def save_settings():
|
||||||
|
global mp3_output_directory, mp4_output_directory
|
||||||
|
|
||||||
|
mp3_output_directory = mp3_directory_entry.get()
|
||||||
|
mp4_output_directory = mp4_directory_entry.get()
|
||||||
|
save_directories()
|
||||||
|
settings_window.destroy()
|
||||||
|
|
||||||
|
# Save button
|
||||||
|
save_button = tk.Button(settings_window, text="Save", command=save_settings)
|
||||||
|
save_button.pack()
|
||||||
|
|
||||||
|
|
||||||
def download_video():
|
def download_video():
|
||||||
url = url_entry.get()
|
url = url_entry.get()
|
||||||
save_as_mp3 = mp3_var.get()
|
save_as_mp3 = mp3_var.get()
|
||||||
@@ -15,7 +108,7 @@ def download_video():
|
|||||||
selected_quality = quality_var.get()
|
selected_quality = quality_var.get()
|
||||||
|
|
||||||
if not save_as_mp3 and not save_as_mp4:
|
if not save_as_mp3 and not save_as_mp4:
|
||||||
status_label.config(text="Bitte wählen Sie mindestens ein Format aus.")
|
status_label.config(text="Please select at least one format.")
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -23,62 +116,78 @@ def download_video():
|
|||||||
|
|
||||||
if save_as_mp3:
|
if save_as_mp3:
|
||||||
audio = video.streams.filter(only_audio=True).first()
|
audio = video.streams.filter(only_audio=True).first()
|
||||||
create_directory("mp3")
|
create_directory(mp3_output_directory)
|
||||||
audio.download(output_path="D:/Youtube Download/mp3/")
|
audio.download(output_path=mp3_output_directory)
|
||||||
status_label.config(text="MP3-Datei erfolgreich heruntergeladen.")
|
status_label.config(text="MP3 file downloaded successfully.")
|
||||||
|
|
||||||
if save_as_mp4:
|
if save_as_mp4:
|
||||||
create_directory("mp4")
|
create_directory(mp4_output_directory)
|
||||||
stream = video.streams.filter(progressive=True)
|
stream = video.streams.filter(progressive=True)
|
||||||
filtered_streams = []
|
filtered_streams = []
|
||||||
for s in stream:
|
for s in stream:
|
||||||
if s.resolution == selected_quality:
|
if s.resolution == selected_quality:
|
||||||
filtered_streams.append(s)
|
filtered_streams.append(s)
|
||||||
if len(filtered_streams) > 0:
|
if len(filtered_streams) > 0:
|
||||||
filtered_streams[0].download(output_path="D:/Youtube Download/mp4/")
|
filtered_streams[0].download(output_path=mp4_output_directory)
|
||||||
status_label.config(text="MP4-Datei erfolgreich heruntergeladen.")
|
status_label.config(text="MP4 file downloaded successfully.")
|
||||||
else:
|
else:
|
||||||
status_label.config(text="Kein Stream in der angegebenen Qualität gefunden.")
|
status_label.config(text="No stream found in the specified quality.")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
status_label.config(text="Fehler beim Herunterladen: " + str(e))
|
status_label.config(text="Error while downloading: " + str(e))
|
||||||
|
|
||||||
|
|
||||||
# GUI erstellen
|
# Create GUI
|
||||||
window = tk.Tk()
|
window = tk.Tk()
|
||||||
window.title("YouTube Downloader")
|
window.title("YouTube Downloader")
|
||||||
|
|
||||||
# URL-Eingabefeld
|
# Set background color
|
||||||
url_label = tk.Label(window, text="YouTube-URL:")
|
window.configure(bg="#f0f0f0")
|
||||||
|
|
||||||
|
# URL entry field
|
||||||
|
url_label = tk.Label(window, text="YouTube URL:", bg="#f0f0f0")
|
||||||
url_label.pack()
|
url_label.pack()
|
||||||
url_entry = tk.Entry(window, width=50)
|
url_entry = tk.Entry(window, width=50)
|
||||||
url_entry.pack()
|
url_entry.pack()
|
||||||
|
|
||||||
# Auswahlmöglichkeiten für Dateiformate
|
# Format selection checkboxes
|
||||||
format_label = tk.Label(window, text="Format:")
|
format_label = tk.Label(window, text="Format:", bg="#f0f0f0")
|
||||||
format_label.pack()
|
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
|
format_frame = tk.Frame(window, bg="#f0f0f0")
|
||||||
quality_label = tk.Label(window, text="Videoqualität:")
|
format_frame.pack()
|
||||||
|
|
||||||
|
mp3_var = tk.IntVar()
|
||||||
|
mp3_checkbox = tk.Checkbutton(format_frame, text=".mp3", variable=mp3_var, bg="#f0f0f0")
|
||||||
|
mp3_checkbox.pack(side=tk.LEFT)
|
||||||
|
|
||||||
|
mp4_var = tk.IntVar()
|
||||||
|
mp4_checkbox = tk.Checkbutton(format_frame, text=".mp4", variable=mp4_var, bg="#f0f0f0")
|
||||||
|
mp4_checkbox.pack(side=tk.LEFT)
|
||||||
|
|
||||||
|
# Video quality selection dropdown
|
||||||
|
quality_label = tk.Label(window, text="Video Quality:", bg="#f0f0f0")
|
||||||
quality_label.pack()
|
quality_label.pack()
|
||||||
quality_var = tk.StringVar()
|
quality_var = tk.StringVar()
|
||||||
quality_var.set("720p") # Standard-Qualität
|
quality_var.set("720p") # Default quality
|
||||||
quality_dropdown = tk.OptionMenu(window, quality_var, "144p", "240p", "360p", "480p", "720p")
|
quality_dropdown = tk.OptionMenu(window, quality_var, "144p", "240p", "360p", "480p", "720p")
|
||||||
|
quality_dropdown.config(bg="#f0f0f0")
|
||||||
quality_dropdown.pack()
|
quality_dropdown.pack()
|
||||||
|
|
||||||
# Download-Button
|
# Download button
|
||||||
download_button = tk.Button(window, text="Download", command=download_video)
|
download_button = tk.Button(window, text="Download", command=download_video, bg="#4CAF50", fg="white")
|
||||||
download_button.pack()
|
download_button.pack()
|
||||||
|
|
||||||
|
# Settings button
|
||||||
|
settings_button = tk.Button(window, text="⚙️", width=2, command=open_settings, bg="#f0f0f0")
|
||||||
|
settings_button.pack(side=tk.RIGHT, padx=10, pady=10)
|
||||||
|
|
||||||
# Status label
|
# Status label
|
||||||
status_label = tk.Label(window, text="")
|
status_label = tk.Label(window, text="", bg="#f0f0f0")
|
||||||
status_label.pack()
|
status_label.pack()
|
||||||
|
|
||||||
# GUI starten
|
# Load directories from config
|
||||||
|
load_directories()
|
||||||
|
|
||||||
|
# Start GUI
|
||||||
window.mainloop()
|
window.mainloop()
|
||||||
|
|||||||
Reference in New Issue
Block a user