am Ende gibt es ein Array, mit den einzelnen Links zu den verschiedenen Videos. Die progressbar soll den Vortschritt des Downloads von allen Videos anzeigen. Mit dem Befehl youtubevideo.filesize bekommt man die bitgröße des videos. Die gesamte Bitgröße habe ich auch bereits, allerdings weißß ich nicht, wie ich ein neues Fenster öffnen kann, in welchem ich dann den Vortschritt realisieren kann.
Code: Alles auswählen
# -*- coding: utf-8 -*-
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QLabel, QLineEdit, QTextBrowser, QMenuBar, QMenu, QProgressBar
from PyQt5.QtGui import QIcon, QFont
from PyQt5.QtCore import QRect, Qt, QCoreApplication
import sys
from threading import Thread
from pytube import YouTube
class Fenster(QWidget):
def __init__(self):
super().__init__()
self.youtube_links = []
self.init_me()
def init_me(self):
self.setObjectName("MainWindow")
self.resize(754, 778)
self.setWindowTitle("YoutubeDownloader by Jakob Priesner")
self.setWindowIcon(QIcon('youtube.png'))
self.textBrowser = QTextBrowser(self)
self.textBrowser.setGeometry(QRect(0, 30, 781, 51))
self.textBrowser.setObjectName("textBrowser")
self.textBrowser.setHtml("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:7.8pt; font-weight:400; font-style:normal;\">\n"
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:16pt; font-weight:600; color:#aa0000;\">YouTube - DOWNLOADER</span></p></body></html>")
self.label = QLabel(self)
self.label.setGeometry(QRect(10, 110, 711, 31))
self.label.setText("Willkommen im Youtube-Downloader von Jakob.\n"
"Füge unten einfach alle Links ein und drück auf herunterladen.")
self.label.setAlignment(Qt.AlignCenter)
self.label.setObjectName("label")
self.lineEdit = QLineEdit(self)
self.lineEdit.setGeometry(QRect(30, 270, 481, 41))
self.lineEdit.setPlaceholderText("Video-Link")
self.lineEdit.setObjectName("lineEdit")
self.pushButton = QPushButton(self)
self.pushButton.setGeometry(QRect(540, 270, 181, 41))
self.pushButton.setText("Add")
self.pushButton.setShortcut("")
self.pushButton.setObjectName("pushButton")
self.pushButton.clicked.connect(self.add_video)
self.label_2 = QLabel(self)
self.label_2.setGeometry(QRect(40, 340, 251, 16))
self.label_2.setText("Folgende Videos werden heruntergeladen:")
self.label_2.setObjectName("label_2")
self.label_3 = QTextBrowser(self)
self.label_3.setGeometry(QRect(30, 370, 691, 261))
self.label_3.setText("")
self.label_3.setObjectName("label_3")
self.pushButton_2 = QPushButton(self)
self.pushButton_2.setGeometry(QRect(540, 670, 181, 41))
self.pushButton_2.setText("herunterladen")
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_2.clicked.connect(self.herunterladen)
#self.pushButton_2.clicked.connect(self.close)
self.lineEdit_2 = QLineEdit(self)
self.lineEdit_2.setGeometry(QRect(30, 190, 691, 41))
self.lineEdit_2.setPlaceholderText("Download-Pfad")
self.lineEdit_2.setObjectName("lineEdit_2")
self.menubar = QMenuBar(self)
self.menubar.setGeometry(QRect(0, 0, 754, 26))
self.menubar.setObjectName("menubar")
self.menuExit = QMenu(self.menubar)
self.menuExit.setObjectName("menuExit")
self.menuExit.setTitle("Exit")
#self.setMenuBar(self.menubar)
self.menubar.addAction(self.menuExit.menuAction())
self.show()
def add_video(self):
if self.lineEdit.text() is not '':
self.youtube_links.append(self.lineEdit.text())
content = ""
for item in self.youtube_links:
content += item + "\n"
self.label_3.setText(content)
self.lineEdit.setText("")
else:
self.label_3.setText("Ungültige Eingeibe!")
def herunterladen(self):
print("herunterladen")
self.youtube_links = youtube_links
self.videos_size = 0
self.progress = 0
self.youtube_links = list(set(self.youtube_links))
print("festgelegt")
DOWNLOAD_PATH = self.lineEdit_2.text()
print(self.youtube_links)
for item in self.youtube_links:
self.videos_size += item.filesize
for item in self.youtube_links:
YouTube(item).streams.filter(progressive=True, file_extension='mp4').last().download(DOWNLOAD_PATH)
def close(self):
app.exec_()
class Progress():
def __init__(self):
super().__init__()
self.youtube_links = []
self.init_me()
def init_me(self):
self.setObjectName("Dialog")
self.resize(706, 183)
self.setWindowIcon(QIcon('youtube.png'))
self.setWindowTitle("Download")
self.progressBar = QProgressBar(Dialog)
self.progressBar.setGeometry(QtCore.QRect(60, 120, 581, 31))
self.progressBar.setProperty("value", 0)
self.progressBar.setTextVisible(True)
self.progressBar.setOrientation(QtCore.Qt.Horizontal)
self.progressBar.setInvertedAppearance(False)
self.progressBar.setObjectName("progressBar")
self.textEdit = QtWidgets.QTextEdit(Dialog)
self.textEdit.setGeometry(QtCore.QRect(60, 60, 581, 31))
self.textEdit.setObjectName("textEdit")
self.textEdit.setText("Aktuell wird heruntergelade:")
self.label = QtWidgets.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(60, 30, 271, 16))
self.label.setObjectName("label")
self.show()
app = QApplication(sys.argv)
w = Fenster()
sys.exit(app.exec_())