1
저는 python에 익숙하지 않으며이 강력한 언어를 배우는 중입니다. 나는 다음 스크립트를 쓸 수 있었다. 그것은 무엇이 잘못 될지 알지 못하는 부분적인 출력 (그것의 단지 두 줄)을 얻습니다! 도와주세요.QProcess를 사용하여 youtube-dl을 출력하십시오.
#!/usr/bin/env python
#-*- coding: utf-8 -*-
from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import (QProcess,QRect,SIGNAL,SLOT,QString,QStringList,qDebug)
from PyQt4.QtGui import (QMainWindow,QWidget,QPushButton,QTextEdit,QApplication)
class YTDL (QtGui.QMainWindow):
def __init__ (self,parent=None):
super(YTDL,self).__init__(parent)
self.resize(400,300)
self.setWindowTitle("Youtube-dl output using QProcess")
self.__init_Components()
self.__ui_event_handler()
def __init_Components(self):
self.proc = QProcess()
self.cw = QWidget(self)
self.btn = QPushButton(self.cw)
self.btn.setText("Run")
self.btn.setGeometry(QRect(270,10,110,27))
self.te = QTextEdit(self.cw)
self.te.setReadOnly(True)
self.te.setOverwriteMode(False)
self.te.setGeometry(QRect(10,40,380,170))
self.setCentralWidget(self.cw)
def __ui_event_handler(self):
self.connect(self.btn, SIGNAL('clicked()'),self.Button_Clicked)
def Button_Clicked(self):
args = '-ct -f 18 --extract-audio --audio-quality 320k --audio-format mp3 -k http://www.youtube.com/watch?v=OiPO_TAAZPc'
cmd = 'youtube-dl'
self.proc.setWorkingDirectory("~/Videos/Folder1")
self.connect(self.proc, SIGNAL('readyRead()'),self._read)
self.proc.setOpenMode(self.proc.ReadWrite)
self.proc.start(cmd ,args)
if not self.proc.waitForStarted():
exit(1)
def _read(self):
s = self.proc.readAllStandardOutput()
qDebug (s)
print (s)
self.te.append(QString(s))
def main():
import sys
app = QApplication(sys.argv)
ytdl = YTDL()
ytdl.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
초기화 (부모). 또한 스크립트에서 수행하고자하는 작업과 수행중인 작업은 무엇입니까? –
필자가 작성한대로 명령을 실행하고 QtextEdit 상자에 youtube-dl 명령의 출력을 표시하려고합니다. – user1787326
출력 내용은 다음과 같습니다. [youtube] 설정 언어 [youtube] - : 다운로드 비디오 웹 페이지 – user1787326