Объект не имеет атрибута "видео" - PullRequest
0 голосов
/ 26 января 2019

Я изучаю PYQT5, так что это моя первая попытка. Чтобы изучить PYQT5, я начал делать загрузчик видео на YouTube с pyqt5 и pytube, но не смог обработать часть индикатора выполнения (плейлисты). Когда я запускаю код, он дает AttributeError: 'mywindow' object has no attribute 'video'

Можете ли вы дать мне совет?

from PyQt5 import QtWidgets

from pytube import YouTube, Playlist

from mydesign import Ui_MainWindow  # importing our generated file

import sys

class mywindow(QtWidgets.QMainWindow):

    def __init__(self):

        super(mywindow, self).__init__()

        self.ui = Ui_MainWindow()

        self.ui.setupUi(self)
        self.ui.action_IKI.setShortcut("Ctrl+Q")
        self.ui.pushButton.clicked.connect(self.click)
        self.ui.action_IKI.triggered.connect(self.quit)


    def quit(self):
        QtWidgets.QApplication.quit()



    def click(self):
        self.completed = 0
        if self.ui.comboBox.currentIndex() == 0:
            while self.completed < 100:
                self.completed += 0.0001
                self.ui.progressBar_2.setValue(self.completed)
        elif self.ui.comboBox.currentIndex() == 1:
            link = self.ui.lineEdit.text()
            yt = YouTube(link, on_progress_callback=self.progress_func)
            video = yt.streams.filter(progressive=True, file_extension='mp4').first()
            video.download()


        elif self.ui.comboBox.currentIndex() == 2:
            pass

        elif self.ui.comboBox.currentIndex() == 3:
            pl = Playlist(self.ui.lineEdit.text())
            pl.populate_video_urls()
            for i in pl.video_urls:
                yt = YouTube(i, on_progress_callback=self.progress_func)
                video = yt.streams.filter(progressive=True, file_extension="mp4").first()
                video.download()

    def progress_func(self, stream, chunk, file_handle, bytes_remaining):
        size = self.video.filesize
        self.progress = (float(abs(bytes_remaining-size)/size))*float(100)
        self.ui.progressBar_2.setValue(self.progress)         

1 Ответ

0 голосов
/ 27 января 2019

Может быть, это должно помочь:

self.video = yt.streams.filter(progressive=True, file_extension='mp4').first()
self.video.download()

Есть 4 места для добавления self.video

...