continuity/main.py

298 lines
16 KiB
Python
Raw Normal View History

2019-08-22 19:00:00 -07:00
#!/usr/bin/python3
2019-08-22 18:54:55 -07:00
# -*- 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!
2019-09-16 17:16:16 -07:00
import sys, os, subprocess, time, psutil
from PyQt5.QtWidgets import QApplication, QPushButton
2019-08-22 18:54:55 -07:00
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
2019-09-16 17:16:16 -07:00
MainWindow.resize(377, 522)
2019-08-22 18:54:55 -07:00
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
MainWindow.setSizePolicy(sizePolicy)
2019-09-16 17:16:16 -07:00
MainWindow.setMinimumSize(QtCore.QSize(377, 522))
MainWindow.setMaximumSize(QtCore.QSize(377, 522))
2019-08-22 18:54:55 -07:00
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.tabs = QtWidgets.QTabWidget(self.centralwidget)
2019-09-16 17:16:16 -07:00
self.tabs.setGeometry(QtCore.QRect(10, 10, 361, 251))
2019-08-22 18:54:55 -07:00
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")
2019-09-16 17:16:16 -07:00
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)
2019-08-22 18:54:55 -07:00
self.audio_url_entry = QtWidgets.QLineEdit(self.audioTab)
self.audio_url_entry.setObjectName("audio_url_entry")
self.verticalLayout_2.addWidget(self.audio_url_entry)
2019-09-16 17:16:16 -07:00
self.audio_format_label = QtWidgets.QLabel(self.audioTab)
self.audio_format_label.setObjectName("audio_format_label")
self.verticalLayout_2.addWidget(self.audio_format_label)
2019-08-22 18:54:55 -07:00
self.audio_format_select = QtWidgets.QComboBox(self.audioTab)
self.audio_format_select.setObjectName("audio_format_select")
2019-09-16 17:16:16 -07:00
self.audio_format_select.addItem("mp3")
self.audio_format_select.addItem("ogg")
self.audio_format_select.addItem("flac")
2019-08-22 18:54:55 -07:00
self.verticalLayout_2.addWidget(self.audio_format_select)
2019-09-16 17:16:16 -07:00
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)
2019-08-22 18:54:55 -07:00
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)
2019-09-16 17:16:16 -07:00
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)
2019-08-22 18:54:55 -07:00
self.video_format_select = QtWidgets.QComboBox(self.videoTab)
self.video_format_select.setObjectName("video_format_select")
2019-09-16 17:16:16 -07:00
self.video_format_select.addItem("mp4")
self.video_format_select.addItem("mkv")
self.video_format_select.addItem("webm")
self.video_format_select.addItem("flv")
2019-08-22 18:54:55 -07:00
self.verticalLayout_4.addWidget(self.video_format_select)
2019-09-16 17:16:16 -07:00
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)
2019-08-22 18:54:55 -07:00
self.tabs.addTab(self.videoTab, "")
2019-09-16 17:16:16 -07:00
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")
2019-08-22 18:54:55 -07:00
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
2019-09-16 17:16:16 -07:00
self.menubar.setGeometry(QtCore.QRect(0, 0, 377, 30))
2019-08-22 18:54:55 -07:00
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)
2019-09-16 17:16:16 -07:00
self.tabs.setCurrentIndex(0)
2019-08-22 18:54:55 -07:00
QtCore.QMetaObject.connectSlotsByName(MainWindow)
2019-09-16 17:16:16 -07:00
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!")
2019-08-22 18:54:55 -07:00
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Continuity 0.0.1"))
2019-09-16 17:16:16 -07:00
self.audio_url_label.setText(_translate("MainWindow", "URL:"))
self.audio_tab_playlist.setText(_translate("MainWindow", "Playlist"))
2019-08-22 18:54:55 -07:00
self.audio_url_entry.setText(_translate("MainWindow", "Paste URL here"))
2019-09-16 17:16:16 -07:00
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"))
2019-08-22 18:54:55 -07:00
self.tabs.setTabText(self.tabs.indexOf(self.audioTab), _translate("MainWindow", "Audio"))
self.video_url_label.setText(_translate("MainWindow", "URL:"))
2019-09-16 17:16:16 -07:00
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"))
2019-08-22 18:54:55 -07:00
self.tabs.setTabText(self.tabs.indexOf(self.videoTab), _translate("MainWindow", "Video"))
2019-09-16 17:16:16 -07:00
self.download_button.setText(_translate("MainWindow", "Download"))
#self.download_button.clicked.connect(dl_file())
2019-08-22 18:54:55 -07:00
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"))
2019-09-16 17:16:16 -07:00
self.download_button.clicked.connect(self.dl_content)
2019-08-22 18:54:55 -07:00
2019-09-16 17:16:16 -07:00
#from KPushButton import KPushButton
2019-08-22 18:54:55 -07:00
if __name__ == "__main__":
2019-09-16 17:16:16 -07:00
import sys, os , subprocess
2019-08-22 18:54:55 -07:00
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())