summaryrefslogtreecommitdiff
path: root/yt_dlp_qt6
diff options
context:
space:
mode:
authoraqua <aqua@iserlohn-fortress.net>2023-10-22 15:21:09 +0300
committeraqua <aqua@iserlohn-fortress.net>2023-10-22 15:21:09 +0300
commit320f1ddbd605dc89cc20bc536f8cb76c68e97ae8 (patch)
tree41975563a7efd57a21370a61e339052a0ff198e0 /yt_dlp_qt6
downloadyt-dlp-qt6-320f1ddbd605dc89cc20bc536f8cb76c68e97ae8.tar.xz
Initial commitHEADmaster
Diffstat (limited to 'yt_dlp_qt6')
-rw-r--r--yt_dlp_qt6/__init__.py3
-rw-r--r--yt_dlp_qt6/__main__.py11
-rw-r--r--yt_dlp_qt6/main_window.py70
3 files changed, 84 insertions, 0 deletions
diff --git a/yt_dlp_qt6/__init__.py b/yt_dlp_qt6/__init__.py
new file mode 100644
index 0000000..7535e8f
--- /dev/null
+++ b/yt_dlp_qt6/__init__.py
@@ -0,0 +1,3 @@
+__license__ = 'GPL-3.0-only'
+
+from .main_window import MainWindow
diff --git a/yt_dlp_qt6/__main__.py b/yt_dlp_qt6/__main__.py
new file mode 100644
index 0000000..46a19b0
--- /dev/null
+++ b/yt_dlp_qt6/__main__.py
@@ -0,0 +1,11 @@
+__license__ = 'GPL-3.0-only'
+
+import sys
+from PyQt6.QtWidgets import QApplication
+from . import MainWindow
+
+app = QApplication(sys.argv)
+window = MainWindow()
+window.show()
+
+app.exec()
diff --git a/yt_dlp_qt6/main_window.py b/yt_dlp_qt6/main_window.py
new file mode 100644
index 0000000..dd95664
--- /dev/null
+++ b/yt_dlp_qt6/main_window.py
@@ -0,0 +1,70 @@
+__license__ = 'GPL-3.0-only'
+
+from pathlib import Path
+from PyQt6.QtWidgets import (QMainWindow, QMessageBox, QFileDialog,
+ QGridLayout, QSpacerItem, QSizePolicy,
+ QWidget, QLabel, QLineEdit, QPushButton)
+import yt_dlp
+from yt_dlp import YoutubeDL
+
+class MainWindow(QMainWindow):
+ def __init__(self):
+ super().__init__()
+ self.setWindowTitle("yt-dlp")
+ self.resize(600, 160)
+
+ layout = QGridLayout()
+
+ self.url = QLineEdit()
+ self.download_path = QLineEdit()
+ self.download_path.setText(str(Path.home()/'Downloads'))
+ browse_btn = QPushButton("...")
+ browse_btn.clicked.connect(self.browse)
+ download_btn = QPushButton("Download")
+
+ layout.addWidget(QLabel("URL:"), 0, 0)
+ layout.addWidget(self.url, 0, 1, 1, 2)
+
+ layout.addWidget(QLabel("Download:"), 1, 0)
+ layout.addWidget(self.download_path, 1, 1)
+ layout.addWidget(browse_btn, 1, 2)
+
+ layout.addItem(QSpacerItem(0, 0,
+ QSizePolicy.Policy.Minimum,
+ QSizePolicy.Policy.Expanding),
+ 2, 1)
+
+ layout.addWidget(download_btn, 3, 1)
+ download_btn.clicked.connect(self.download)
+
+ widget = QWidget()
+ widget.setLayout(layout)
+ self.setCentralWidget(widget)
+
+ def on_finish_hook(self, data):
+ if data['status'] == 'finished':
+ print(f"\n\nfinished: {data['filename']}\n")
+
+ def browse(self):
+ dirpath = QFileDialog.getExistingDirectory(self)
+ if len(dirpath) > 0:
+ self.download_path.setText(dirpath)
+
+ def download(self):
+ ydl_opts = {
+ 'paths': {'home': self.download_path.text()},
+ 'progress_hooks': [self.on_finish_hook],
+ }
+
+ with YoutubeDL(ydl_opts) as ydl:
+ try:
+ ydl.download([self.url.text()])
+ except yt_dlp.utils.DownloadError as ex:
+ box = QMessageBox(self)
+ box.setWindowTitle(self.windowTitle())
+ box.setText('Error downloading using yt-dlp')
+ box.setDetailedText(f'{ex}')
+ box.exec()
+ finally:
+ QMessageBox.information(self, self.windowTitle(), 'Finished')
+ self.url.clear()