-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
74 lines (56 loc) · 2.35 KB
/
main.py
File metadata and controls
74 lines (56 loc) · 2.35 KB
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
import sys
import os
from PyQt6.QtWidgets import (QApplication, QWidget, QVBoxLayout, QPushButton,
QLineEdit, QLabel, QFileDialog, QMessageBox)
from yt_dlp import YoutubeDL
class YoutubeDownloader(QWidget):
def __init__(self):
super().__init__()
self.init_ui()
def init_ui(self):
self.setWindowTitle('YouTube Downloader (PyQt6)')
self.setGeometry(300, 300, 400, 200)
layout = QVBoxLayout()
self.label = QLabel('Paste video link here:')
self.url_input = QLineEdit()
self.path_label = QLabel('Save to folder:')
self.path_display = QLineEdit()
self.path_display.setPlaceholderText("Select folder...")
self.path_display.setReadOnly(True)
self.btn_browse = QPushButton('Browse Folder')
self.btn_browse.clicked.connect(self.browse_folder)
self.btn_download = QPushButton('Download Video')
self.btn_download.clicked.connect(self.download_video)
self.btn_download.setStyleSheet("background-color: #ff0000; color: white; font-weight: bold;")
layout.addWidget(self.label)
layout.addWidget(self.url_input)
layout.addWidget(self.path_label)
layout.addWidget(self.path_display)
layout.addWidget(self.btn_browse)
layout.addWidget(self.btn_download)
self.setLayout(layout)
def browse_folder(self):
directory = QFileDialog.getExistingDirectory(self, "Select Download Folder")
if directory:
self.path_display.setText(directory)
def download_video(self):
url = self.url_input.text()
save_path = self.path_display.text()
if not url or not save_path:
QMessageBox.warning(self, "Error", "Please enter a URL and select a folder!")
return
try:
ydl_opts = {
'format': 'best',
'outtmpl': os.path.join(save_path, '%(title)s.%(ext)s'),
}
with YoutubeDL(ydl_opts) as ydl:
ydl.download([url])
QMessageBox.information(self, "Success", "Video downloaded successfully!")
except Exception as e:
QMessageBox.critical(self, "Error", f"An error occurred: {str(e)}")
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = YoutubeDownloader()
ex.show()
sys.exit(app.exec())