python - 对象没有属性“视频”
问题描述
我正在学习 PYQT5,所以这是我的第一次尝试。为了学习 PYQT5,我开始用 pyqt5 和 pytube 制作一个 youtube 视频下载器,但我无法处理进度条部分(播放列表)。当我运行代码时,它给出了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)
解决方案
可能这应该有帮助:
self.video = yt.streams.filter(progressive=True, file_extension='mp4').first()
self.video.download()
有4个地方可以添加self.video
推荐阅读
- perl - LWP::Simple get() 神秘地失败了
- python - 根据 Pandas 中的条件连接列的字符串值
- arrays - 错误:sub2ind:所有下标必须使用 Octave 4.2.2 的大小相同
- bit-shift - 为什么将 3 的算术右移到二进制序列“0110 0100”会导致“1110 1100”而不是“0000 1100”?
- java - 使用 MongoDB 和 Spring Data JPA 的复合主键
- javascript - 从 BehaviourSubject 检索到的 ngIf 和 Observable 之间是否存在冲突?
- google-api - 使用 Gmail API 加密
- ethereum - 如何修复“未知网络“ganache”。有关可用网络,请参阅您的 Truffle 配置文件。”
- php - 标头未发送,但以前它正在工作
- angular - @ViewChild('tTaskTeam', { read: MatAutocompleteTrigger }) 升级到 V8 后无法正常工作