PyQt5 Youtube Downloader
Last active
August 26, 2017 01:45
-
-
Save eyllanesc/3490e43619b922ef1bb04bd0716bddb1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# Form implementation generated from reading ui file 'MainWindow.ui' | |
# | |
# Created by: PyQt5 UI code generator 5.6 | |
# | |
# WARNING! All changes made in this file will be lost! | |
from PyQt5 import QtCore, QtGui, QtWidgets | |
class Ui_MainWindow(object): | |
def setupUi(self, MainWindow): | |
MainWindow.setObjectName("MainWindow") | |
MainWindow.resize(824, 728) | |
MainWindow.setMinimumSize(QtCore.QSize(250, 150)) | |
self.centralwidget = QtWidgets.QWidget(MainWindow) | |
self.centralwidget.setEnabled(True) | |
self.centralwidget.setMaximumSize(QtCore.QSize(1218, 836)) | |
self.centralwidget.setLayoutDirection(QtCore.Qt.LeftToRight) | |
self.centralwidget.setObjectName("centralwidget") | |
self.gridLayout = QtWidgets.QGridLayout(self.centralwidget) | |
self.gridLayout.setObjectName("gridLayout") | |
self.downloadButton = QtWidgets.QPushButton(self.centralwidget) | |
self.downloadButton.setObjectName("downloadButton") | |
self.gridLayout.addWidget(self.downloadButton, 2, 0, 1, 2) | |
self.urlInput = QtWidgets.QLineEdit(self.centralwidget) | |
font = QtGui.QFont() | |
font.setPointSize(10) | |
self.urlInput.setFont(font) | |
self.urlInput.setClearButtonEnabled(False) | |
self.urlInput.setObjectName("urlInput") | |
self.gridLayout.addWidget(self.urlInput, 0, 0, 1, 1) | |
self.setURL = QtWidgets.QPushButton(self.centralwidget) | |
self.setURL.setObjectName("setURL") | |
self.gridLayout.addWidget(self.setURL, 0, 1, 1, 1) | |
spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) | |
#self.gridLayout.addItem(spacerItem, 1, 0, 1, 1) | |
MainWindow.setCentralWidget(self.centralwidget) | |
self.menubar = QtWidgets.QMenuBar(MainWindow) | |
self.menubar.setGeometry(QtCore.QRect(0, 0, 824, 21)) | |
self.menubar.setObjectName("menubar") | |
MainWindow.setMenuBar(self.menubar) | |
self.retranslateUi(MainWindow) | |
QtCore.QMetaObject.connectSlotsByName(MainWindow) | |
def retranslateUi(self, MainWindow): | |
_translate = QtCore.QCoreApplication.translate | |
MainWindow.setWindowTitle(_translate("MainWindow", "Youtube Downloader")) | |
self.downloadButton.setText(_translate("MainWindow", "Download Youtube Video")) | |
self.urlInput.setText(_translate("MainWindow", "Enter URL here (include http://www)")) | |
self.setURL.setText(_translate("MainWindow", "Go to entered URL")) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<ui version="4.0"> | |
<class>MainWindow</class> | |
<widget class="QMainWindow" name="MainWindow"> | |
<property name="geometry"> | |
<rect> | |
<x>0</x> | |
<y>0</y> | |
<width>824</width> | |
<height>728</height> | |
</rect> | |
</property> | |
<property name="minimumSize"> | |
<size> | |
<width>250</width> | |
<height>150</height> | |
</size> | |
</property> | |
<property name="windowTitle"> | |
<string>Youtube Downloader</string> | |
</property> | |
<widget class="QWidget" name="centralwidget"> | |
<property name="enabled"> | |
<bool>true</bool> | |
</property> | |
<property name="maximumSize"> | |
<size> | |
<width>1218</width> | |
<height>836</height> | |
</size> | |
</property> | |
<property name="layoutDirection"> | |
<enum>Qt::LeftToRight</enum> | |
</property> | |
<layout class="QGridLayout" name="gridLayout"> | |
<item row="2" column="0" colspan="2"> | |
<widget class="QPushButton" name="downloadButton"> | |
<property name="text"> | |
<string>Download Youtube Video</string> | |
</property> | |
</widget> | |
</item> | |
<item row="0" column="0"> | |
<widget class="QLineEdit" name="urlInput"> | |
<property name="font"> | |
<font> | |
<pointsize>10</pointsize> | |
</font> | |
</property> | |
<property name="text"> | |
<string>Enter URL here (include http://www)</string> | |
</property> | |
<property name="clearButtonEnabled"> | |
<bool>false</bool> | |
</property> | |
</widget> | |
</item> | |
<item row="0" column="1"> | |
<widget class="QPushButton" name="setURL"> | |
<property name="text"> | |
<string>Go to entered URL</string> | |
</property> | |
</widget> | |
</item> | |
<item row="1" column="0"> | |
<spacer name="verticalSpacer"> | |
<property name="orientation"> | |
<enum>Qt::Vertical</enum> | |
</property> | |
<property name="sizeHint" stdset="0"> | |
<size> | |
<width>20</width> | |
<height>40</height> | |
</size> | |
</property> | |
</spacer> | |
</item> | |
</layout> | |
</widget> | |
<widget class="QMenuBar" name="menubar"> | |
<property name="geometry"> | |
<rect> | |
<x>0</x> | |
<y>0</y> | |
<width>824</width> | |
<height>21</height> | |
</rect> | |
</property> | |
</widget> | |
</widget> | |
<resources/> | |
<connections/> | |
</ui> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from PyQt5.QtWidgets import * | |
from PyQt5.QtGui import * | |
from PyQt5.QtCore import * | |
from PyQt5 import QtWidgets, QtCore, QtGui, QtTest | |
from PyQt5 import QtWebEngine,QtWebEngineWidgets, QtWebEngineCore | |
from PyQt5.QtWebEngineWidgets import QWebEngineView | |
import os, subprocess, youtube_dl, MainWindow | |
from MainWindow import * | |
class App(QMainWindow, Ui_MainWindow): | |
def __init__(self): | |
super().__init__() | |
self.setupUi(self) | |
self.setUpStuff() | |
def setUpStuff(self): | |
#self.engineView = QWebEngineView | |
#self.engineView.load(QWebEngineView, QtCore.QUrl("http://www.Youtube.com")) | |
#self.webView.setEnabled(True) | |
#self.webView.setObjectName("webView") | |
#self.webView.setBaseSize(30, 30) | |
self.webView = QWebEngineView() | |
self.webView.load(QUrl('http://youtube.com')) | |
self.webView.setBaseSize(500,500) | |
self.webView.setVisible(True) | |
self.getActualURL() | |
self.gridLayout.addWidget(self.webView, 1, 0, 1, 2) | |
#ui.downloadButton.setEnabled(False) | |
#ui.setURL.setEnabled(False) | |
self.downloadButton.clicked.connect(self.youtubeDownload) | |
self.setURL.clicked.connect(self.setURLm) | |
#self.getActualURL() | |
#self.webView.installEventFilter(self) | |
#def event(self,obj): | |
#if obj == self.webView: | |
#if(self.webView.hasFocus() == True): | |
#self.getActualURL() | |
#self.setURLm | |
#return False | |
def getActualURL(self): | |
print("getactualurl") | |
i = self.webView.url() | |
i = str(i) | |
i = i[19:] | |
ilen = i.__len__() | |
url = i[:ilen - 2] | |
print(url) | |
#self.urlInput.setText(url) | |
@pyqtSlot() | |
def youtubeDownload(self): | |
print("ytdownload") | |
try: | |
with youtube_dl.YoutubeDL({}) as ydl: | |
login = os.getlogin() | |
path = "C:/Users/"+login+"/Downloads/Youtube_Downloader" | |
if not os.path.exists(path): | |
os.makedirs(path) | |
os.chdir(path) | |
ydl.download([str(self.urlInput.displayText())]) | |
except: | |
msgBox = QMessageBox() | |
msgBox.setText("Error:") | |
msgBox.setInformativeText("An unknown error occurred. Ensure video link is correct") | |
msgBox.setStandardButtons(QMessageBox.Ok) | |
msgBox.setDefaultButton(QMessageBox.Ok) | |
msgBox.exec_() | |
@pyqtSlot() | |
def setURLm(self): | |
print("seturlm") | |
try: | |
url = self.urlInput.displayText() | |
i7 = url[:7] | |
i8 = url[:8] | |
if (i7 == "http://" or i8 == "https://"): | |
pass | |
else: | |
url = "http://"+url | |
print(url) | |
self.webView.load(QUrl(url)) | |
except: | |
pass | |
app = QApplication(sys.argv) | |
l = App() | |
l.show() | |
sys.exit(app.exec_()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@C:/Users/Michael/Anaconda3\python.exe -m PyQt5.uic.pyuic %1 %2 %3 %4 %5 %6 %7 %8 %9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment