Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 对象没有属性';视频&x27;_Python_Pyqt5_Pytube - Fatal编程技术网

Python 对象没有属性';视频&x27;

Python 对象没有属性';视频&x27;,python,pyqt5,pytube,Python,Pyqt5,Pytube,我正在学习PYQT5,所以这是我的第一次尝试。为了学习PYQT5,我开始用PYQT5和pytube制作youtube视频下载程序,但我无法处理进度条部分(播放列表)。当我运行代码时,它会给出一个AttributeError:“mywindow”对象没有属性“video” 你能给我一些建议吗 from PyQt5 import QtWidgets from pytube import YouTube, Playlist from mydesign import Ui_MainWindow #

我正在学习PYQT5,所以这是我的第一次尝试。为了学习PYQT5,我开始用PYQT5和pytube制作youtube视频下载程序,但我无法处理进度条部分(播放列表)。当我运行代码时,它会给出一个
AttributeError:“mywindow”对象没有属性“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)         
从PyQt5导入QtWidgets
从pytube导入YouTube,播放列表
从mydesign导入Ui_主窗口#导入生成的文件
导入系统
类mywindow(QtWidgets.QMainWindow):
定义初始化(自):
超级(mywindow,self)。\uuuuu init\uuuuuuu()
self.ui=ui\u主窗口()
self.ui.setupUi(self)
self.ui.action_IKI.setShortcut(“Ctrl+Q”)
self.ui.button.clicked.connect(self.click)
self.ui.action_IKI.triggered.connect(self.quit)
def退出(自我):
qtwidts.QApplication.quit()
def单击(自我):
self.completed=0
如果self.ui.comboBox.currentIndex()==0:
当自我完成<100时:
自完成+=0.0001
self.ui.progressBar_2.setValue(self.completed)
elif self.ui.comboBox.currentIndex()==1:
link=self.ui.lineEdit.text()
yt=YouTube(链接,on\u progress\u callback=self.progress\u func)
video=yt.streams.filter(progressive=True,文件扩展名=mp4').first()
视频下载()
elif self.ui.comboBox.currentIndex()==2:
通过
elif self.ui.comboBox.currentIndex()==3:
pl=播放列表(self.ui.lineEdit.text())
pl.填充视频URL()
对于pl.video_URL中的i:
yt=YouTube(i,on\u progress\u callback=self.progress\u func)
video=yt.streams.filter(progressive=True,file_extension=“mp4”).first()
视频下载()
def progress_func(自身、流、块、文件句柄、剩余字节):
size=self.video.filesize
self.progress=(浮点(abs(字节大小)/大小))*float(100)
self.ui.progressBar_2.setValue(self.progress)

这可能会有帮助:

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

有4个地方可以添加自我。视频给你一个例子,它成功了

yt = YouTube(YouTube_url,on_progress_callback=self.on_progress)
self.video = yt.streams.first()
self.video.download(self.datapath + '/video/', video_id)
def on_progress(self, chunk, file_handler, remaining):
    contentSize = self.video.filesize
    size = contentSize - remaining
    # print('已下载%.2f' % (percent))
    print('\r' + '[Download progress]:[%s%s]%.2f%%' % (
        '█' * int(size * 20 / contentSize), ' ' * (20 - int(size * 20 / contentSize)),
        float(size / contentSize * 100)), end='')
结果是:


如果有帮助,您能将我的答案标记为正确的变体吗?:-)