From 03a5e89d38dfc03508e4283ff16f38533fc3816b Mon Sep 17 00:00:00 2001 From: haujet <1292756898@qq.com> Date: Sun, 26 Jul 2020 10:17:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E4=BA=86=20if=20platfm=20?= =?UTF-8?q?=E6=9D=A5=E5=88=A4=E6=96=AD=E5=B9=B3=E5=8F=B0=EF=BC=8C=E8=BF=99?= =?UTF-8?q?=E6=A0=B7=EF=BC=8C=E5=9C=A8=20mac=20=E5=92=8C=20linux=20?= =?UTF-8?q?=E4=B8=8A=E5=B0=B1=E4=B8=8D=E4=BC=9A=E8=A7=A6=E5=8F=91=20subpro?= =?UTF-8?q?cess=20=E7=9A=84=20startupinfo=20=E9=80=89=E9=A1=B9=E4=BA=86?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- QuickCut.py | 189 ++++++++++++++++++++++++---------------------------- README.md | 12 ++++ 2 files changed, 100 insertions(+), 101 deletions(-) diff --git a/QuickCut.py b/QuickCut.py index 5ba6aea..e0764ae 100644 --- a/QuickCut.py +++ b/QuickCut.py @@ -57,7 +57,7 @@ apiTableName = 'api' preferenceTableName = 'preference' finalCommand = '' -version = 'V1.0.2' +version = 'V1.0.3' class MainWindow(QMainWindow): @@ -128,7 +128,6 @@ def onUpdateText(self, text): def closeEvent(self, event): """Shuts down application on close.""" # Return stdout to defaults. - print(main.ConfigTab.hideToSystemTraySwitch.isChecked()) if main.ConfigTab.hideToSystemTraySwitch.isChecked(): event.ignore() self.hide() @@ -1833,8 +1832,8 @@ def __init__(self): self.initUI() def drop(self): - print('12345') - + # print('12345') + pass def initUI(self): self.inputHintLabel = QLabel('点击列表右下边的加号添加要合并的视频片段:') self.fileListWidget = FileListWidget(self) # 文件表控件 @@ -2250,7 +2249,6 @@ def youGetCheckInfoButtonClicked(self): if self.youGetProxyBox.currentText() != '': finalCommand += ''' %s''' % self.youGetProxyBox.currentText() finalCommand += ''' -i %s''' % self.youGetInputBox.text() - print(finalCommand) thread = CommandThread() thread.command = finalCommand window = Console(main) @@ -2270,8 +2268,6 @@ def youTubeDlCheckInfoButtonClicked(self): if self.youTubeDlProxyBox.currentText() != '': finalCommand += ''' --proxy %s''' % self.youTubeDlProxyBox.currentText() finalCommand += ''' -F %s''' % self.youTubeDlInputBox.text() - print(finalCommand) - print(finalCommand) thread = CommandThread() thread.command = finalCommand window = Console(main) @@ -2285,7 +2281,7 @@ def youTubeDlCheckInfoButtonClicked(self): def youGetDownloadButtonClicked(self): if self.youGetInputBox.text != '': - finalCommand = '''you-get''' + finalCommand = '''you-get -f''' if self.youGetSaveBox.currentText() != '': finalCommand += ''' -o %s''' % self.youGetSaveBox.currentText() if self.youGetDownloadFormatBox.text() != '': @@ -2297,7 +2293,6 @@ def youGetDownloadButtonClicked(self): if self.youGetPlayListBox.isChecked() != False: finalCommand += ''' --playlist''' finalCommand += ''' %s''' % self.youGetInputBox.text() - print(finalCommand) thread = CommandThread() thread.command = finalCommand window = Console(main) @@ -2328,8 +2323,6 @@ def youTubeDlDownloadButtonClicked(self): if self.youTubeDlOnlyDownloadSubtitleBox.isChecked() != False: finalCommand += ''' --skip-download''' finalCommand += ''' %s''' % self.youTubeDlInputBox.text() - print(finalCommand) - print(finalCommand) thread = CommandThread() thread.command = finalCommand window = Console(main) @@ -3055,58 +3048,50 @@ def initGui(self): # self.apiBoxLayout.addStretch(0) self.db = QSqlDatabase.addDatabase('QSQLITE') - print('is it? ') self.db.setDatabaseName(dbname) - print('1') self.model = QSqlTableModel() # api 表的模型 - print('1') self.delrow = -1 - print('1') self.model.setTable(apiTableName) - print('1') self.model.setEditStrategy(QSqlTableModel.OnRowChange) - print('1') self.model.select() - print('1') self.model.setHeaderData(0, Qt.Horizontal, 'id') - print('1') self.model.setHeaderData(1, Qt.Horizontal, '引擎名称') - print('1') + self.model.setHeaderData(2, Qt.Horizontal, '服务商') - print('1') + self.model.setHeaderData(3, Qt.Horizontal, 'AppKey') - print('1') + self.model.setHeaderData(4, Qt.Horizontal, '语言') - print('1') + self.model.setHeaderData(5, Qt.Horizontal, 'AccessKeyId') - print('1') + self.model.setHeaderData(6, Qt.Horizontal, 'AccessKeySecret') - print('1') + self.apiTableView = QTableView() - print('1') + self.apiTableView.setModel(self.model) - print('1') + self.apiTableView.hideColumn(0) - print('1') + self.apiTableView.hideColumn(5) - print('1') + self.apiTableView.hideColumn(6) - print('1') + self.apiTableView.setColumnWidth(1, 150) - print('1') + self.apiTableView.setColumnWidth(2, 100) - print('1') + self.apiTableView.setColumnWidth(3, 150) - print('1') + self.apiTableView.setColumnWidth(4, 200) - print('1') + self.apiTableView.setEditTriggers(QAbstractItemView.NoEditTriggers) - print('1') + self.apiTableView.setSelectionBehavior(QAbstractItemView.SelectRows) - print('1') + # self.apiTableView.setsize(600) self.apiBoxLayout.addWidget(self.apiTableView) - print('1') + # self.apiBoxLayout.addStretch(0) self.appKeyControlButtonLayout = QHBoxLayout() @@ -3695,7 +3680,7 @@ def print(self, text): self.setTextCursor(cursor) self.ensureCursorVisible() except: - print(text) + pass pass @@ -3720,17 +3705,21 @@ def printForFFmpeg(self, text): def run(self): self.print('开始执行命令\n') try: - self.process = subprocess.Popen(self.command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, - universal_newlines=True, encoding='utf-8',startupinfo=subprocessStartUpInfo) + if platfm == 'Windows': + self.process = subprocess.Popen(self.command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, + universal_newlines=True, encoding='utf-8', + startupinfo=subprocessStartUpInfo) + else: + self.process = subprocess.Popen(self.command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, + universal_newlines=True, encoding='utf-8') except: self.print('命令运行出错了,估计是你的 you-get、youtube-dl 没有安装上。快去看下视频教程的下载视频这一节吧,里面有安装 you-get 和 youtube-dl 的命令') try: for line in self.process.stdout: self.printForFFmpeg(line) - print(line) except: self.print( - '出错了,为了兼容中文 Windows 的编码,在源代码的 class CommandThread(QThread) 中的 def run(self) 下边,self.process 用的是 utf-8 编码,有可能是那里出的问题。') + '''出错了,本次运行的命令是:\n\n%s\n\n你可以将上面这行命令复制到 cmd 窗口运行下,看看报什么错,如果自己解决不了,把那个报错信息发给开发者''' % self.command) self.print('\n命令执行完毕\n') # except: # self.print('\n\n命令执行出错,可能是系统没有安装必要的软件,如 FFmpeg, you-get, youtube-dl 等等') @@ -3785,51 +3774,34 @@ def run(self): self.cutStartTime = self.cutStartTime + '.0' if re.match(r'\d+:\d+:\d+\.\d+', self.cutStartTime): temp = re.findall('\d+', self.cutStartTime) - print(temp) self.cutStartTime = float(temp[0]) * 3600 + float(temp[1]) * 60 + float(temp[2]) + float( '0.' + temp[3]) - print(self.cutStartTime) elif re.match(r'\d+:\d+\.\d+', self.cutStartTime): temp = re.findall('\d+', self.cutStartTime) - print(temp) self.cutStartTime = float(temp[0]) * 60 + float(temp[1]) + float('0.' + temp[2]) - print(self.cutStartTime) elif re.match(r'\d+\.\d+', self.cutStartTime): temp = re.findall('\d+', self.cutStartTime) - print(temp) self.cutStartTime = float(temp[0]) + float('0.' + temp[1]) - print(self.cutStartTime) elif re.match(r'\d+', self.cutStartTime): temp = re.findall('\d+', self.cutStartTime) - print(temp) self.cutStartTime = float(temp[0]) - print(self.cutStartTime) else: self.print('起始剪切时间格式有误,命令结束') return 0 - print('end') if self.cutEndTime != '': # 如果结束时间不为空,转换为秒数 if re.match(r'\d+:\d+:\d+\.\d+', self.cutEndTime): temp = re.findall('\d+', self.cutEndTime) - print(temp) self.cutEndTime = float(temp[0]) * 3600 + float(temp[1]) * 60 + float(temp[2]) + float( '0.' + temp[3]) - print(self.cutEndTime) elif re.match(r'\d+:\d+\.\d+', self.cutEndTime): temp = re.findall('\d+', self.cutEndTime) - print(temp) self.cutEndTime = float(temp[0]) * 60 + float(temp[1]) + float('0.' + temp[2]) - print(self.cutEndTime) elif re.match(r'\d+\.\d+', self.cutEndTime): temp = re.findall('\d+', self.cutEndTime) - print(temp) self.cutEndTime = float(temp[0]) + float('0.' + temp[1]) - print(self.cutEndTime) elif re.match(r'\d+', self.cutEndTime): temp = re.findall('\d+', self.cutEndTime) - print(temp) self.cutEndTime = float(temp[0]) - print(self.cutEndTime) else: self.print('起始剪切时间格式有误,命令结束') return 0 @@ -3837,8 +3809,7 @@ def run(self): if re.match('\.ass', subtitleExt, re.IGNORECASE): self.print('字幕是ass格式,先转换成srt格式\n') command = '''ffmpeg -y -hide_banner -i "%s" "%s" ''' % (self.subtitleFile, subtitleName + '.srt') - print(command) - self.process = subprocess.call(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, + self.process = subprocess.call(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) # for line in self.process.stdout: # self.print(line) @@ -3863,8 +3834,7 @@ def run(self): elif re.match('\.mkv', subtitleExt, re.IGNORECASE): self.print('字幕是 mkv 格式,先转换成srt格式\n') command = '''ffmpeg -y -hide_banner -i "%s" -an -vn "%s" ''' % (self.subtitleFile, subtitleName + '.srt') - print(command) - self.process = subprocess.call(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, + self.process = subprocess.call(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) # for line in self.process.stdout: # self.print(line) @@ -3887,7 +3857,6 @@ def run(self): except: self.print('删除生成的srt字幕失败') elif re.match('\.srt', subtitleExt, re.IGNORECASE): - print(self.subtitleFile) with f: subtitleContent = f.read() else: @@ -3904,7 +3873,6 @@ def run(self): self.print('创建输出文件夹失败,可能是已经创建上了\n') self.clipOutputOption = '' for i in range(0, totalNumber, self.subtitleNumberPerClip): - print(format(i, '0>6d')) # Subtitle(index=2, start=datetime.timedelta(seconds=11, microseconds=800000), end=datetime.timedelta(seconds=13, microseconds=160000), content='该喝水了', proprietary='') # Subtitle(index=2, start=datetime.timedelta(seconds=11, microseconds=800000), end=datetime.timedelta(seconds=13, microseconds=160000), content='该喝水了', proprietary='') self.print('总共有 %s 段要处理,现在开始导出第 %s 段……\n' % (int(totalNumber / self.subtitleNumberPerClip), int( @@ -3920,17 +3888,20 @@ def run(self): if self.cutSwitchValue != 0: # 如果确定要剪切一个区间 if self.cutStartTime != '': # 如果起始文件不为空 if end < self.cutStartTime: - print('%s < %s, continue' % (end, self.cutStartTime)) continue if self.cutEndTime != '': if start > self.cutEndTime: - print('%s > %s, continue' % (start, self.cutEndTime)) continue index = format(srtList[i].index, '0>6d') command = 'ffmpeg -y -ss %s -to %s -i "%s" %s "%s"' % ( start, end, self.inputFile, self.clipOutputOption, self.outputFolder + index + '.' + inputFileExt) - self.process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, - universal_newlines=True, encoding='utf-8', startupinfo=subprocessStartUpInfo) + if platfm == 'Windows': + self.process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, + universal_newlines=True, encoding='utf-8', + startupinfo=subprocessStartUpInfo) + else: + self.process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, + universal_newlines=True, encoding='utf-8') for line in self.process.stdout: self.printForFFmpeg(line) pass @@ -4016,7 +3987,6 @@ def run(self): else: 视频处理的总时长 = 视频文件的总时长 - 视频处理的起点时刻 - print('起始:%s 终止:%s' % (视频处理的起点时刻, 视频处理的总时长)) try: os.mkdir(self.outputFolder) except: @@ -4035,8 +4005,13 @@ def run(self): command = '''ffmpeg -y -ss %s -t %s -i "%s" "%s"''' % ( 视频处理的起点时刻, 每段输出视频的时长, self.inputFile, self.outputFolder + format(i, '0>6d') + self.ext) # self.print(command) - self.process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, - universal_newlines=True, encoding='utf-8', startupinfo=subprocessStartUpInfo) + if platfm == 'Windows': + self.process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, + universal_newlines=True, encoding='utf-8', + startupinfo=subprocessStartUpInfo) + else: + self.process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, + universal_newlines=True, encoding='utf-8') for line in self.process.stdout: self.printForFFmpeg(line) pass @@ -4098,7 +4073,6 @@ def run(self): 视频处理的总时长 = 视频文件的总时长 - 视频处理的起点时刻 总共应导出的时长 = 视频处理的总时长 - print('起始:%s 终止:%s' % (视频处理的起点时刻, 视频处理的总时长)) try: os.mkdir(self.outputFolder) except: @@ -4116,8 +4090,13 @@ def run(self): command = '''ffmpeg -y -ss %s -t %s -i "%s" -fs %s "%s"''' % ( 视频处理的起点时刻, 视频处理的总时长, self.inputFile, 每段输出视频的大小, self.outputFolder + format(i, '0>6d') + self.ext) # self.print(command) - self.process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, - universal_newlines=True, encoding='utf-8', startupinfo=subprocessStartUpInfo) + if platfm == 'Windows': + self.process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, + universal_newlines=True, encoding='utf-8', + startupinfo=subprocessStartUpInfo) + else: + self.process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, + universal_newlines=True, encoding='utf-8') self.print('\n\n\n\n\n\n\n还有 %s 秒时长的片段要导出,总共已经导出 %s 秒的视频,目前正在导出的是第 %s 个片段……\n' % (format(视频处理的总时长, '.1f'), format(已导出的总时长, '.1f'), i)) for line in self.process.stdout: self.printForFFmpeg(line) @@ -4275,8 +4254,13 @@ def run(self): self.print('\n\n将所有视频帧提取到临时文件夹:\n\n') command = 'ffmpeg -hide_banner -i "%s" -qscale:v %s %s/frame%s' % ( self.inputFile, self.frameQuality, self.TEMP_FOLDER, "%06d.jpg") - self.process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, - universal_newlines=True, encoding='utf-8', startupinfo=subprocessStartUpInfo) + if platfm == 'Windows': + self.process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, + universal_newlines=True, encoding='utf-8', + startupinfo=subprocessStartUpInfo) + else: + self.process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, + universal_newlines=True, encoding='utf-8') for line in self.process.stdout: self.printForFFmpeg(line) @@ -4285,8 +4269,13 @@ def run(self): self.print('\n\n分离出音频流:\n\n') command = 'ffmpeg -hide_banner -i "%s" -ab 160k -ac 2 -ar %s -vn %s/audio.wav' % ( self.inputFile, SAMPLE_RATE, self.TEMP_FOLDER) - self.process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, - universal_newlines=True, encoding='utf-8', startupinfo=subprocessStartUpInfo) + if platfm == 'Windows': + self.process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, + universal_newlines=True, encoding='utf-8', + startupinfo=subprocessStartUpInfo) + else: + self.process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, + universal_newlines=True, encoding='utf-8') for line in self.process.stdout: self.printForFFmpeg(line) @@ -4514,8 +4503,13 @@ def run(self): # command = ["ffmpeg","-y","-hide_banner","-safe","0","-f","concat","-i",TEMP_FOLDER+"/concat.txt","-framerate",str(frameRate),TEMP_FOLDER+"/audioNew.wav"] command = 'ffmpeg -y -hide_banner -safe 0 -f concat -i %s/concat.txt -framerate %s %s/audioNew.wav' % ( self.TEMP_FOLDER, frameRate, self.TEMP_FOLDER) - self.process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, - universal_newlines=True, encoding='utf-8', startupinfo=subprocessStartUpInfo) + if platfm == 'Windows': + self.process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, + universal_newlines=True, encoding='utf-8', + startupinfo=subprocessStartUpInfo) + else: + self.process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, + universal_newlines=True, encoding='utf-8') for line in self.process.stdout: # self.print(line) pass @@ -4524,8 +4518,12 @@ def run(self): # command = ["ffmpeg","-y","-hide_banner","-framerate",str(frameRate),"-i",TEMP_FOLDER+"/newFrame%06d.jpg","-i",TEMP_FOLDER+"/audioNew.wav","-strict","-2",OUTPUT_FILE] command = 'ffmpeg -y -hide_banner -framerate %s -i %s/newFrame%s -i %s/audioNew.wav -strict -2 %s "%s"' % ( frameRate, self.TEMP_FOLDER, "%06d.jpg", self.TEMP_FOLDER, self.ffmpegOutputOption, self.outputFile) - self.process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, + if platfm == 'Windows': + self.process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, encoding='utf-8', startupinfo=subprocessStartUpInfo) + else: + self.process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, + universal_newlines=True, encoding='utf-8') for line in self.process.stdout: self.printForFFmpeg(line) @@ -4591,7 +4589,6 @@ def run(self): apiProvider, apiappKey, apiLanguage, apiAccessKeyId, apiAccessKeySecret = apiData[0], apiData[1], apiData[ 2], apiData[3], apiData[4] - print('name: %s provider: %s appKey: %s accessKeyId: %s accessKeySecret: %s' %(self.apiEngine, apiProvider, apiappKey, apiAccessKeyId, apiAccessKeySecret)) if apiProvider == 'Alibaba': transEngine = AliTrans() elif apiProvider == 'Tencent': @@ -4638,20 +4635,6 @@ def run(self): try: - print("""\r\nCaps Writer 开始运行 - - 开源发布地址:https://github.com/HaujetZhao/CapsWriter - - 下载地址:https://github.com/HaujetZhao/CapsWriter/releases - - 视频教程地址:https://www.bilibili.com/video/BV1qK4y1s7Fb/ - - 作者:淳帅二代(HaujetZhao) - - 软件基于 MIT 协议 - - """) - self.client = ali_speech.NlsClient() self.client.set_log_level('ERROR') # 设置 client 输出日志信息的级别:DEBUG、INFO、WARNING、ERROR @@ -5350,7 +5333,7 @@ def getMediaTimeLength(inputFile): # 用于获取一个视频或者音频文件的长度 result = subprocess.run(["ffprobe", "-v", "error", "-show_entries", "format=duration", "-of", - "default=noprint_wrappers=1:nokey=1", inputFile], + "default=noprint_wrappers=1:nokey=1", inputFile], shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) return float(result.stdout) @@ -5382,9 +5365,13 @@ def execute(command): app = QApplication(sys.argv) conn = sqlite3.connect(dbname) apiUpdateBroadCaster = ApiUpdated() - subprocessStartUpInfo = subprocess.STARTUPINFO() - subprocessStartUpInfo.dwFlags = subprocess.STARTF_USESHOWWINDOW - subprocessStartUpInfo.wShowWindow = subprocess.SW_HIDE + platfm = platform.system() + if platfm == 'Windows': + subprocessStartUpInfo = subprocess.STARTUPINFO() + subprocessStartUpInfo.dwFlags = subprocess.STARTF_USESHOWWINDOW + subprocessStartUpInfo.wShowWindow = subprocess.SW_HIDE + else: + pass main = MainWindow() tray = SystemTray(QIcon('icon.ico'), main) sys.exit(app.exec_()) diff --git a/README.md b/README.md index 380b52f..69af824 100644 --- a/README.md +++ b/README.md @@ -229,7 +229,19 @@ pip install setuptools 这些问题的原因是一些模块用了其它依赖,而这些其它依赖已经好久没更新了。只能遇到一个问题就搜一下,解决掉。上面这些问题都是我遇到后,在网上找了解法,根据自己的情况做了改动,使得问题得以解决。 +**Mac 和 Linux 用户请注意:** +为了在 Windows 上运行时候不弹黑窗口,我在用 subprocess 的时候用了一个 `subprocess.STARTUPINFO()` 类,但是在 Linux 或 Mac 上好像不能用它,所以你们在使用前,要删除几段代码: + +首先是末尾的这三行: + +``` +subprocessStartUpInfo = subprocess.STARTUPINFO() +subprocessStartUpInfo.dwFlags = subprocess.STARTF_USESHOWWINDOW +subprocessStartUpInfo.wShowWindow = subprocess.SW_HIDE +``` + +然后再全局搜索 `, startupinfo=subprocessStartUpInfo` 将其删掉。理论上就好了。 搭建好环境可以运行之后,如果修改了源代码然,后要进行发布,就应当打包成可以独立运行的exe文件,下面提供两种方法进行编译打包: