From bac0e94d0d1745ab791bda8354d32d3499f8511f Mon Sep 17 00:00:00 2001 From: sentenzo Date: Fri, 26 Aug 2022 18:51:25 +0300 Subject: [PATCH] =?UTF-8?q?MVP=20(hooray=20=F0=9F=98=84=F0=9F=8E=89)=20(ye?= =?UTF-8?q?t=20more=20is=20to=20be=20done)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 20 ++++++++++++++++---- src/app.py | 18 ++---------------- src/app_gui.py | 24 +++++++++++++++++++----- src/qt/py_ui/main_window.py | 11 ++++++++--- src/qt/ui/main_window.ui | 10 +++++++++- src/ytdpl_wrapper.py | 9 +++++++++ 6 files changed, 63 insertions(+), 29 deletions(-) create mode 100644 src/ytdpl_wrapper.py diff --git a/Makefile b/Makefile index cea7594..b8ae40a 100644 --- a/Makefile +++ b/Makefile @@ -13,16 +13,28 @@ else endif endif -ENTRY_POINT = ./src/app.py +# APP_FILE = app +APP_FILE = app_gui + +APP_NAME = yt-dpl-qt6 + +ENTRY_POINT = ./src/$(APP_FILE).py + +all: pyui: - pyuic6 -o ./src/qt/py_ui/main_window.py -x ./src/qt/ui/main_window.ui + pyuic6 -o ./src/qt/py_ui/main_window.py \ + -x ./src/qt/ui/main_window.ui build: - pyinstaller --workpath ./.pyinstaller/build --distpath ./bin --specpath ./.pyinstaller --onefile $(ENTRY_POINT) + pyinstaller --workpath ./.pyinstaller/build \ + --distpath ./bin --specpath ./.pyinstaller \ + --noconsole --onefile \ + --name $(APP_NAME) \ + $(ENTRY_POINT) run: - ./bin/app + ./bin/$(APP_NAME) runpy: $(PYTHON) $(ENTRY_POINT) diff --git a/src/app.py b/src/app.py index 8038c15..f39b18c 100644 --- a/src/app.py +++ b/src/app.py @@ -1,20 +1,6 @@ import sys -from yt_dlp import YoutubeDL - - -def download_videos(urls): - # if not urls or not isinstance(urls, list): - # # Rick Astley - Never Gonna Give You Up (Official Music Video) - urls = ["https://www.youtube.com/watch?v=dQw4w9WgXcQ"] - with YoutubeDL() as ydl: - ydl.download(urls) - - -def main(): - if len(sys.argv) > 1: - download_videos(sys.argv[1:]) - print(sys.argv) +from ytdpl_wrapper import download_videos if __name__ == "__main__": - main() + download_videos(sys.argv[1:]) diff --git a/src/app_gui.py b/src/app_gui.py index d9ed210..71d4a30 100644 --- a/src/app_gui.py +++ b/src/app_gui.py @@ -1,12 +1,26 @@ import sys -from PyQt6.QtWidgets import QApplication, QWidget, QMainWindow +import PyQt6.QtWidgets as qtw + +# from PyQt6.QtWidgets import QApplication, QWidget, QMainWindow, QPushButton, QTextEdit from qt.py_ui.main_window import Ui_MainWindow +from ytdpl_wrapper import download_videos + +app = qtw.QApplication(sys.argv) +window = qtw.QMainWindow() +ui = Ui_MainWindow() +ui.setupUi(window) + + +def do__download_all(): + te_youtube_links = window.findChild(qtw.QTextEdit, "te_youtube_links") + youtube_links = te_youtube_links.toPlainText().split() + download_videos(youtube_links) + + +window.findChild(qtw.QPushButton, "pb_download_all").clicked.connect(do__download_all) if __name__ == "__main__": - app = QApplication(sys.argv) - window = QMainWindow() - ui = Ui_MainWindow() - ui.setupUi(window) + window.show() app.exec() diff --git a/src/qt/py_ui/main_window.py b/src/qt/py_ui/main_window.py index 62773cd..d1ae08a 100644 --- a/src/qt/py_ui/main_window.py +++ b/src/qt/py_ui/main_window.py @@ -20,9 +20,9 @@ def setupUi(self, MainWindow): self.verticalLayout = QtWidgets.QVBoxLayout() self.verticalLayout.setSizeConstraint(QtWidgets.QLayout.SizeConstraint.SetDefaultConstraint) self.verticalLayout.setObjectName("verticalLayout") - self.textEdit = QtWidgets.QTextEdit(self.centralwidget) - self.textEdit.setObjectName("textEdit") - self.verticalLayout.addWidget(self.textEdit) + self.te_youtube_links = QtWidgets.QTextEdit(self.centralwidget) + self.te_youtube_links.setObjectName("te_youtube_links") + self.verticalLayout.addWidget(self.te_youtube_links) self.pb_download_all = QtWidgets.QPushButton(self.centralwidget) self.pb_download_all.setObjectName("pb_download_all") self.verticalLayout.addWidget(self.pb_download_all) @@ -45,6 +45,11 @@ def setupUi(self, MainWindow): def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) + self.te_youtube_links.setHtml(_translate("MainWindow", "\n" +"\n" +"

https://www.youtube.com/watch?v=cmb6pTj67Nk

")) self.pb_download_all.setText(_translate("MainWindow", "Download All")) diff --git a/src/qt/ui/main_window.ui b/src/qt/ui/main_window.ui index 53f6ae6..65d5b01 100644 --- a/src/qt/ui/main_window.ui +++ b/src/qt/ui/main_window.ui @@ -21,7 +21,15 @@ QLayout::SetDefaultConstraint - + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">https://www.youtube.com/watch?v=cmb6pTj67Nk</p></body></html> + + diff --git a/src/ytdpl_wrapper.py b/src/ytdpl_wrapper.py new file mode 100644 index 0000000..27aa289 --- /dev/null +++ b/src/ytdpl_wrapper.py @@ -0,0 +1,9 @@ +from yt_dlp import YoutubeDL + + +def download_videos(urls=None): + if not urls or not isinstance(urls, list): + # Rick Astley - Never Gonna Give You Up (Official Music Video) + urls = ["https://www.youtube.com/watch?v=dQw4w9WgXcQ"] + with YoutubeDL() as ydl: + ydl.download(urls)