#!/usr/bin/python ''' Hypervideo GUI ''' import sys from PyQt5.QtCore import ( QFile, QPoint, QRect, QSize, QStandardPaths, Qt, QProcess, QSettings ) from PyQt5.QtGui import QIcon, QFont, QClipboard from PyQt5.QtWidgets import ( QAction, QApplication, QComboBox, QFileDialog, QHBoxLayout, QLineEdit, QLabel, QMainWindow, QMessageBox, QProgressBar, QPushButton, QToolButton, QVBoxLayout, QWidget, ) # Debuging if len(sys.argv) == 2: if sys.argv[1] == '-v': DEBUG = 0 else: DEBUG = None else: DEBUG = None __version__ = '1.0.1' __license__ = 'GPL-3' __title__ = 'Simple Hypervideo Download GUI' class MainWindow(QMainWindow): def __init__(self): ''' Initial ''' super(MainWindow, self).__init__() self.hypervideo_bin = None self.url_catch = None self.out_folder_path = '/tmp/' self.settings = QSettings('YouTubeDL', 'YTDL') self.setAttribute(Qt.WA_DeleteOnClose) self.create_status_bar() pyfile = QStandardPaths.findExecutable("hypervideo") if not pyfile == "": debugging('Found executable: %s' % pyfile) self.hypervideo_bin = pyfile else: self.msgbox("hypervideo not found\nPlease install hypervideo") self.default_formats_menu_items = ['Video/Audio - Best Quality', 'Audio Only - Best Quality'] self.list = [] self.init_ui() def init_ui(self): ''' Initial UI ''' self.setWindowTitle(__title__) btnwidth = 155 self.cmd = None self.process = QProcess(self) self.process.started.connect(lambda: self.show_message("Creating List")) self.process.started.connect(lambda: self.btn_get_formats.setEnabled(False)) self.process.finished.connect(lambda: self.show_message("Finished creating List")) self.process.finished.connect(self.process_finished) self.process.finished.connect(lambda: self.btn_get_formats.setEnabled(True)) self.process.readyRead.connect(self.process_output) self.download_process = QProcess(self) self.download_process.setProcessChannelMode(QProcess.MergedChannels) self.download_process.started.connect(lambda: self.show_message("Download started")) self.download_process.started.connect(lambda: self.download_button.setEnabled(False)) self.download_process.started.connect(lambda: self.cancel_button.setEnabled(True)) self.download_process.finished.connect(lambda: self.show_message("Download finished")) self.download_process.finished.connect(lambda: self.download_button.setEnabled(True)) self.download_process.finished.connect(lambda: self.cancel_button.setEnabled(False)) self.download_process.finished.connect(lambda: self.setWindowTitle(__title__)) self.download_process.readyRead.connect(self.dl_process_out) self.setGeometry(0, 0, 600, 250) self.setFixedSize(600, 250) self.setStyleSheet(ui_style_sheet(self)) self.setWindowIcon(QIcon.fromTheme("video-playlist")) # Menu main_menu = self.menuBar() file_menu = main_menu.addMenu('File') help_menu = main_menu.addMenu('Help') # Exit button exit_button = QAction('Exit', self) exit_button.setShortcut('Ctrl+Q') exit_button.setStatusTip('Exit application') exit_button.triggered.connect(self.close) # About button about_button = QAction('About', self) about_button.triggered.connect(self.on_button_clicked) # Adding buttons to Menu help_menu.addAction(about_button) file_menu.addAction(exit_button) # Path lbl_url = QLabel() lbl_url.setText("Insert URL/ID:") lbl_url.setAlignment(Qt.AlignRight) lbl_url.setFixedWidth(btnwidth) lbl_url.setAlignment(Qt.AlignCenter | Qt.AlignVCenter) self.lbl_url_path = QLineEdit() self.lbl_url_path.setPlaceholderText('https://invidio.us/watch?v=8SdPLG-_wtA') # Set up callback to update video formats when URL is changed self.lbl_url_path.textChanged.connect(self.reset_video_formats) hlayout = QHBoxLayout() hlayout.addWidget(lbl_url) hlayout.addWidget(self.lbl_url_path) # Output path btn_out_path = QToolButton() btn_out_path.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) btn_out_path.setText("Select Output Folder") btn_out_path.setFixedWidth(btnwidth) btn_out_path.clicked.connect(self.open_output_folder) self.lbl_out_path = QLineEdit() self.lbl_out_path.setPlaceholderText("Insert Output Folder Path") self.lbl_out_path.textChanged.connect(self.update_output_path) hlayout2 = QHBoxLayout() hlayout2.addWidget(btn_out_path) hlayout2.addWidget(self.lbl_out_path) # Hypervideo path btn_hypervideo_path = QToolButton() btn_hypervideo_path.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) btn_hypervideo_path.setText("Select hypervideo") btn_hypervideo_path.setFixedWidth(btnwidth) btn_hypervideo_path.clicked.connect(self.select_hyper_dl) self.lbl_hypervideo_path = QLineEdit(str(self.hypervideo_bin)) self.lbl_hypervideo_path.textChanged.connect(self.update_hypervideo_path) self.lbl_hypervideo_path.setPlaceholderText("Insert Path to Hypervideo") hlayout3 = QHBoxLayout() hlayout3.addWidget(btn_hypervideo_path) hlayout3.addWidget(self.lbl_hypervideo_path) self.download_button = QToolButton() self.download_button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) self.download_button.setText("Download") self.download_button.clicked.connect(self.download_selected) self.download_button.setFixedWidth(btnwidth) self.download_button.setFixedHeight(32) self.btn_get_formats = QToolButton() self.btn_get_formats.setText('Get Formats') self.btn_get_formats.setFixedWidth(btnwidth) self.btn_get_formats.setFixedHeight(32) self.btn_get_formats.clicked.connect(self.fill_combo_formats) self.cancel_button = QToolButton() self.cancel_button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) self.cancel_button.setText("Cancel") self.cancel_button.clicked.connect(self.cancel_download) self.cancel_button.setEnabled(False) self.cancel_button.setFixedWidth(btnwidth) self.cancel_button.setFixedHeight(32) self.video_format_combobox = QComboBox() self.populate_video_format_combobox(self.default_formats_menu_items) self.video_format_combobox.setFixedHeight(26) self.pbar = QProgressBar() self.pbar.setFixedHeight(16) self.pbar.setMaximum(100) self.pbar.setMinimum(0) self.pbar.setValue(0) btn_layout = QHBoxLayout() btn_layout.addWidget(self.download_button) btn_layout.addWidget(self.btn_get_formats) btn_layout.addWidget(self.cancel_button) vlayout = QVBoxLayout() vlayout.addLayout(hlayout) vlayout.addLayout(hlayout2) vlayout.addLayout(hlayout3) vlayout.addWidget(self.video_format_combobox) vlayout.addWidget(self.pbar) vlayout.addLayout(btn_layout) main_widget = QWidget() main_widget.setLayout(vlayout) self.setCentralWidget(main_widget) # Copy URL of clipboard self.clip = QApplication.clipboard() if self.clip.text().startswith("http"): self.lbl_url_path.setText(self.clip.text()) self.fill_combo_formats() self.read_settings() def on_button_clicked(self): """ Button about """ msg = QMessageBox() msg.setWindowTitle('About us') msg.setText("
Written with Python3 and PyQt5
"
"Version: %s
License: %s