298 lines
16 KiB
Python
Executable File
298 lines
16 KiB
Python
Executable File
#!/usr/bin/python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Form implementation generated from reading ui file 'continuity.ui'
|
|
#
|
|
# Created by: PyQt5 UI code generator 5.12.2
|
|
#
|
|
# WARNING! All changes made in this file will be lost!
|
|
|
|
import sys, os, subprocess, time, psutil
|
|
from PyQt5.QtWidgets import QApplication, QPushButton
|
|
from PyQt5 import QtCore, QtGui, QtWidgets
|
|
|
|
|
|
class Ui_MainWindow(object):
|
|
def setupUi(self, MainWindow):
|
|
MainWindow.setObjectName("MainWindow")
|
|
MainWindow.resize(377, 522)
|
|
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
|
|
sizePolicy.setHorizontalStretch(0)
|
|
sizePolicy.setVerticalStretch(0)
|
|
sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
|
|
MainWindow.setSizePolicy(sizePolicy)
|
|
MainWindow.setMinimumSize(QtCore.QSize(377, 522))
|
|
MainWindow.setMaximumSize(QtCore.QSize(377, 522))
|
|
self.centralwidget = QtWidgets.QWidget(MainWindow)
|
|
self.centralwidget.setObjectName("centralwidget")
|
|
self.tabs = QtWidgets.QTabWidget(self.centralwidget)
|
|
self.tabs.setGeometry(QtCore.QRect(10, 10, 361, 251))
|
|
self.tabs.setObjectName("tabs")
|
|
self.audioTab = QtWidgets.QWidget()
|
|
self.audioTab.setObjectName("audioTab")
|
|
self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.audioTab)
|
|
self.verticalLayout_2.setObjectName("verticalLayout_2")
|
|
self.audio_url_label = QtWidgets.QLabel(self.audioTab)
|
|
self.audio_url_label.setObjectName("audio_url_label")
|
|
self.verticalLayout_2.addWidget(self.audio_url_label)
|
|
self.audio_tab_playlist = QtWidgets.QCheckBox(self.audioTab)
|
|
self.audio_tab_playlist.setObjectName("audio_tab_playlist")
|
|
self.verticalLayout_2.addWidget(self.audio_tab_playlist)
|
|
self.audio_url_entry = QtWidgets.QLineEdit(self.audioTab)
|
|
self.audio_url_entry.setObjectName("audio_url_entry")
|
|
self.verticalLayout_2.addWidget(self.audio_url_entry)
|
|
self.audio_format_label = QtWidgets.QLabel(self.audioTab)
|
|
self.audio_format_label.setObjectName("audio_format_label")
|
|
self.verticalLayout_2.addWidget(self.audio_format_label)
|
|
self.audio_format_select = QtWidgets.QComboBox(self.audioTab)
|
|
self.audio_format_select.setObjectName("audio_format_select")
|
|
self.audio_format_select.addItem("mp3")
|
|
self.audio_format_select.addItem("ogg")
|
|
self.audio_format_select.addItem("flac")
|
|
self.verticalLayout_2.addWidget(self.audio_format_select)
|
|
self.bitrate_select_label = QtWidgets.QLabel(self.audioTab)
|
|
self.bitrate_select_label.setObjectName("bitrate_select_label")
|
|
self.verticalLayout_2.addWidget(self.bitrate_select_label)
|
|
self.bitrate_select = QtWidgets.QComboBox(self.audioTab)
|
|
self.bitrate_select.setObjectName("bitrate_select")
|
|
self.bitrate_select.addItem("Best")
|
|
#self.bitrate_select.addItem("128K")
|
|
#self.bitrate_select.addItem("256K")
|
|
#self.bitrate_select.addItem("320K")
|
|
self.verticalLayout_2.addWidget(self.bitrate_select)
|
|
self.tabs.addTab(self.audioTab, "")
|
|
self.videoTab = QtWidgets.QWidget()
|
|
self.videoTab.setObjectName("videoTab")
|
|
self.verticalLayout_4 = QtWidgets.QVBoxLayout(self.videoTab)
|
|
self.verticalLayout_4.setObjectName("verticalLayout_4")
|
|
self.video_url_label = QtWidgets.QLabel(self.videoTab)
|
|
self.video_url_label.setObjectName("video_url_label")
|
|
self.verticalLayout_4.addWidget(self.video_url_label)
|
|
self.video_tab_playlist = QtWidgets.QCheckBox(self.videoTab)
|
|
self.video_tab_playlist.setObjectName("video_tab_playlist")
|
|
self.verticalLayout_4.addWidget(self.video_tab_playlist)
|
|
self.video_url_entry = QtWidgets.QLineEdit(self.videoTab)
|
|
self.video_url_entry.setObjectName("video_url_entry")
|
|
self.verticalLayout_4.addWidget(self.video_url_entry)
|
|
self.video_format_label = QtWidgets.QLabel(self.videoTab)
|
|
self.video_format_label.setObjectName("video_format_label")
|
|
self.verticalLayout_4.addWidget(self.video_format_label)
|
|
self.video_format_select = QtWidgets.QComboBox(self.videoTab)
|
|
self.video_format_select.setObjectName("video_format_select")
|
|
self.video_format_select.addItem("mp4")
|
|
self.video_format_select.addItem("mkv")
|
|
self.video_format_select.addItem("webm")
|
|
self.video_format_select.addItem("flv")
|
|
self.verticalLayout_4.addWidget(self.video_format_select)
|
|
self.resolution_select_label = QtWidgets.QLabel(self.videoTab)
|
|
self.resolution_select_label.setObjectName("resolution_select_label")
|
|
self.verticalLayout_4.addWidget(self.resolution_select_label)
|
|
self.resolution_select = QtWidgets.QComboBox(self.videoTab)
|
|
self.resolution_select.setObjectName("resolution_select")
|
|
self.resolution_select.addItem("480")
|
|
self.resolution_select.addItem("720")
|
|
self.resolution_select.addItem("1080")
|
|
self.verticalLayout_4.addWidget(self.resolution_select)
|
|
self.tabs.addTab(self.videoTab, "")
|
|
self.download_button = QPushButton(self.centralwidget)
|
|
self.download_button.setGeometry(QtCore.QRect(120, 430, 141, 34))
|
|
self.download_button.setObjectName("download_button")
|
|
self.output_window = QtWidgets.QTextBrowser(self.centralwidget)
|
|
self.output_window.setGeometry(QtCore.QRect(10, 270, 361, 141))
|
|
self.output_window.setObjectName("output_window")
|
|
self.progressBar = QtWidgets.QProgressBar(self.centralwidget)
|
|
self.progressBar.setGeometry(QtCore.QRect(10, 410, 361, 23))
|
|
self.progressBar.setProperty("value", 0)
|
|
self.progressBar.setObjectName("progressBar")
|
|
MainWindow.setCentralWidget(self.centralwidget)
|
|
self.menubar = QtWidgets.QMenuBar(MainWindow)
|
|
self.menubar.setGeometry(QtCore.QRect(0, 0, 377, 30))
|
|
self.menubar.setObjectName("menubar")
|
|
self.menuMandy = QtWidgets.QMenu(self.menubar)
|
|
self.menuMandy.setObjectName("menuMandy")
|
|
self.menuEdit = QtWidgets.QMenu(self.menubar)
|
|
self.menuEdit.setObjectName("menuEdit")
|
|
self.menuAbout = QtWidgets.QMenu(self.menubar)
|
|
self.menuAbout.setObjectName("menuAbout")
|
|
MainWindow.setMenuBar(self.menubar)
|
|
self.statusbar = QtWidgets.QStatusBar(MainWindow)
|
|
self.statusbar.setObjectName("statusbar")
|
|
MainWindow.setStatusBar(self.statusbar)
|
|
self.actionSettings = QtWidgets.QAction(MainWindow)
|
|
self.actionSettings.setObjectName("actionSettings")
|
|
self.actionQuit_Ctrl_q = QtWidgets.QAction(MainWindow)
|
|
self.actionQuit_Ctrl_q.setObjectName("actionQuit_Ctrl_q")
|
|
self.actionSettings_2 = QtWidgets.QAction(MainWindow)
|
|
self.actionSettings_2.setObjectName("actionSettings_2")
|
|
self.menuMandy.addSeparator()
|
|
self.menuMandy.addAction(self.actionQuit_Ctrl_q)
|
|
self.menuEdit.addAction(self.actionSettings_2)
|
|
self.menubar.addAction(self.menuMandy.menuAction())
|
|
self.menubar.addAction(self.menuEdit.menuAction())
|
|
self.menubar.addAction(self.menuAbout.menuAction())
|
|
|
|
self.retranslateUi(MainWindow)
|
|
self.tabs.setCurrentIndex(0)
|
|
QtCore.QMetaObject.connectSlotsByName(MainWindow)
|
|
|
|
def dl_content(self):
|
|
index = self.tabs.currentIndex()
|
|
if index == 0:
|
|
url = self.audio_url_entry.text()
|
|
if "https://" not in url[:8]:
|
|
if "http://" not in url[:7]:
|
|
self.output_window.append("That is not a valid url.")
|
|
return
|
|
self.output_window.append("Downloading " + url + "...")
|
|
self.output_window.repaint()
|
|
playlist = self.audio_tab_playlist.isChecked()
|
|
audio_format = self.audio_format_select.currentText()
|
|
|
|
#command = "youtube-dl "
|
|
#if playlist == 1:
|
|
# command = command + "--yes-playlist "
|
|
#command = command + "--extract-audio "
|
|
#command = command + "--audio-format "
|
|
#command = command + audio_format
|
|
#command = command + " -o '%(title)s.%(ext)s' "
|
|
#command = command + url
|
|
|
|
if playlist == 0:
|
|
subprocess.Popen(["youtube-dl", "--extract-audio", "--audio-format", audio_format, "-o '%(title)s.%(ext)s'", url], stdout=open('status.txt', 'w'), encoding='utf-8')
|
|
timeout = 0
|
|
for p in psutil.process_iter(attrs=['name']):
|
|
while p.info['name'] == "youtube-dl":
|
|
b = open('status.txt', 'r', encoding='utf-8')
|
|
self.output_window.clear()
|
|
self.output_window.append(b.read())
|
|
self.output_window.repaint()
|
|
time.sleep(2)
|
|
if p.info['name'] == "youtube-dl":
|
|
size = os.path.getsize("status.txt")
|
|
if size == os.path.getsize("status.txt"):
|
|
timeout = timeout + 1
|
|
if timeout == 30:
|
|
break
|
|
#b.close()
|
|
if playlist == 1:
|
|
subprocess.run(["youtube-dl", "--yes-playlist", "--extract-audio", "--audio-format", audio_format, "-o '%(title)s.%(ext)s'", url], stdout=open('status.txt', 'w'), encoding='utf-8')
|
|
timeout = 0
|
|
for p in psutil.process_iter(attrs=['name']):
|
|
while p.info['name'] == "youtube-dl":
|
|
b = open('status.txt', 'r', encoding='utf-8')
|
|
self.output_window.clear()
|
|
self.output_window.append(b.read())
|
|
self.output_window.repaint()
|
|
time.sleep(2)
|
|
if p.info['name'] == "youtube-dl":
|
|
size = os.path.getsize("status.txt")
|
|
if size == os.path.getsize("status.txt"):
|
|
timeout = timeout + 1
|
|
if timeout == 30:
|
|
break
|
|
if index == 1:
|
|
url = self.video_url_entry.text()
|
|
if "https://" not in url[:8]:
|
|
if "http://" not in url[:7]:
|
|
self.output_window.append("That is not a valid url.")
|
|
return
|
|
self.output_window.append("Downloading " + url + "...")
|
|
self.output_window.repaint()
|
|
playlist = self.video_tab_playlist.isChecked()
|
|
video_format = self.video_format_select.currentText()
|
|
resolution = self.resolution_select.currentText()
|
|
command = "(" + video_format + ")[height<=" + resolution + "]'"
|
|
if playlist == 0:
|
|
print("video playlist 0")
|
|
subprocess.Popen(["youtube-dl", "-f", command, "-o '%(title)s.%(ext)s'", url], stdout=open('status.txt', 'w'), encoding='utf-8')
|
|
timeout = 0
|
|
for p in psutil.process_iter(attrs=['name']):
|
|
print("process for")
|
|
while p.info['name'] == "youtube-dl":
|
|
print("file open")
|
|
b = open('status.txt', 'r', encoding='utf-8')
|
|
self.output_window.clear()
|
|
self.output_window.append(b.read())
|
|
self.output_window.repaint()
|
|
time.sleep(2)
|
|
if p.info['name'] == "youtube-dl":
|
|
print("size check")
|
|
size = os.path.getsize("status.txt")
|
|
if size == os.path.getsize("status.txt"):
|
|
timeout = timeout + 1
|
|
if timeout == 30:
|
|
break
|
|
if playlist == 1:
|
|
subprocess.Popen(["youtube-dl", "--yes-playlist", "-f", command, "-o '%(title)s.%(ext)s'", url], stdout=open('status.txt', 'w'), encoding='utf-8')
|
|
timeout = 0
|
|
for p in psutil.process_iter(attrs=['name']):
|
|
while p.info['name'] == "youtube-dl":
|
|
b = open('status.txt', 'r', encoding='utf-8')
|
|
self.output_window.clear()
|
|
self.output_window.append(b.read())
|
|
self.output_window.repaint()
|
|
time.sleep(2)
|
|
if p.info['name'] == "youtube-dl":
|
|
size = os.path.getsize("status.txt")
|
|
if size == os.path.getsize("status.txt"):
|
|
timeout = timeout + 1
|
|
if timeout == 30:
|
|
break
|
|
self.output_window.append("File Download Complete!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def retranslateUi(self, MainWindow):
|
|
_translate = QtCore.QCoreApplication.translate
|
|
MainWindow.setWindowTitle(_translate("MainWindow", "Continuity 0.0.1"))
|
|
self.audio_url_label.setText(_translate("MainWindow", "URL:"))
|
|
self.audio_tab_playlist.setText(_translate("MainWindow", "Playlist"))
|
|
self.audio_url_entry.setText(_translate("MainWindow", "Paste URL here"))
|
|
self.audio_format_label.setText(_translate("MainWindow", "Audio Format:"))
|
|
#self.audio_format_select.setItemText(0, _translate("MainWindow", "Ogg"))
|
|
#self.audio_format_select.setItemText(1, _translate("MainWindow", "MP3"))
|
|
#self.audio_format_select.setItemText(2, _translate("MainWindow", "FLAC"))
|
|
self.bitrate_select_label.setText(_translate("MainWindow", "Bitrate:"))
|
|
#self.bitrate_select.setItemText(0, _translate("MainWindow", "128 kb/s"))
|
|
#self.bitrate_select.setItemText(1, _translate("MainWindow", "192 kb/s"))
|
|
#self.bitrate_select.setItemText(2, _translate("MainWindow", "320 kb/s"))
|
|
#self.bitrate_select.setItemText(3, _translate("MainWindow", "Best"))
|
|
self.tabs.setTabText(self.tabs.indexOf(self.audioTab), _translate("MainWindow", "Audio"))
|
|
self.video_url_label.setText(_translate("MainWindow", "URL:"))
|
|
self.video_tab_playlist.setText(_translate("MainWindow", "Playlist"))
|
|
self.video_url_entry.setText(_translate("MainWindow", "Paste URL here"))
|
|
self.video_format_label.setText(_translate("MainWindow", "Video Format:"))
|
|
#self.video_format_select.setItemText(0, _translate("MainWindow", "MP4"))
|
|
#self.video_format_select.setItemText(1, _translate("MainWindow", "AVI"))
|
|
#self.video_format_select.setItemText(2, _translate("MainWindow", "WEBM"))
|
|
self.resolution_select_label.setText(_translate("MainWindow", "Resolution:"))
|
|
#self.resolution_select.setItemText(0, _translate("MainWindow", "Best"))
|
|
self.tabs.setTabText(self.tabs.indexOf(self.videoTab), _translate("MainWindow", "Video"))
|
|
self.download_button.setText(_translate("MainWindow", "Download"))
|
|
#self.download_button.clicked.connect(dl_file())
|
|
self.menuMandy.setTitle(_translate("MainWindow", "File"))
|
|
self.menuEdit.setTitle(_translate("MainWindow", "Edit"))
|
|
self.menuAbout.setTitle(_translate("MainWindow", "About"))
|
|
self.actionSettings.setText(_translate("MainWindow", "Settings"))
|
|
self.actionQuit_Ctrl_q.setText(_translate("MainWindow", "Quit (Ctrl + q)"))
|
|
self.actionSettings_2.setText(_translate("MainWindow", "Settings"))
|
|
self.download_button.clicked.connect(self.dl_content)
|
|
|
|
|
|
|
|
#from KPushButton import KPushButton
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import sys, os , subprocess
|
|
app = QtWidgets.QApplication(sys.argv)
|
|
MainWindow = QtWidgets.QMainWindow()
|
|
ui = Ui_MainWindow()
|
|
ui.setupUi(MainWindow)
|
|
MainWindow.show()
|
|
sys.exit(app.exec_())
|