在此处输入图像描述我使用 PyQt5 制作从 youtube 下载视频的下载 GUI 程序,我在代码中使用 pafy 模块,问题是当我将脚本转换为 exe 文件时出现 gui,但当我按下按钮时程序没有响应开始下载,程序没有响应并关闭,并且这个错误出现在 cmd “类型错误:不能在路径组件中混合字符串和字节”,这是我使用的代码,
我使用win10和python3.6。
class threading_one(QThread, QMessageBox):
signal = pyqtSignal()
count_pro = pyqtSignal(int)
cha_name = pyqtSignal(str)
def __init__(self):
QThread.__init__(self)
def progress_count(self, total, recvd, ratio, rate, eta):
read_data = recvd
if total > 0:
download_percentage = read_data * 100 / total
self.count_pro.emit(download_percentage)
if download_percentage >= 100:
self.signal.emit()
def run(self):
video = pafy.new(self.url)
stream = video.getbest(preftype='mp4')
self.cha_name.emit(video.title)
stream.download(filepath=self.save, callback=self.progress_count)
self.signal.emit()
class MainApp(QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super(MainApp, self).__init__(parent)
self.setupUi(self)
self.Handel_Screen()
self.Handel_Button()
def Handel_Screen(self):
self.setWindowTitle("Test Download Program")
def Handel_Button(self):
self.pushButton.clicked.connect(self.download_video)
self.pushButton_2.clicked.connect(self.Browse_Location)
self.down_single = threading_one()
self.down_single.signal.connect(self.finish)
self.down_single.count_pro.connect(self.chang_progressBar)
self.down_single.cha_name.connect(self.change_name_video)
def chang_progressBar(self, value):
self.progressBar.setValue(value)
def finish(self):
QMessageBox.information(self, "Complete Download ...", "Your Download is Complete ...")
self.lineEdit.clear()
self.progressBar.setValue(0)
self.pushButton.setEnabled(True)
def Browse_Location(self):
save_lacation = QFileDialog.getExistingDirectory(self, 'Select Location')
self.label.setText(save_lacation)
def change_name_video(self, title):
self.label_2.setText(title)
def download_video(self):
self.down_single.url = self.lineEdit.text()
self.down_single.save = self.label.text()
if self.lineEdit.text() == "":
QMessageBox.warning(self, " From System ! ", " Please put valid URL first !! ")
return
self.pushButton.setEnabled(False)
self.down_single.start()
def main():
app = QApplication(sys.argv)
window = MainApp()
window.show()
app.exec()
if __name__ == '__main__':
main()
错误:
C:\Users\Amr\PycharmProjects\test1\venv\Scripts\python.exe C:/Users/Amr/PycharmProjects/test1/index.py
Traceback (most recent call last):
File "C:/Users/Amr/PycharmProjects/test1/index.py", line 42, in run
stream.download(filepath=self.save, callback=self.progress_count)
File "C:\Users\Amr\PycharmProjects\test1\venv\lib\site-packages\pafy\backend_shared.py", line 587, in download
filepath = os.path.join(savedir, filename)
File "C:\Users\Amr\AppData\Local\Programs\Python\Python36\lib\ntpath.py", line 115, in join
genericpath._check_arg_types('join', path, *paths)
File "C:\Users\Amr\AppData\Local\Programs\Python\Python36\lib\genericpath.py", line 151, in _check_arg_types
raise TypeError("Can't mix strings and bytes in path components") from None
TypeError: Can't mix strings and bytes in path components
Process finished with exit code -1073740791 (0xC0000409)