YTSage 2.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- YTSage/YTSage.py +1169 -0
- YTSage-2.0.0.dist-info/LICENSE +21 -0
- YTSage-2.0.0.dist-info/METADATA +71 -0
- YTSage-2.0.0.dist-info/RECORD +7 -0
- YTSage-2.0.0.dist-info/WHEEL +5 -0
- YTSage-2.0.0.dist-info/entry_points.txt +2 -0
- YTSage-2.0.0.dist-info/top_level.txt +1 -0
YTSage/YTSage.py
ADDED
|
@@ -0,0 +1,1169 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import os
|
|
3
|
+
import threading
|
|
4
|
+
import time
|
|
5
|
+
from PyQt6.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout,
|
|
6
|
+
QHBoxLayout, QLineEdit, QPushButton, QTableWidget,
|
|
7
|
+
QTableWidgetItem, QProgressBar, QLabel, QFileDialog,
|
|
8
|
+
QHeaderView, QStyle, QStyleFactory, QComboBox, QTextEdit, QDialog, QPlainTextEdit)
|
|
9
|
+
from PyQt6.QtCore import Qt, pyqtSignal, QObject
|
|
10
|
+
from PyQt6.QtGui import QIcon, QPalette, QColor, QPixmap
|
|
11
|
+
import yt_dlp
|
|
12
|
+
import requests
|
|
13
|
+
from io import BytesIO
|
|
14
|
+
from PIL import Image
|
|
15
|
+
from urllib.request import urlopen
|
|
16
|
+
from datetime import datetime
|
|
17
|
+
import json
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
from packaging import version
|
|
20
|
+
import subprocess
|
|
21
|
+
import webbrowser
|
|
22
|
+
|
|
23
|
+
class SignalManager(QObject):
|
|
24
|
+
update_formats = pyqtSignal(list)
|
|
25
|
+
update_status = pyqtSignal(str)
|
|
26
|
+
update_progress = pyqtSignal(float)
|
|
27
|
+
|
|
28
|
+
class LogWindow(QDialog):
|
|
29
|
+
def __init__(self, parent=None):
|
|
30
|
+
super().__init__(parent)
|
|
31
|
+
self.setWindowTitle('yt-dlp Log')
|
|
32
|
+
self.setMinimumSize(700, 500)
|
|
33
|
+
|
|
34
|
+
layout = QVBoxLayout(self)
|
|
35
|
+
|
|
36
|
+
self.log_text = QTextEdit()
|
|
37
|
+
self.log_text.setReadOnly(True)
|
|
38
|
+
self.log_text.setStyleSheet("""
|
|
39
|
+
QTextEdit {
|
|
40
|
+
background-color: #2b2b2b;
|
|
41
|
+
color: #ffffff;
|
|
42
|
+
font-family: Consolas, monospace;
|
|
43
|
+
font-size: 12px;
|
|
44
|
+
border: 2px solid #3d3d3d;
|
|
45
|
+
border-radius: 4px;
|
|
46
|
+
}
|
|
47
|
+
""")
|
|
48
|
+
|
|
49
|
+
layout.addWidget(self.log_text)
|
|
50
|
+
|
|
51
|
+
def append_log(self, message):
|
|
52
|
+
self.log_text.append(message)
|
|
53
|
+
# Auto-scroll to bottom
|
|
54
|
+
scrollbar = self.log_text.verticalScrollBar()
|
|
55
|
+
scrollbar.setValue(scrollbar.maximum())
|
|
56
|
+
|
|
57
|
+
class CustomCommandDialog(QDialog):
|
|
58
|
+
def __init__(self, parent=None):
|
|
59
|
+
super().__init__(parent)
|
|
60
|
+
self.parent = parent
|
|
61
|
+
self.setWindowTitle('Custom yt-dlp Command')
|
|
62
|
+
self.setMinimumSize(600, 400)
|
|
63
|
+
|
|
64
|
+
layout = QVBoxLayout(self)
|
|
65
|
+
|
|
66
|
+
# Help text
|
|
67
|
+
help_text = QLabel(
|
|
68
|
+
"Enter custom yt-dlp commands below. The URL will be automatically appended.\n"
|
|
69
|
+
"Example: --extract-audio --audio-format mp3 --audio-quality 0\n"
|
|
70
|
+
"Note: Download path and output template will be preserved."
|
|
71
|
+
)
|
|
72
|
+
help_text.setWordWrap(True)
|
|
73
|
+
help_text.setStyleSheet("color: #999999; padding: 10px;")
|
|
74
|
+
layout.addWidget(help_text)
|
|
75
|
+
|
|
76
|
+
# Command input
|
|
77
|
+
self.command_input = QPlainTextEdit()
|
|
78
|
+
self.command_input.setPlaceholderText("Enter yt-dlp arguments...")
|
|
79
|
+
self.command_input.setStyleSheet("""
|
|
80
|
+
QPlainTextEdit {
|
|
81
|
+
background-color: #363636;
|
|
82
|
+
color: #ffffff;
|
|
83
|
+
border: 2px solid #3d3d3d;
|
|
84
|
+
border-radius: 4px;
|
|
85
|
+
padding: 8px;
|
|
86
|
+
font-family: Consolas, monospace;
|
|
87
|
+
}
|
|
88
|
+
""")
|
|
89
|
+
layout.addWidget(self.command_input)
|
|
90
|
+
|
|
91
|
+
# Buttons
|
|
92
|
+
button_layout = QHBoxLayout()
|
|
93
|
+
|
|
94
|
+
self.run_btn = QPushButton("Run Command")
|
|
95
|
+
self.run_btn.clicked.connect(self.run_custom_command)
|
|
96
|
+
|
|
97
|
+
self.close_btn = QPushButton("Close")
|
|
98
|
+
self.close_btn.clicked.connect(self.close)
|
|
99
|
+
|
|
100
|
+
button_layout.addWidget(self.run_btn)
|
|
101
|
+
button_layout.addWidget(self.close_btn)
|
|
102
|
+
layout.addLayout(button_layout)
|
|
103
|
+
|
|
104
|
+
# Log output
|
|
105
|
+
self.log_output = QTextEdit()
|
|
106
|
+
self.log_output.setReadOnly(True)
|
|
107
|
+
self.log_output.setStyleSheet("""
|
|
108
|
+
QTextEdit {
|
|
109
|
+
background-color: #2b2b2b;
|
|
110
|
+
color: #ffffff;
|
|
111
|
+
border: 2px solid #3d3d3d;
|
|
112
|
+
border-radius: 4px;
|
|
113
|
+
padding: 8px;
|
|
114
|
+
font-family: Consolas, monospace;
|
|
115
|
+
font-size: 12px;
|
|
116
|
+
}
|
|
117
|
+
""")
|
|
118
|
+
layout.addWidget(self.log_output)
|
|
119
|
+
|
|
120
|
+
self.setStyleSheet("""
|
|
121
|
+
QDialog {
|
|
122
|
+
background-color: #2b2b2b;
|
|
123
|
+
}
|
|
124
|
+
QPushButton {
|
|
125
|
+
padding: 8px 15px;
|
|
126
|
+
background-color: #ff0000;
|
|
127
|
+
border: none;
|
|
128
|
+
border-radius: 4px;
|
|
129
|
+
color: white;
|
|
130
|
+
font-weight: bold;
|
|
131
|
+
}
|
|
132
|
+
QPushButton:hover {
|
|
133
|
+
background-color: #cc0000;
|
|
134
|
+
}
|
|
135
|
+
""")
|
|
136
|
+
|
|
137
|
+
def run_custom_command(self):
|
|
138
|
+
url = self.parent.url_input.text().strip()
|
|
139
|
+
if not url:
|
|
140
|
+
self.log_output.append("Error: No URL provided")
|
|
141
|
+
return
|
|
142
|
+
|
|
143
|
+
command = self.command_input.toPlainText().strip()
|
|
144
|
+
path = self.parent.path_input.text().strip()
|
|
145
|
+
|
|
146
|
+
self.log_output.clear()
|
|
147
|
+
self.log_output.append(f"Running command with URL: {url}")
|
|
148
|
+
self.run_btn.setEnabled(False)
|
|
149
|
+
|
|
150
|
+
# Start command in thread
|
|
151
|
+
threading.Thread(target=self._run_command_thread,
|
|
152
|
+
args=(command, url, path),
|
|
153
|
+
daemon=True).start()
|
|
154
|
+
|
|
155
|
+
def _run_command_thread(self, command, url, path):
|
|
156
|
+
try:
|
|
157
|
+
class CommandLogger:
|
|
158
|
+
def debug(self, msg):
|
|
159
|
+
self.dialog.log_output.append(msg)
|
|
160
|
+
def warning(self, msg):
|
|
161
|
+
self.dialog.log_output.append(f"Warning: {msg}")
|
|
162
|
+
def error(self, msg):
|
|
163
|
+
self.dialog.log_output.append(f"Error: {msg}")
|
|
164
|
+
def __init__(self, dialog):
|
|
165
|
+
self.dialog = dialog
|
|
166
|
+
|
|
167
|
+
# Split command into arguments
|
|
168
|
+
args = command.split()
|
|
169
|
+
|
|
170
|
+
# Base options
|
|
171
|
+
ydl_opts = {
|
|
172
|
+
'logger': CommandLogger(self),
|
|
173
|
+
'paths': {'home': path},
|
|
174
|
+
'debug_printout': True,
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
# Add custom arguments
|
|
178
|
+
for i in range(0, len(args), 2):
|
|
179
|
+
if i + 1 < len(args):
|
|
180
|
+
key = args[i].lstrip('-').replace('-', '_')
|
|
181
|
+
value = args[i + 1]
|
|
182
|
+
try:
|
|
183
|
+
# Try to convert to appropriate type
|
|
184
|
+
if value.lower() in ('true', 'false'):
|
|
185
|
+
value = value.lower() == 'true'
|
|
186
|
+
elif value.isdigit():
|
|
187
|
+
value = int(value)
|
|
188
|
+
ydl_opts[key] = value
|
|
189
|
+
except:
|
|
190
|
+
ydl_opts[key] = value
|
|
191
|
+
|
|
192
|
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
|
193
|
+
ydl.download([url])
|
|
194
|
+
|
|
195
|
+
self.log_output.append("Command completed successfully")
|
|
196
|
+
|
|
197
|
+
except Exception as e:
|
|
198
|
+
self.log_output.append(f"Error: {str(e)}")
|
|
199
|
+
finally:
|
|
200
|
+
self.run_btn.setEnabled(True)
|
|
201
|
+
|
|
202
|
+
class FFmpegCheckDialog(QDialog):
|
|
203
|
+
def __init__(self, parent=None):
|
|
204
|
+
super().__init__(parent)
|
|
205
|
+
self.setWindowTitle('FFmpeg Required')
|
|
206
|
+
self.setMinimumWidth(400)
|
|
207
|
+
|
|
208
|
+
layout = QVBoxLayout(self)
|
|
209
|
+
|
|
210
|
+
# Message
|
|
211
|
+
message_label = QLabel(
|
|
212
|
+
"FFmpeg is not installed. Please install it.\n"
|
|
213
|
+
"To install FFmpeg, click the button below."
|
|
214
|
+
)
|
|
215
|
+
message_label.setWordWrap(True)
|
|
216
|
+
layout.addWidget(message_label)
|
|
217
|
+
|
|
218
|
+
# Install button
|
|
219
|
+
install_btn = QPushButton("Install FFmpeg")
|
|
220
|
+
install_btn.clicked.connect(lambda: webbrowser.open('https://github.com/oop7/ffmpeg-install-guide'))
|
|
221
|
+
layout.addWidget(install_btn)
|
|
222
|
+
|
|
223
|
+
# Close button
|
|
224
|
+
close_btn = QPushButton("Close")
|
|
225
|
+
close_btn.clicked.connect(self.close)
|
|
226
|
+
layout.addWidget(close_btn)
|
|
227
|
+
|
|
228
|
+
# Style the dialog
|
|
229
|
+
self.setStyleSheet("""
|
|
230
|
+
QDialog {
|
|
231
|
+
background-color: #2b2b2b;
|
|
232
|
+
}
|
|
233
|
+
QLabel {
|
|
234
|
+
color: #ffffff;
|
|
235
|
+
font-size: 12px;
|
|
236
|
+
padding: 10px;
|
|
237
|
+
}
|
|
238
|
+
QPushButton {
|
|
239
|
+
padding: 8px 15px;
|
|
240
|
+
background-color: #ff0000;
|
|
241
|
+
border: none;
|
|
242
|
+
border-radius: 4px;
|
|
243
|
+
color: white;
|
|
244
|
+
font-weight: bold;
|
|
245
|
+
}
|
|
246
|
+
QPushButton:hover {
|
|
247
|
+
background-color: #cc0000;
|
|
248
|
+
}
|
|
249
|
+
""")
|
|
250
|
+
|
|
251
|
+
class YTSage(QMainWindow):
|
|
252
|
+
def __init__(self):
|
|
253
|
+
super().__init__()
|
|
254
|
+
# Check for FFmpeg before proceeding
|
|
255
|
+
if not self.check_ffmpeg():
|
|
256
|
+
self.show_ffmpeg_dialog()
|
|
257
|
+
|
|
258
|
+
self.version = "2.0.0"
|
|
259
|
+
self.check_for_updates() # Check for updates on startup
|
|
260
|
+
self.config_file = Path.home() / '.ytsage_config.json'
|
|
261
|
+
self.load_saved_path()
|
|
262
|
+
self.setWindowIcon(self.style().standardIcon(QStyle.StandardPixmap.SP_ArrowDown))
|
|
263
|
+
self.signals = SignalManager()
|
|
264
|
+
self.download_paused = False
|
|
265
|
+
self.current_download = None
|
|
266
|
+
self.log_window = None
|
|
267
|
+
self.show_log = False
|
|
268
|
+
self.download_cancelled = False
|
|
269
|
+
self.init_ui()
|
|
270
|
+
self.setStyleSheet("""
|
|
271
|
+
QMainWindow {
|
|
272
|
+
background-color: #2b2b2b;
|
|
273
|
+
}
|
|
274
|
+
QWidget {
|
|
275
|
+
background-color: #2b2b2b;
|
|
276
|
+
color: #ffffff;
|
|
277
|
+
}
|
|
278
|
+
QLineEdit {
|
|
279
|
+
padding: 8px;
|
|
280
|
+
border: 2px solid #3d3d3d;
|
|
281
|
+
border-radius: 4px;
|
|
282
|
+
background-color: #363636;
|
|
283
|
+
color: #ffffff;
|
|
284
|
+
}
|
|
285
|
+
QPushButton {
|
|
286
|
+
padding: 8px 15px;
|
|
287
|
+
background-color: #ff0000; /* YouTube red */
|
|
288
|
+
border: none;
|
|
289
|
+
border-radius: 4px;
|
|
290
|
+
color: white;
|
|
291
|
+
font-weight: bold;
|
|
292
|
+
}
|
|
293
|
+
QPushButton:hover {
|
|
294
|
+
background-color: #cc0000; /* Darker red on hover */
|
|
295
|
+
}
|
|
296
|
+
QPushButton:pressed {
|
|
297
|
+
background-color: #990000; /* Even darker red when pressed */
|
|
298
|
+
}
|
|
299
|
+
QTableWidget {
|
|
300
|
+
border: 2px solid #3d3d3d;
|
|
301
|
+
border-radius: 4px;
|
|
302
|
+
background-color: #363636;
|
|
303
|
+
gridline-color: #3d3d3d;
|
|
304
|
+
}
|
|
305
|
+
QHeaderView::section {
|
|
306
|
+
background-color: #2b2b2b;
|
|
307
|
+
padding: 5px;
|
|
308
|
+
border: 1px solid #3d3d3d;
|
|
309
|
+
color: #ffffff;
|
|
310
|
+
}
|
|
311
|
+
QProgressBar {
|
|
312
|
+
border: 2px solid #3d3d3d;
|
|
313
|
+
border-radius: 4px;
|
|
314
|
+
text-align: center;
|
|
315
|
+
color: white;
|
|
316
|
+
}
|
|
317
|
+
QProgressBar::chunk {
|
|
318
|
+
background-color: #ff0000; /* YouTube red */
|
|
319
|
+
border-radius: 2px;
|
|
320
|
+
}
|
|
321
|
+
QLabel {
|
|
322
|
+
color: #ffffff;
|
|
323
|
+
}
|
|
324
|
+
/* Style for filter buttons */
|
|
325
|
+
QPushButton.filter-btn {
|
|
326
|
+
background-color: #363636;
|
|
327
|
+
padding: 5px 10px;
|
|
328
|
+
margin: 0 5px;
|
|
329
|
+
}
|
|
330
|
+
QPushButton.filter-btn:checked {
|
|
331
|
+
background-color: #ff0000;
|
|
332
|
+
}
|
|
333
|
+
QPushButton.filter-btn:hover {
|
|
334
|
+
background-color: #444444;
|
|
335
|
+
}
|
|
336
|
+
QPushButton.filter-btn:checked:hover {
|
|
337
|
+
background-color: #cc0000;
|
|
338
|
+
}
|
|
339
|
+
/* Modern Scrollbar Styling */
|
|
340
|
+
QScrollBar:vertical {
|
|
341
|
+
border: none;
|
|
342
|
+
background: #2b2b2b;
|
|
343
|
+
width: 14px;
|
|
344
|
+
margin: 15px 0 15px 0;
|
|
345
|
+
border-radius: 7px;
|
|
346
|
+
}
|
|
347
|
+
QScrollBar::handle:vertical {
|
|
348
|
+
background: #404040;
|
|
349
|
+
min-height: 30px;
|
|
350
|
+
border-radius: 7px;
|
|
351
|
+
}
|
|
352
|
+
QScrollBar::handle:vertical:hover {
|
|
353
|
+
background: #505050;
|
|
354
|
+
}
|
|
355
|
+
QScrollBar::sub-line:vertical {
|
|
356
|
+
border: none;
|
|
357
|
+
background: #2b2b2b;
|
|
358
|
+
height: 15px;
|
|
359
|
+
border-top-left-radius: 7px;
|
|
360
|
+
border-top-right-radius: 7px;
|
|
361
|
+
subcontrol-position: top;
|
|
362
|
+
subcontrol-origin: margin;
|
|
363
|
+
}
|
|
364
|
+
QScrollBar::add-line:vertical {
|
|
365
|
+
border: none;
|
|
366
|
+
background: #2b2b2b;
|
|
367
|
+
height: 15px;
|
|
368
|
+
border-bottom-left-radius: 7px;
|
|
369
|
+
border-bottom-right-radius: 7px;
|
|
370
|
+
subcontrol-position: bottom;
|
|
371
|
+
subcontrol-origin: margin;
|
|
372
|
+
}
|
|
373
|
+
QScrollBar::sub-line:vertical:hover,
|
|
374
|
+
QScrollBar::add-line:vertical:hover {
|
|
375
|
+
background: #404040;
|
|
376
|
+
}
|
|
377
|
+
QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical {
|
|
378
|
+
background: none;
|
|
379
|
+
width: 0;
|
|
380
|
+
height: 0;
|
|
381
|
+
}
|
|
382
|
+
QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {
|
|
383
|
+
background: none;
|
|
384
|
+
}
|
|
385
|
+
/* Horizontal Scrollbar */
|
|
386
|
+
QScrollBar:horizontal {
|
|
387
|
+
border: none;
|
|
388
|
+
background: #2b2b2b;
|
|
389
|
+
height: 14px;
|
|
390
|
+
margin: 0 15px 0 15px;
|
|
391
|
+
border-radius: 7px;
|
|
392
|
+
}
|
|
393
|
+
QScrollBar::handle:horizontal {
|
|
394
|
+
background: #404040;
|
|
395
|
+
min-width: 30px;
|
|
396
|
+
border-radius: 7px;
|
|
397
|
+
}
|
|
398
|
+
QScrollBar::handle:horizontal:hover {
|
|
399
|
+
background: #505050;
|
|
400
|
+
}
|
|
401
|
+
QScrollBar::sub-line:horizontal {
|
|
402
|
+
border: none;
|
|
403
|
+
background: #2b2b2b;
|
|
404
|
+
width: 15px;
|
|
405
|
+
border-top-left-radius: 7px;
|
|
406
|
+
border-bottom-left-radius: 7px;
|
|
407
|
+
subcontrol-position: left;
|
|
408
|
+
subcontrol-origin: margin;
|
|
409
|
+
}
|
|
410
|
+
QScrollBar::add-line:horizontal {
|
|
411
|
+
border: none;
|
|
412
|
+
background: #2b2b2b;
|
|
413
|
+
width: 15px;
|
|
414
|
+
border-top-right-radius: 7px;
|
|
415
|
+
border-bottom-right-radius: 7px;
|
|
416
|
+
subcontrol-position: right;
|
|
417
|
+
subcontrol-origin: margin;
|
|
418
|
+
}
|
|
419
|
+
QScrollBar::sub-line:horizontal:hover,
|
|
420
|
+
QScrollBar::add-line:horizontal:hover {
|
|
421
|
+
background: #404040;
|
|
422
|
+
}
|
|
423
|
+
QScrollBar::up-arrow:horizontal, QScrollBar::down-arrow:horizontal {
|
|
424
|
+
background: none;
|
|
425
|
+
width: 0;
|
|
426
|
+
height: 0;
|
|
427
|
+
}
|
|
428
|
+
QScrollBar::add-page:horizontal, QScrollBar::sub-page:horizontal {
|
|
429
|
+
background: none;
|
|
430
|
+
}
|
|
431
|
+
""")
|
|
432
|
+
self.signals.update_progress.connect(self.update_progress_bar)
|
|
433
|
+
|
|
434
|
+
def load_saved_path(self):
|
|
435
|
+
try:
|
|
436
|
+
if self.config_file.exists():
|
|
437
|
+
with open(self.config_file, 'r') as f:
|
|
438
|
+
config = json.load(f)
|
|
439
|
+
saved_path = config.get('download_path', '')
|
|
440
|
+
if os.path.exists(saved_path):
|
|
441
|
+
self.last_path = saved_path
|
|
442
|
+
else:
|
|
443
|
+
self.last_path = str(Path.home() / 'Downloads')
|
|
444
|
+
else:
|
|
445
|
+
self.last_path = str(Path.home() / 'Downloads')
|
|
446
|
+
except Exception as e:
|
|
447
|
+
print(f"Error loading saved path: {e}")
|
|
448
|
+
self.last_path = str(Path.home() / 'Downloads')
|
|
449
|
+
|
|
450
|
+
def save_path(self, path):
|
|
451
|
+
try:
|
|
452
|
+
config = {'download_path': path}
|
|
453
|
+
with open(self.config_file, 'w') as f:
|
|
454
|
+
json.dump(config, f)
|
|
455
|
+
except Exception as e:
|
|
456
|
+
print(f"Error saving path: {e}")
|
|
457
|
+
|
|
458
|
+
def init_ui(self):
|
|
459
|
+
self.setWindowTitle('YTSage v2.0.0')
|
|
460
|
+
self.setMinimumSize(900, 600)
|
|
461
|
+
|
|
462
|
+
# Main widget and layout
|
|
463
|
+
main_widget = QWidget()
|
|
464
|
+
self.setCentralWidget(main_widget)
|
|
465
|
+
layout = QVBoxLayout(main_widget)
|
|
466
|
+
layout.setSpacing(10)
|
|
467
|
+
layout.setContentsMargins(20, 20, 20, 20)
|
|
468
|
+
|
|
469
|
+
# URL input section
|
|
470
|
+
url_layout = QHBoxLayout()
|
|
471
|
+
self.url_input = QLineEdit()
|
|
472
|
+
self.url_input.setPlaceholderText('Enter YouTube URL...')
|
|
473
|
+
self.analyze_btn = QPushButton('Analyze')
|
|
474
|
+
self.analyze_btn.clicked.connect(self.analyze_url)
|
|
475
|
+
url_layout.addWidget(self.url_input)
|
|
476
|
+
url_layout.addWidget(self.analyze_btn)
|
|
477
|
+
layout.addLayout(url_layout)
|
|
478
|
+
|
|
479
|
+
# Create a horizontal layout for thumbnail and video info
|
|
480
|
+
media_info_layout = QHBoxLayout()
|
|
481
|
+
|
|
482
|
+
# Thumbnail on the left
|
|
483
|
+
self.thumbnail_label = QLabel()
|
|
484
|
+
self.thumbnail_label.setFixedSize(320, 180)
|
|
485
|
+
self.thumbnail_label.setStyleSheet("border: 2px solid #3d3d3d; border-radius: 4px;")
|
|
486
|
+
self.thumbnail_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
|
487
|
+
media_info_layout.addWidget(self.thumbnail_label)
|
|
488
|
+
|
|
489
|
+
# Video information on the right
|
|
490
|
+
video_info_layout = QVBoxLayout()
|
|
491
|
+
self.title_label = QLabel()
|
|
492
|
+
self.title_label.setWordWrap(True)
|
|
493
|
+
self.title_label.setStyleSheet("font-size: 14px; font-weight: bold;")
|
|
494
|
+
|
|
495
|
+
self.channel_label = QLabel()
|
|
496
|
+
self.views_label = QLabel()
|
|
497
|
+
self.date_label = QLabel()
|
|
498
|
+
self.duration_label = QLabel()
|
|
499
|
+
|
|
500
|
+
# Subtitle section
|
|
501
|
+
subtitle_layout = QHBoxLayout()
|
|
502
|
+
self.subtitle_check = QPushButton("Download Subtitles")
|
|
503
|
+
self.subtitle_check.setCheckable(True)
|
|
504
|
+
self.subtitle_check.clicked.connect(self.toggle_subtitle_list)
|
|
505
|
+
subtitle_layout.addWidget(self.subtitle_check)
|
|
506
|
+
|
|
507
|
+
self.subtitle_combo = QComboBox()
|
|
508
|
+
self.subtitle_combo.setVisible(False)
|
|
509
|
+
subtitle_layout.addWidget(self.subtitle_combo)
|
|
510
|
+
subtitle_layout.addStretch()
|
|
511
|
+
|
|
512
|
+
# Add all info widgets to the video info layout
|
|
513
|
+
video_info_layout.addWidget(self.title_label)
|
|
514
|
+
video_info_layout.addWidget(self.channel_label)
|
|
515
|
+
video_info_layout.addWidget(self.views_label)
|
|
516
|
+
video_info_layout.addWidget(self.date_label)
|
|
517
|
+
video_info_layout.addWidget(self.duration_label)
|
|
518
|
+
video_info_layout.addLayout(subtitle_layout)
|
|
519
|
+
video_info_layout.addStretch()
|
|
520
|
+
|
|
521
|
+
media_info_layout.addLayout(video_info_layout)
|
|
522
|
+
layout.addLayout(media_info_layout)
|
|
523
|
+
|
|
524
|
+
# Add playlist information section
|
|
525
|
+
self.playlist_info_label = QLabel()
|
|
526
|
+
self.playlist_info_label.setVisible(False)
|
|
527
|
+
self.playlist_info_label.setStyleSheet("font-size: 12px; color: #ff9900;")
|
|
528
|
+
layout.addWidget(self.playlist_info_label)
|
|
529
|
+
|
|
530
|
+
# Simplified format filter buttons
|
|
531
|
+
filter_layout = QHBoxLayout()
|
|
532
|
+
self.filter_label = QLabel("Show formats:")
|
|
533
|
+
filter_layout.addWidget(self.filter_label)
|
|
534
|
+
|
|
535
|
+
self.video_btn = QPushButton("Video")
|
|
536
|
+
self.video_btn.setCheckable(True)
|
|
537
|
+
self.video_btn.setChecked(True)
|
|
538
|
+
self.video_btn.clicked.connect(self.filter_formats)
|
|
539
|
+
self.video_btn.setProperty("class", "filter-btn")
|
|
540
|
+
|
|
541
|
+
self.audio_btn = QPushButton("Audio Only")
|
|
542
|
+
self.audio_btn.setCheckable(True)
|
|
543
|
+
self.audio_btn.clicked.connect(self.filter_formats)
|
|
544
|
+
self.audio_btn.setProperty("class", "filter-btn")
|
|
545
|
+
|
|
546
|
+
filter_layout.addWidget(self.video_btn)
|
|
547
|
+
filter_layout.addWidget(self.audio_btn)
|
|
548
|
+
filter_layout.addStretch()
|
|
549
|
+
layout.addLayout(filter_layout)
|
|
550
|
+
|
|
551
|
+
# Format table
|
|
552
|
+
self.format_table = QTableWidget()
|
|
553
|
+
self.format_table.setColumnCount(6)
|
|
554
|
+
self.format_table.setHorizontalHeaderLabels(['Format ID', 'Extension', 'Resolution', 'File Size', 'Codec', 'Audio'])
|
|
555
|
+
self.format_table.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.Stretch)
|
|
556
|
+
layout.addWidget(self.format_table)
|
|
557
|
+
|
|
558
|
+
# Store formats for filtering
|
|
559
|
+
self.all_formats = []
|
|
560
|
+
|
|
561
|
+
# Download section
|
|
562
|
+
download_layout = QHBoxLayout()
|
|
563
|
+
self.path_input = QLineEdit()
|
|
564
|
+
self.path_input.setPlaceholderText('Download path...')
|
|
565
|
+
self.path_input.setText(self.last_path)
|
|
566
|
+
self.browse_btn = QPushButton('Browse')
|
|
567
|
+
self.browse_btn.clicked.connect(self.browse_path)
|
|
568
|
+
|
|
569
|
+
# Create download control buttons
|
|
570
|
+
self.download_btn = QPushButton('Download')
|
|
571
|
+
self.download_btn.clicked.connect(self.start_download)
|
|
572
|
+
|
|
573
|
+
self.pause_btn = QPushButton('Pause')
|
|
574
|
+
self.pause_btn.clicked.connect(self.toggle_pause)
|
|
575
|
+
self.pause_btn.setVisible(False)
|
|
576
|
+
|
|
577
|
+
# Add cancel button
|
|
578
|
+
self.cancel_btn = QPushButton('Cancel')
|
|
579
|
+
self.cancel_btn.clicked.connect(self.cancel_download)
|
|
580
|
+
self.cancel_btn.setVisible(False)
|
|
581
|
+
|
|
582
|
+
# Add log button
|
|
583
|
+
self.log_btn = QPushButton('yt-dlp Log')
|
|
584
|
+
self.log_btn.setCheckable(True)
|
|
585
|
+
self.log_btn.clicked.connect(self.toggle_log_window)
|
|
586
|
+
download_layout.addWidget(self.log_btn)
|
|
587
|
+
|
|
588
|
+
# Add custom command button to download_layout
|
|
589
|
+
self.custom_cmd_btn = QPushButton('Custom Command')
|
|
590
|
+
self.custom_cmd_btn.clicked.connect(self.show_custom_command)
|
|
591
|
+
download_layout.addWidget(self.custom_cmd_btn)
|
|
592
|
+
|
|
593
|
+
download_layout.addWidget(self.path_input)
|
|
594
|
+
download_layout.addWidget(self.browse_btn)
|
|
595
|
+
download_layout.addWidget(self.download_btn)
|
|
596
|
+
download_layout.addWidget(self.pause_btn)
|
|
597
|
+
download_layout.addWidget(self.cancel_btn)
|
|
598
|
+
layout.addLayout(download_layout)
|
|
599
|
+
|
|
600
|
+
# Progress section
|
|
601
|
+
progress_layout = QVBoxLayout()
|
|
602
|
+
self.progress_bar = QProgressBar()
|
|
603
|
+
progress_layout.addWidget(self.progress_bar)
|
|
604
|
+
|
|
605
|
+
# Add download details label
|
|
606
|
+
self.download_details_label = QLabel()
|
|
607
|
+
self.download_details_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
|
608
|
+
progress_layout.addWidget(self.download_details_label)
|
|
609
|
+
|
|
610
|
+
self.status_label = QLabel('Ready')
|
|
611
|
+
self.status_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
|
612
|
+
progress_layout.addWidget(self.status_label)
|
|
613
|
+
|
|
614
|
+
layout.addLayout(progress_layout)
|
|
615
|
+
|
|
616
|
+
# Connect signals
|
|
617
|
+
self.signals.update_formats.connect(self.update_format_table)
|
|
618
|
+
self.signals.update_status.connect(self.status_label.setText)
|
|
619
|
+
self.signals.update_progress.connect(self.update_progress_bar)
|
|
620
|
+
|
|
621
|
+
def analyze_url(self):
|
|
622
|
+
url = self.url_input.text().strip()
|
|
623
|
+
if not url:
|
|
624
|
+
self.signals.update_status.emit("Invalid URL or please enter a URL.")
|
|
625
|
+
return
|
|
626
|
+
|
|
627
|
+
self.signals.update_status.emit("Analyzing...")
|
|
628
|
+
threading.Thread(target=self._analyze_url_thread, args=(url,), daemon=True).start()
|
|
629
|
+
|
|
630
|
+
def _analyze_url_thread(self, url):
|
|
631
|
+
try:
|
|
632
|
+
# Clean up the URL to handle both playlist and video URLs
|
|
633
|
+
if 'list=' in url and 'watch?v=' in url:
|
|
634
|
+
# Extract playlist ID
|
|
635
|
+
playlist_id = url.split('list=')[1].split('&')[0]
|
|
636
|
+
url = f'https://www.youtube.com/playlist?list={playlist_id}'
|
|
637
|
+
|
|
638
|
+
# Initial extraction with basic options
|
|
639
|
+
ydl_opts = {
|
|
640
|
+
'quiet': True,
|
|
641
|
+
'no_warnings': True,
|
|
642
|
+
'extract_flat': True,
|
|
643
|
+
'force_generic_extractor': False,
|
|
644
|
+
'ignoreerrors': True,
|
|
645
|
+
'no_color': True
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
|
649
|
+
try:
|
|
650
|
+
basic_info = ydl.extract_info(url, download=False)
|
|
651
|
+
except Exception as e:
|
|
652
|
+
print(f"First extraction failed: {str(e)}")
|
|
653
|
+
raise Exception("Could not extract video information")
|
|
654
|
+
|
|
655
|
+
# Configure options for detailed extraction
|
|
656
|
+
ydl_opts.update({
|
|
657
|
+
'extract_flat': False,
|
|
658
|
+
'format': 'best', # Start with best format to ensure we get some formats
|
|
659
|
+
'writesubtitles': True,
|
|
660
|
+
'allsubtitles': True,
|
|
661
|
+
'writeautomaticsub': True,
|
|
662
|
+
'playliststart': 1,
|
|
663
|
+
'playlistend': 1 # Only get first video initially
|
|
664
|
+
})
|
|
665
|
+
|
|
666
|
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
|
667
|
+
try:
|
|
668
|
+
if basic_info.get('_type') == 'playlist':
|
|
669
|
+
self.is_playlist = True
|
|
670
|
+
self.playlist_info = basic_info
|
|
671
|
+
|
|
672
|
+
# Get the first video URL from the playlist
|
|
673
|
+
first_video = None
|
|
674
|
+
for entry in basic_info['entries']:
|
|
675
|
+
if entry:
|
|
676
|
+
first_video = entry
|
|
677
|
+
break
|
|
678
|
+
|
|
679
|
+
if not first_video:
|
|
680
|
+
raise Exception("No valid videos found in playlist")
|
|
681
|
+
|
|
682
|
+
# Get the video URL
|
|
683
|
+
video_url = first_video.get('url') or first_video.get('webpage_url')
|
|
684
|
+
if not video_url:
|
|
685
|
+
raise Exception("Could not extract video URL from playlist")
|
|
686
|
+
|
|
687
|
+
# Extract detailed information for the first video
|
|
688
|
+
self.video_info = ydl.extract_info(video_url, download=False)
|
|
689
|
+
|
|
690
|
+
# Update playlist info
|
|
691
|
+
playlist_text = f"Playlist: {basic_info.get('title', 'Unknown')} | {len(basic_info['entries'])} videos"
|
|
692
|
+
self.playlist_info_label.setText(playlist_text)
|
|
693
|
+
self.playlist_info_label.setVisible(True)
|
|
694
|
+
else:
|
|
695
|
+
self.is_playlist = False
|
|
696
|
+
self.video_info = ydl.extract_info(url, download=False)
|
|
697
|
+
self.playlist_info_label.setVisible(False)
|
|
698
|
+
|
|
699
|
+
# Verify we have format information
|
|
700
|
+
if not self.video_info or 'formats' not in self.video_info:
|
|
701
|
+
print(f"Debug - video_info keys: {self.video_info.keys() if self.video_info else 'None'}")
|
|
702
|
+
raise Exception("No format information available")
|
|
703
|
+
|
|
704
|
+
self.all_formats = self.video_info['formats']
|
|
705
|
+
|
|
706
|
+
# Update UI
|
|
707
|
+
self.signals.update_status.emit("Updating video information...")
|
|
708
|
+
self.update_video_info(self.video_info)
|
|
709
|
+
|
|
710
|
+
# Update thumbnail
|
|
711
|
+
thumbnail_url = self.video_info.get('thumbnail')
|
|
712
|
+
if thumbnail_url:
|
|
713
|
+
self.download_thumbnail(thumbnail_url)
|
|
714
|
+
|
|
715
|
+
# Update subtitles
|
|
716
|
+
self.available_subtitles = self.video_info.get('subtitles', {})
|
|
717
|
+
self.available_automatic_subtitles = self.video_info.get('automatic_captions', {})
|
|
718
|
+
self.update_subtitle_list()
|
|
719
|
+
|
|
720
|
+
# Update format table
|
|
721
|
+
self.video_btn.setChecked(True)
|
|
722
|
+
self.audio_btn.setChecked(False)
|
|
723
|
+
self.filter_formats()
|
|
724
|
+
|
|
725
|
+
self.signals.update_status.emit("Analysis complete")
|
|
726
|
+
|
|
727
|
+
except Exception as e:
|
|
728
|
+
print(f"Detailed extraction failed: {str(e)}")
|
|
729
|
+
raise Exception(f"Failed to extract video details: {str(e)}")
|
|
730
|
+
|
|
731
|
+
except Exception as e:
|
|
732
|
+
error_message = str(e)
|
|
733
|
+
print(f"Error in analysis: {error_message}")
|
|
734
|
+
self.signals.update_status.emit(f"Error: {error_message}")
|
|
735
|
+
|
|
736
|
+
def update_video_info(self, info):
|
|
737
|
+
# Format view count with commas
|
|
738
|
+
views = int(info.get('view_count', 0))
|
|
739
|
+
formatted_views = f"{views:,}"
|
|
740
|
+
|
|
741
|
+
# Format upload date
|
|
742
|
+
upload_date = info.get('upload_date', '')
|
|
743
|
+
if upload_date:
|
|
744
|
+
date_obj = datetime.strptime(upload_date, '%Y%m%d')
|
|
745
|
+
formatted_date = date_obj.strftime('%B %d, %Y')
|
|
746
|
+
else:
|
|
747
|
+
formatted_date = 'Unknown date'
|
|
748
|
+
|
|
749
|
+
# Format duration
|
|
750
|
+
duration = info.get('duration', 0)
|
|
751
|
+
minutes = duration // 60
|
|
752
|
+
seconds = duration % 60
|
|
753
|
+
duration_str = f"{minutes}:{seconds:02d}"
|
|
754
|
+
|
|
755
|
+
# Update labels
|
|
756
|
+
self.title_label.setText(info.get('title', 'Unknown title'))
|
|
757
|
+
self.channel_label.setText(f"Channel: {info.get('uploader', 'Unknown channel')}")
|
|
758
|
+
self.views_label.setText(f"Views: {formatted_views}")
|
|
759
|
+
self.date_label.setText(f"Upload date: {formatted_date}")
|
|
760
|
+
self.duration_label.setText(f"Duration: {duration_str}")
|
|
761
|
+
|
|
762
|
+
def toggle_subtitle_list(self):
|
|
763
|
+
self.subtitle_combo.setVisible(self.subtitle_check.isChecked())
|
|
764
|
+
|
|
765
|
+
def update_subtitle_list(self):
|
|
766
|
+
self.subtitle_combo.clear()
|
|
767
|
+
|
|
768
|
+
if not (self.available_subtitles or self.available_automatic_subtitles):
|
|
769
|
+
self.subtitle_combo.addItem("No subtitles available")
|
|
770
|
+
return
|
|
771
|
+
|
|
772
|
+
self.subtitle_combo.addItem("Select subtitle language")
|
|
773
|
+
|
|
774
|
+
# Add manual subtitles
|
|
775
|
+
for lang_code, subtitle_info in self.available_subtitles.items():
|
|
776
|
+
self.subtitle_combo.addItem(f"{lang_code} - Manual")
|
|
777
|
+
|
|
778
|
+
# Add auto-generated subtitles
|
|
779
|
+
for lang_code, subtitle_info in self.available_automatic_subtitles.items():
|
|
780
|
+
self.subtitle_combo.addItem(f"{lang_code} - Auto-generated")
|
|
781
|
+
|
|
782
|
+
def download_thumbnail(self, url):
|
|
783
|
+
try:
|
|
784
|
+
response = requests.get(url)
|
|
785
|
+
image = Image.open(BytesIO(response.content))
|
|
786
|
+
image = image.resize((320, 180), Image.Resampling.LANCZOS)
|
|
787
|
+
img_byte_arr = BytesIO()
|
|
788
|
+
image.save(img_byte_arr, format='PNG')
|
|
789
|
+
img_byte_arr = img_byte_arr.getvalue()
|
|
790
|
+
|
|
791
|
+
pixmap = QPixmap()
|
|
792
|
+
pixmap.loadFromData(img_byte_arr)
|
|
793
|
+
self.thumbnail_label.setPixmap(pixmap)
|
|
794
|
+
except Exception as e:
|
|
795
|
+
print(f"Error loading thumbnail: {str(e)}")
|
|
796
|
+
|
|
797
|
+
def filter_formats(self):
|
|
798
|
+
# Clear current table
|
|
799
|
+
self.format_table.setRowCount(0)
|
|
800
|
+
|
|
801
|
+
# Determine which formats to show
|
|
802
|
+
filtered_formats = []
|
|
803
|
+
|
|
804
|
+
if self.video_btn.isChecked():
|
|
805
|
+
# Include all video formats (both with and without audio)
|
|
806
|
+
filtered_formats.extend([f for f in self.all_formats
|
|
807
|
+
if f.get('vcodec') != 'none'
|
|
808
|
+
and f.get('filesize') is not None])
|
|
809
|
+
|
|
810
|
+
if self.audio_btn.isChecked():
|
|
811
|
+
# Add audio-only formats
|
|
812
|
+
filtered_formats.extend([f for f in self.all_formats
|
|
813
|
+
if (f.get('vcodec') == 'none'
|
|
814
|
+
or 'audio only' in f.get('format_note', '').lower())
|
|
815
|
+
and f.get('acodec') != 'none'
|
|
816
|
+
and f.get('filesize') is not None])
|
|
817
|
+
|
|
818
|
+
# Sort formats by quality
|
|
819
|
+
def get_quality(f):
|
|
820
|
+
if f.get('vcodec') != 'none':
|
|
821
|
+
# Extract height from resolution (e.g., "1920x1080" -> 1080)
|
|
822
|
+
res = f.get('resolution', '0x0').split('x')[-1]
|
|
823
|
+
try:
|
|
824
|
+
return int(res)
|
|
825
|
+
except ValueError:
|
|
826
|
+
return 0
|
|
827
|
+
else:
|
|
828
|
+
return f.get('abr', 0)
|
|
829
|
+
|
|
830
|
+
filtered_formats.sort(key=get_quality, reverse=True)
|
|
831
|
+
|
|
832
|
+
# Update table with filtered formats
|
|
833
|
+
self.update_format_table(filtered_formats)
|
|
834
|
+
|
|
835
|
+
def update_format_table(self, formats):
|
|
836
|
+
self.format_table.setRowCount(0)
|
|
837
|
+
for f in formats:
|
|
838
|
+
row = self.format_table.rowCount()
|
|
839
|
+
self.format_table.insertRow(row)
|
|
840
|
+
|
|
841
|
+
# Format ID
|
|
842
|
+
self.format_table.setItem(row, 0, QTableWidgetItem(str(f.get('format_id', ''))))
|
|
843
|
+
|
|
844
|
+
# Extension
|
|
845
|
+
self.format_table.setItem(row, 1, QTableWidgetItem(f.get('ext', '')))
|
|
846
|
+
|
|
847
|
+
# Resolution
|
|
848
|
+
resolution = f.get('resolution', 'N/A')
|
|
849
|
+
if f.get('vcodec') == 'none':
|
|
850
|
+
resolution = 'Audio only'
|
|
851
|
+
self.format_table.setItem(row, 2, QTableWidgetItem(resolution))
|
|
852
|
+
|
|
853
|
+
# File Size
|
|
854
|
+
filesize = f"{f.get('filesize', 0) / 1024 / 1024:.2f} MB"
|
|
855
|
+
self.format_table.setItem(row, 3, QTableWidgetItem(filesize))
|
|
856
|
+
|
|
857
|
+
# Codec
|
|
858
|
+
if f.get('vcodec') == 'none':
|
|
859
|
+
codec = f.get('acodec', 'N/A')
|
|
860
|
+
else:
|
|
861
|
+
codec = f"{f.get('vcodec', 'N/A')}"
|
|
862
|
+
if f.get('acodec') != 'none':
|
|
863
|
+
codec += f" / {f.get('acodec', 'N/A')}"
|
|
864
|
+
self.format_table.setItem(row, 4, QTableWidgetItem(codec))
|
|
865
|
+
|
|
866
|
+
# Audio Status
|
|
867
|
+
needs_audio = f.get('acodec') == 'none'
|
|
868
|
+
audio_status = "Will merge audio" if needs_audio else "✓ Has Audio"
|
|
869
|
+
audio_item = QTableWidgetItem(audio_status)
|
|
870
|
+
if needs_audio:
|
|
871
|
+
audio_item.setForeground(QColor('#ffa500')) # Orange for merge indication
|
|
872
|
+
self.format_table.setItem(row, 5, audio_item)
|
|
873
|
+
|
|
874
|
+
def browse_path(self):
|
|
875
|
+
path = QFileDialog.getExistingDirectory(self, "Select Download Directory", self.last_path)
|
|
876
|
+
if path:
|
|
877
|
+
self.path_input.setText(path)
|
|
878
|
+
self.save_path(path)
|
|
879
|
+
self.last_path = path
|
|
880
|
+
|
|
881
|
+
def start_download(self):
|
|
882
|
+
url = self.url_input.text()
|
|
883
|
+
path = self.path_input.text().strip()
|
|
884
|
+
|
|
885
|
+
# Path validation
|
|
886
|
+
if not path:
|
|
887
|
+
self.signals.update_status.emit("Invalid path or please enter a path.")
|
|
888
|
+
return
|
|
889
|
+
|
|
890
|
+
selected_items = self.format_table.selectedItems()
|
|
891
|
+
if not selected_items:
|
|
892
|
+
self.signals.update_status.emit("Please select a format")
|
|
893
|
+
return
|
|
894
|
+
|
|
895
|
+
format_id = self.format_table.item(selected_items[0].row(), 0).text()
|
|
896
|
+
|
|
897
|
+
# If it's a video format, also download the best audio
|
|
898
|
+
selected_format = next((f for f in self.all_formats if str(f.get('format_id')) == format_id), None)
|
|
899
|
+
if selected_format and selected_format.get('acodec') == 'none':
|
|
900
|
+
format_id = f"{format_id}+bestaudio"
|
|
901
|
+
|
|
902
|
+
# Check if subtitles should be downloaded
|
|
903
|
+
download_subs = self.subtitle_check.isChecked()
|
|
904
|
+
selected_sub = self.subtitle_combo.currentText().split(' - ')[0] if download_subs else None
|
|
905
|
+
|
|
906
|
+
self.download_paused = False
|
|
907
|
+
self.download_cancelled = False
|
|
908
|
+
self.pause_btn.setText('Pause')
|
|
909
|
+
self.download_btn.setEnabled(False)
|
|
910
|
+
self.pause_btn.setVisible(True)
|
|
911
|
+
self.cancel_btn.setVisible(True)
|
|
912
|
+
|
|
913
|
+
threading.Thread(target=self._download_thread,
|
|
914
|
+
args=(url, path, format_id, selected_sub, self.is_playlist),
|
|
915
|
+
daemon=True).start()
|
|
916
|
+
|
|
917
|
+
def _download_thread(self, url, path, format_id, subtitle_lang=None, is_playlist=False):
|
|
918
|
+
try:
|
|
919
|
+
class DebugLogger:
|
|
920
|
+
def debug(self, msg):
|
|
921
|
+
# Update both status and log window
|
|
922
|
+
if any(x in msg.lower() for x in ['downloading webpage', 'downloading api', 'extracting', 'downloading m3u8']):
|
|
923
|
+
self.signals.update_status.emit("Preparing for download...")
|
|
924
|
+
self.signals.update_progress.emit(0)
|
|
925
|
+
if self.parent.show_log and self.parent.log_window:
|
|
926
|
+
self.parent.log_window.append_log(msg)
|
|
927
|
+
|
|
928
|
+
def warning(self, msg):
|
|
929
|
+
if self.parent.show_log and self.parent.log_window:
|
|
930
|
+
self.parent.log_window.append_log(f"Warning: {msg}")
|
|
931
|
+
|
|
932
|
+
def error(self, msg):
|
|
933
|
+
if self.parent.show_log and self.parent.log_window:
|
|
934
|
+
self.parent.log_window.append_log(f"Error: {msg}")
|
|
935
|
+
|
|
936
|
+
def __init__(self, signals, parent):
|
|
937
|
+
self.signals = signals
|
|
938
|
+
self.parent = parent
|
|
939
|
+
|
|
940
|
+
class CancelHandler:
|
|
941
|
+
def __init__(self, parent):
|
|
942
|
+
self.parent = parent
|
|
943
|
+
|
|
944
|
+
def __call__(self, signum, frame):
|
|
945
|
+
return self.parent.download_cancelled
|
|
946
|
+
|
|
947
|
+
ydl_opts = {
|
|
948
|
+
'format': format_id,
|
|
949
|
+
'outtmpl': os.path.join(path, '%(playlist_title)s/%(title)s.%(ext)s' if is_playlist else '%(title)s.%(ext)s'),
|
|
950
|
+
'progress_hooks': [self._progress_hook],
|
|
951
|
+
'merge_output_format': 'mp4',
|
|
952
|
+
'debug_printout': True,
|
|
953
|
+
'logger': DebugLogger(self.signals, self),
|
|
954
|
+
'signal_handler': CancelHandler(self),
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
# Add subtitle options if requested
|
|
958
|
+
if subtitle_lang:
|
|
959
|
+
lang_code = subtitle_lang.split(' - ')[0]
|
|
960
|
+
is_auto = 'Auto-generated' in subtitle_lang
|
|
961
|
+
ydl_opts.update({
|
|
962
|
+
'writesubtitles': True,
|
|
963
|
+
'subtitleslangs': [lang_code],
|
|
964
|
+
'writeautomaticsub': True,
|
|
965
|
+
'skip_manual_subs': is_auto,
|
|
966
|
+
'skip_auto_subs': not is_auto,
|
|
967
|
+
})
|
|
968
|
+
|
|
969
|
+
self.signals.update_status.emit("Preparing for download...")
|
|
970
|
+
self.signals.update_progress.emit(0)
|
|
971
|
+
|
|
972
|
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
|
973
|
+
self.current_download = ydl
|
|
974
|
+
ydl.download([url])
|
|
975
|
+
|
|
976
|
+
except Exception as e:
|
|
977
|
+
if self.download_cancelled:
|
|
978
|
+
self.signals.update_status.emit("Download cancelled")
|
|
979
|
+
else:
|
|
980
|
+
error_message = str(e)
|
|
981
|
+
self.signals.update_status.emit(f"Error: {error_message}")
|
|
982
|
+
finally:
|
|
983
|
+
self.current_download = None
|
|
984
|
+
self.download_btn.setEnabled(True)
|
|
985
|
+
self.pause_btn.setVisible(False)
|
|
986
|
+
self.cancel_btn.setVisible(False)
|
|
987
|
+
|
|
988
|
+
def _progress_hook(self, d):
|
|
989
|
+
if self.download_cancelled:
|
|
990
|
+
raise Exception("Download cancelled by user")
|
|
991
|
+
|
|
992
|
+
if d['status'] == 'downloading':
|
|
993
|
+
while self.download_paused and not self.download_cancelled:
|
|
994
|
+
time.sleep(0.1)
|
|
995
|
+
continue
|
|
996
|
+
|
|
997
|
+
try:
|
|
998
|
+
downloaded_bytes = int(d.get('downloaded_bytes', 0))
|
|
999
|
+
total_bytes = int(d.get('total_bytes', 1))
|
|
1000
|
+
progress = int((downloaded_bytes * 100) // total_bytes)
|
|
1001
|
+
progress = max(0, min(100, progress))
|
|
1002
|
+
|
|
1003
|
+
# Extract additional download information
|
|
1004
|
+
speed = d.get('speed', 0)
|
|
1005
|
+
eta = d.get('eta', 0)
|
|
1006
|
+
filename = os.path.basename(d.get('filename', ''))
|
|
1007
|
+
|
|
1008
|
+
# Format the speed dynamically
|
|
1009
|
+
if speed:
|
|
1010
|
+
if speed > 1024 * 1024: # If speed is greater than 1 MiB/s
|
|
1011
|
+
speed_str = f"{speed/(1024*1024):.1f} MiB/s"
|
|
1012
|
+
else:
|
|
1013
|
+
speed_str = f"{speed/1024:.1f} KiB/s"
|
|
1014
|
+
else:
|
|
1015
|
+
speed_str = "N/A"
|
|
1016
|
+
|
|
1017
|
+
eta_str = f"{eta//60}:{eta%60:02d}" if eta else "N/A"
|
|
1018
|
+
|
|
1019
|
+
# Update the UI
|
|
1020
|
+
details_text = f"Speed: {speed_str} | ETA: {eta_str} | File: {filename}"
|
|
1021
|
+
self.signals.update_status.emit(details_text)
|
|
1022
|
+
self.signals.update_progress.emit(progress)
|
|
1023
|
+
|
|
1024
|
+
except Exception as e:
|
|
1025
|
+
print(f"Progress calculation error: {str(e)}")
|
|
1026
|
+
self.signals.update_status.emit("Downloading...")
|
|
1027
|
+
|
|
1028
|
+
elif d['status'] == 'finished':
|
|
1029
|
+
self.signals.update_progress.emit(100)
|
|
1030
|
+
self.signals.update_status.emit("Download completed!")
|
|
1031
|
+
self.download_details_label.setText("") # Clear the details when finished
|
|
1032
|
+
|
|
1033
|
+
def update_progress_bar(self, value):
|
|
1034
|
+
try:
|
|
1035
|
+
# Ensure the value is an integer
|
|
1036
|
+
int_value = int(value)
|
|
1037
|
+
self.progress_bar.setValue(int_value)
|
|
1038
|
+
except Exception as e:
|
|
1039
|
+
print(f"Progress bar update error: {str(e)}")
|
|
1040
|
+
|
|
1041
|
+
def toggle_pause(self):
|
|
1042
|
+
if self.current_download:
|
|
1043
|
+
self.download_paused = not self.download_paused
|
|
1044
|
+
if self.download_paused:
|
|
1045
|
+
self.pause_btn.setText('Resume')
|
|
1046
|
+
self.signals.update_status.emit("Download paused")
|
|
1047
|
+
else:
|
|
1048
|
+
self.pause_btn.setText('Pause')
|
|
1049
|
+
self.signals.update_status.emit("Download resumed")
|
|
1050
|
+
|
|
1051
|
+
def toggle_log_window(self):
|
|
1052
|
+
if self.log_btn.isChecked():
|
|
1053
|
+
if not self.log_window:
|
|
1054
|
+
self.log_window = LogWindow(self)
|
|
1055
|
+
self.log_window.show()
|
|
1056
|
+
self.show_log = True
|
|
1057
|
+
else:
|
|
1058
|
+
if self.log_window:
|
|
1059
|
+
self.log_window.hide()
|
|
1060
|
+
self.show_log = False
|
|
1061
|
+
|
|
1062
|
+
def check_for_updates(self):
|
|
1063
|
+
try:
|
|
1064
|
+
# Get the latest release info from GitHub
|
|
1065
|
+
response = requests.get(
|
|
1066
|
+
"https://api.github.com/repos/oop7/YTSage/releases/latest",
|
|
1067
|
+
headers={"Accept": "application/vnd.github.v3+json"}
|
|
1068
|
+
)
|
|
1069
|
+
response.raise_for_status()
|
|
1070
|
+
|
|
1071
|
+
latest_release = response.json()
|
|
1072
|
+
latest_version = latest_release["tag_name"].lstrip('v')
|
|
1073
|
+
|
|
1074
|
+
# Compare versions
|
|
1075
|
+
if version.parse(latest_version) > version.parse(self.version):
|
|
1076
|
+
self.show_update_dialog(latest_version, latest_release["html_url"])
|
|
1077
|
+
except Exception as e:
|
|
1078
|
+
print(f"Failed to check for updates: {str(e)}")
|
|
1079
|
+
|
|
1080
|
+
def show_update_dialog(self, latest_version, release_url):
|
|
1081
|
+
msg = QDialog(self)
|
|
1082
|
+
msg.setWindowTitle("Update Available")
|
|
1083
|
+
msg.setMinimumWidth(400)
|
|
1084
|
+
|
|
1085
|
+
layout = QVBoxLayout(msg)
|
|
1086
|
+
|
|
1087
|
+
# Update message
|
|
1088
|
+
message_label = QLabel(
|
|
1089
|
+
f"A new version of YTSage is available!\n\n"
|
|
1090
|
+
f"Current version: {self.version}\n"
|
|
1091
|
+
f"Latest version: {latest_version}"
|
|
1092
|
+
)
|
|
1093
|
+
message_label.setWordWrap(True)
|
|
1094
|
+
layout.addWidget(message_label)
|
|
1095
|
+
|
|
1096
|
+
# Buttons
|
|
1097
|
+
button_layout = QHBoxLayout()
|
|
1098
|
+
|
|
1099
|
+
download_btn = QPushButton("Download Update")
|
|
1100
|
+
download_btn.clicked.connect(lambda: self.open_release_page(release_url))
|
|
1101
|
+
|
|
1102
|
+
remind_btn = QPushButton("Remind Me Later")
|
|
1103
|
+
remind_btn.clicked.connect(msg.close)
|
|
1104
|
+
|
|
1105
|
+
button_layout.addWidget(download_btn)
|
|
1106
|
+
button_layout.addWidget(remind_btn)
|
|
1107
|
+
layout.addLayout(button_layout)
|
|
1108
|
+
|
|
1109
|
+
# Style the dialog
|
|
1110
|
+
msg.setStyleSheet("""
|
|
1111
|
+
QDialog {
|
|
1112
|
+
background-color: #2b2b2b;
|
|
1113
|
+
}
|
|
1114
|
+
QLabel {
|
|
1115
|
+
color: #ffffff;
|
|
1116
|
+
font-size: 12px;
|
|
1117
|
+
padding: 10px;
|
|
1118
|
+
}
|
|
1119
|
+
QPushButton {
|
|
1120
|
+
padding: 8px 15px;
|
|
1121
|
+
background-color: #ff0000;
|
|
1122
|
+
border: none;
|
|
1123
|
+
border-radius: 4px;
|
|
1124
|
+
color: white;
|
|
1125
|
+
font-weight: bold;
|
|
1126
|
+
}
|
|
1127
|
+
QPushButton:hover {
|
|
1128
|
+
background-color: #cc0000;
|
|
1129
|
+
}
|
|
1130
|
+
""")
|
|
1131
|
+
|
|
1132
|
+
msg.show()
|
|
1133
|
+
|
|
1134
|
+
def open_release_page(self, url):
|
|
1135
|
+
import webbrowser
|
|
1136
|
+
webbrowser.open(url)
|
|
1137
|
+
|
|
1138
|
+
def show_custom_command(self):
|
|
1139
|
+
dialog = CustomCommandDialog(self)
|
|
1140
|
+
dialog.exec()
|
|
1141
|
+
|
|
1142
|
+
def cancel_download(self):
|
|
1143
|
+
self.download_cancelled = True
|
|
1144
|
+
if self.current_download:
|
|
1145
|
+
self.signals.update_status.emit("Cancelling download...")
|
|
1146
|
+
|
|
1147
|
+
def check_ffmpeg(self):
|
|
1148
|
+
try:
|
|
1149
|
+
subprocess.run(['ffmpeg', '-version'],
|
|
1150
|
+
stdout=subprocess.PIPE,
|
|
1151
|
+
stderr=subprocess.PIPE,
|
|
1152
|
+
check=True)
|
|
1153
|
+
return True
|
|
1154
|
+
except (subprocess.SubprocessError, FileNotFoundError):
|
|
1155
|
+
return False
|
|
1156
|
+
|
|
1157
|
+
def show_ffmpeg_dialog(self):
|
|
1158
|
+
dialog = FFmpegCheckDialog(self)
|
|
1159
|
+
dialog.exec()
|
|
1160
|
+
|
|
1161
|
+
def main():
|
|
1162
|
+
app = QApplication(sys.argv)
|
|
1163
|
+
app.setStyle(QStyleFactory.create('Fusion'))
|
|
1164
|
+
window = YTSage()
|
|
1165
|
+
window.show()
|
|
1166
|
+
sys.exit(app.exec())
|
|
1167
|
+
|
|
1168
|
+
if __name__ == '__main__':
|
|
1169
|
+
main()
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 oop7
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: YTSage
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: A simple GUI for yt-dlp
|
|
5
|
+
Home-page: https://github.com/oop7/YTSage
|
|
6
|
+
Author: oop7
|
|
7
|
+
Author-email: oop7 <oop7_support@proton.me>
|
|
8
|
+
License: MIT License
|
|
9
|
+
Project-URL: Homepage, https://github.com/oop7/YTSage
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Requires-Python: >=3.7
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: yt-dlp
|
|
17
|
+
Requires-Dist: PyQt6
|
|
18
|
+
Requires-Dist: requests
|
|
19
|
+
Requires-Dist: Pillow
|
|
20
|
+
Requires-Dist: packaging
|
|
21
|
+
|
|
22
|
+
# YTSage
|
|
23
|
+
|
|
24
|
+
YTSage is a graphical user interface (GUI) for the popular command-line tool `yt-dlp`, which is used for downloading videos from YouTube and other video platforms. YTSage provides an easy-to-use interface for downloading videos, selecting formats, and managing downloads.
|
|
25
|
+
|
|
26
|
+
## Features
|
|
27
|
+
|
|
28
|
+
* **Analyze URLs:** Quickly analyze YouTube URLs (both videos and playlists).
|
|
29
|
+
* **Format Selection:** Choose from available video and audio formats.
|
|
30
|
+
* **Subtitle Support:** Download subtitles in various languages (if available).
|
|
31
|
+
* **Download Management:** Pause, resume, and cancel downloads.
|
|
32
|
+
* **Custom Commands:** Run custom `yt-dlp` commands.
|
|
33
|
+
* **Progress Tracking:** Monitor download progress with a progress bar and status updates.
|
|
34
|
+
* **FFmpeg Integration:** Automatically merges audio and video if needed (requires FFmpeg to be installed).
|
|
35
|
+
* **Dark Mode Theme:** A modern, dark-themed interface.
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
### Prerequisites
|
|
40
|
+
* FFmpeg is required to be installed separately. You can find instructions on how to install FFmpeg [here](https://github.com/oop7/ffmpeg-install-guide).
|
|
41
|
+
|
|
42
|
+
### From PyPI
|
|
43
|
+
YTSage can be installed via pip:
|
|
44
|
+
```bash
|
|
45
|
+
pip install YTSage
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
- This will also install the required dependencies (yt-dlp, PyQt6, requests, Pillow, packaging)
|
|
49
|
+
|
|
50
|
+
## Usage
|
|
51
|
+
|
|
52
|
+
After installation, you can run YTSage from your terminal:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
YTSage
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
1. Paste a YouTube URL into the URL input field.
|
|
59
|
+
2. Click **Analyze** to analyze the URL.
|
|
60
|
+
3. Select the desired video/audio format from the table.
|
|
61
|
+
4. Choose a download location (optional).
|
|
62
|
+
5. Click **Download** to start the download.
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
## Contributing
|
|
66
|
+
|
|
67
|
+
Contributions are welcome! If you find a bug or want to suggest a new feature, please open an issue or submit a pull request on the [GitHub repository](https://github.com/oop7/YTSage).
|
|
68
|
+
|
|
69
|
+
## License
|
|
70
|
+
|
|
71
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
YTSage/YTSage.py,sha256=Ix0Bv0kDhJ70uDbCdTkky5RgpCXyTk5fjdM1g0zBT2k,46004
|
|
2
|
+
YTSage-2.0.0.dist-info/LICENSE,sha256=I0b2gvqQlZaYyvQtO-lF3iAXDBviQBYEyvrClENF81Y,1061
|
|
3
|
+
YTSage-2.0.0.dist-info/METADATA,sha256=rb3t4_b4JKBsJfO-FcY5dCTdF73AIjGkbIohRxR1__o,2589
|
|
4
|
+
YTSage-2.0.0.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
|
5
|
+
YTSage-2.0.0.dist-info/entry_points.txt,sha256=MsNQH1wf6FArndtuSUxqzvIo05okb54VHrRAJ980ZjA,46
|
|
6
|
+
YTSage-2.0.0.dist-info/top_level.txt,sha256=OmRxMfDzqrNxEkDPsPUyLb56394qeUzqRvgD9NrtIJc,7
|
|
7
|
+
YTSage-2.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
YTSage
|